Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Ruby_Scripts/200.commands.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74 - (show annotations) (download)
Sun May 14 04:10:42 2017 UTC (6 years, 10 months ago) by toshinagata1964
File size: 2102 byte(s)
Change Timebase command is implemented.
1 # Copyright (c) 2010-2017 Toshi Nagata. All rights reserved.
2 #
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 hash = Dialog.run {
16 layout(1,
17 layout(2,
18 item(:text, :title=>"Old control Number"),
19 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 def change_timebase
43 timebase = self.timebase
44 hash = Dialog.run {
45 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 p hash
53 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 end
65
66 end
67
68 register_menu("Change timebase...", :change_timebase)
69 # register_menu("Change control number...", :change_control_number_ext)

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26