| 205 |
message_box("#{nev} events were replaced with #{nev_new} events.", "", :ok) |
message_box("#{nev} events were replaced with #{nev_new} events.", "", :ok) |
| 206 |
end |
end |
| 207 |
|
|
| 208 |
|
@@tremolo_len = "60" |
| 209 |
|
@@tremolo_len2 = "90" |
| 210 |
|
@@tremolo_accel = "4" |
| 211 |
|
@@tremolo_ofs = "1" |
| 212 |
|
@@tremolo_fluct = "10" |
| 213 |
|
|
| 214 |
|
def create_tremolo |
| 215 |
|
values = [@@tremolo_len, @@tremolo_len2, @@tremolo_accel, @@tremolo_ofs, @@tremolo_fluct] |
| 216 |
|
hash = Dialog.run("Create Tremolo") { |
| 217 |
|
layout(1, |
| 218 |
|
layout(2, |
| 219 |
|
item(:text, :title=>"Note length (ms)"), |
| 220 |
|
item(:textfield, :width=>40, :tag=>"len", :value=>values[0]), |
| 221 |
|
item(:text, :title=>"First note length (ms)"), |
| 222 |
|
item(:textfield, :width=>40, :tag=>"len2", :value=>values[1]), |
| 223 |
|
item(:text, :title=>"Accelerate count"), |
| 224 |
|
item(:textfield, :width=>40, :tag=>"accel", :value=>values[2]), |
| 225 |
|
item(:text, :title=>"Note offset"), |
| 226 |
|
item(:textfield, :width=>40, :tag=>"ofs", :value=>values[3]), |
| 227 |
|
item(:text, :title=>"Length fluctuate (%)"), |
| 228 |
|
item(:textfield, :width=>40, :tag=>"fluct", :value=>values[4]))) |
| 229 |
|
} |
| 230 |
|
# p hash |
| 231 |
|
if hash[:status] == 0 |
| 232 |
|
len = hash["len"].to_f / 1000 |
| 233 |
|
len2 = hash["len2"].to_f / 1000 |
| 234 |
|
if len2 == 0.0 |
| 235 |
|
len2 = len |
| 236 |
|
end |
| 237 |
|
accel = hash["accel"].to_i |
| 238 |
|
ofs = hash["ofs"].to_i |
| 239 |
|
fluct = hash["fluct"].to_f / 100.0 |
| 240 |
|
if fluct < 0.0 |
| 241 |
|
fluct = 0.0 |
| 242 |
|
elsif fluct >= 1.0 |
| 243 |
|
fluct = 1.0 |
| 244 |
|
end |
| 245 |
|
@@tremolo_len = hash["len"] |
| 246 |
|
@@tremolo_len2 = hash["len2"] |
| 247 |
|
@@tremolo_accel = hash["accel"] |
| 248 |
|
@@tremolo_ofs = hash["ofs"] |
| 249 |
|
@@tremolo_fluct = hash["fluct"] |
| 250 |
|
if accel <= 0 |
| 251 |
|
r = 1.0 |
| 252 |
|
else |
| 253 |
|
r = (len / len2) ** (1.0 / accel) |
| 254 |
|
end |
| 255 |
|
each_track { |tr| |
| 256 |
|
next if tr.selection.length == 0 |
| 257 |
|
trnew = Track.new |
| 258 |
|
tr.each_selected { |p| |
| 259 |
|
next if p.kind != :note |
| 260 |
|
stick = p.tick |
| 261 |
|
etick = p.tick + p.duration |
| 262 |
|
vel = p.velocity |
| 263 |
|
ctick = stick # Start tick of next note |
| 264 |
|
code = p.code # Key number of next note |
| 265 |
|
clen = len2 # Length of next note |
| 266 |
|
n = 0 # Note count |
| 267 |
|
while (ctick < etick) |
| 268 |
|
ntick = time_to_tick(tick_to_time(ctick) + clen * (1 + (rand - 0.5) * fluct * 2)) |
| 269 |
|
if ntick < ctick + 5 |
| 270 |
|
ntick = ctick + 5 |
| 271 |
|
end |
| 272 |
|
break if ntick >= etick |
| 273 |
|
cvel = vel * (1 + (rand - 0.5) * fluct * 2) |
| 274 |
|
c = (code < 0 ? 0 : (code > 127 ? 127 : code)) |
| 275 |
|
trnew.add(ctick, c, ntick - ctick, cvel) |
| 276 |
|
ctick = ntick |
| 277 |
|
if n < accel |
| 278 |
|
clen = clen * r |
| 279 |
|
else |
| 280 |
|
clen = len |
| 281 |
|
end |
| 282 |
|
if n % 2 == 0 |
| 283 |
|
code = code + ofs |
| 284 |
|
else |
| 285 |
|
code = code - ofs |
| 286 |
|
end |
| 287 |
|
n = n + 1 |
| 288 |
|
end |
| 289 |
|
} |
| 290 |
|
tr.cut(tr.selection) |
| 291 |
|
tr.merge(trnew) |
| 292 |
|
} |
| 293 |
|
end |
| 294 |
|
end |
| 295 |
|
|
| 296 |
end |
end |
| 297 |
|
|
| 298 |
register_menu("Change Timebase...", :change_timebase) |
register_menu("Change Timebase...", :change_timebase) |
| 299 |
register_menu("Randomize Ticks...", :randomize_ticks, 1) |
register_menu("Randomize Ticks...", :randomize_ticks, 1) |
| 300 |
register_menu("Thin Selected Events...", :thin_events, 1) |
register_menu("Thin Selected Events...", :thin_events, 1) |
| 301 |
|
register_menu("Create tremolo...", :create_tremolo, 1) |