| 1 |
toshinagata1964 |
73 |
# Copyright (c) 2010-2017 Toshi Nagata. All rights reserved. |
| 2 |
toshinagata1964 |
4 |
# |
| 3 |
|
|
# This program is free software; you can redistribute it and/or modify |
| 4 |
|
|
# it under the terms of the GNU General Public License as published by |
| 5 |
|
|
# the Free Software Foundation version 2 of the License. |
| 6 |
|
|
# |
| 7 |
|
|
# This program is distributed in the hope that it will be useful, |
| 8 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
|
|
# GNU General Public License for more details. |
| 11 |
|
|
|
| 12 |
|
|
class Sequence |
| 13 |
|
|
|
| 14 |
|
|
def change_control_number_ext |
| 15 |
toshinagata1964 |
36 |
hash = Dialog.run { |
| 16 |
toshinagata1964 |
4 |
layout(1, |
| 17 |
|
|
layout(2, |
| 18 |
toshinagata1964 |
74 |
item(:text, :title=>"Old control Number"), |
| 19 |
toshinagata1964 |
4 |
item(:textfield, :width=>40, :range=>[0, 127], :tag=>"old"), |
| 20 |
|
|
item(:text, :title=>"New control number"), |
| 21 |
|
|
item(:textfield, :width=>40, :range=>[0, 127], :tag=>"new")), |
| 22 |
|
|
item(:checkbox, :title=>"Change only editable tracks", :tag=>"editable_only"), |
| 23 |
|
|
item(:checkbox, :title=>"Change only selected events", :tag=>"selection_only")) |
| 24 |
|
|
} |
| 25 |
|
|
if hash["status"] == 0 |
| 26 |
|
|
old = hash["old"] |
| 27 |
|
|
new = hash["new"] |
| 28 |
|
|
editable_only = hash["editable_only"] |
| 29 |
|
|
selection_only = hash["selection_only"] |
| 30 |
|
|
# puts "old = #{old}, new = #{new}, editable_only = #{editable_only}" |
| 31 |
|
|
each_track { |tr| |
| 32 |
|
|
next if editable_only && !tr.editable? |
| 33 |
|
|
tr.send(selection_only ? :each_selected : :each) { |p| |
| 34 |
|
|
if p.kind == :control && p.code == old |
| 35 |
|
|
p.code = new |
| 36 |
|
|
end |
| 37 |
|
|
} |
| 38 |
|
|
} |
| 39 |
|
|
end |
| 40 |
|
|
end |
| 41 |
|
|
|
| 42 |
toshinagata1964 |
74 |
def change_timebase |
| 43 |
|
|
timebase = self.timebase |
| 44 |
toshinagata1964 |
80 |
hash = Dialog.run("Change Timebase") { |
| 45 |
toshinagata1964 |
74 |
layout(1, |
| 46 |
|
|
layout(2, |
| 47 |
|
|
item(:text, :title=>"Current timebase = #{timebase}"), |
| 48 |
|
|
nil, |
| 49 |
|
|
item(:text, :title=>"New timebase"), |
| 50 |
|
|
item(:textfield, :width=>40, :range=>[24, 960], :tag=>"new"))) |
| 51 |
|
|
} |
| 52 |
toshinagata1964 |
80 |
# p hash |
| 53 |
toshinagata1964 |
74 |
if hash[:status] == 0 |
| 54 |
|
|
new = hash["new"].to_f |
| 55 |
|
|
mult = new / timebase |
| 56 |
|
|
each_track { |tr| |
| 57 |
|
|
set1 = tr.all_events |
| 58 |
|
|
set2 = tr.eventset { |p| p.kind == :note } |
| 59 |
|
|
set2.modify_duration("*", mult) |
| 60 |
|
|
set1.modify_tick("*", mult) |
| 61 |
|
|
} |
| 62 |
|
|
self.set_timebase(new) |
| 63 |
|
|
end |
| 64 |
toshinagata1964 |
4 |
end |
| 65 |
|
|
|
| 66 |
toshinagata1964 |
80 |
def randomize_ticks |
| 67 |
|
|
wd = (get_global_settings("randomize_tick_width") || "10").to_f |
| 68 |
|
|
if !self.has_selection |
| 69 |
|
|
message_box("No events are selected.", "Error", :ok); |
| 70 |
|
|
return |
| 71 |
|
|
end |
| 72 |
|
|
hash = Dialog.run("Randomize Ticks") { |
| 73 |
|
|
layout(1, |
| 74 |
|
|
layout(1, |
| 75 |
|
|
item(:text, :title=>"Randomize width (in milliseconds, 10-1000)"), |
| 76 |
|
|
item(:textfield, :width=>40, :value=>wd.to_s, :range=>[10, 1000], :tag=>"width"))) |
| 77 |
toshinagata1964 |
78 |
} |
| 78 |
toshinagata1964 |
80 |
if hash[:status] == 0 |
| 79 |
|
|
wd = hash["width"].to_f |
| 80 |
|
|
set_global_settings("randomize_tick_width", wd.to_s) |
| 81 |
|
|
each_track { |tr| |
| 82 |
|
|
s = tr.selection |
| 83 |
|
|
t = [] |
| 84 |
|
|
s.each { |p| |
| 85 |
|
|
t1 = self.tick_to_time(p.tick) |
| 86 |
|
|
t2 = t1 + (rand() - 0.5) * wd / 1000.0 |
| 87 |
|
|
t.push(Integer(self.time_to_tick(t2))) |
| 88 |
|
|
} |
| 89 |
|
|
s.modify_tick(t) |
| 90 |
|
|
} |
| 91 |
|
|
end |
| 92 |
toshinagata1964 |
74 |
end |
| 93 |
|
|
|
| 94 |
toshinagata1964 |
78 |
end |
| 95 |
|
|
|
| 96 |
toshinagata1964 |
74 |
register_menu("Change timebase...", :change_timebase) |
| 97 |
toshinagata1964 |
80 |
register_menu("Randomize ticks...", :randomize_ticks, 1) |
| 98 |
toshinagata1964 |
4 |
# register_menu("Change control number...", :change_control_number_ext) |