midilib 2.0.4 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ChangeLog +2 -1
- data/Credits +44 -2
- data/README.rdoc +13 -9
- data/Rakefile +36 -53
- data/TODO.rdoc +13 -2
- data/examples/from_scratch.rb +4 -6
- data/examples/measures_mbt.rb +11 -11
- data/examples/print_program_changes.rb +11 -11
- data/examples/reader2text.rb +191 -191
- data/examples/seq2text.rb +18 -18
- data/examples/split.rb +21 -20
- data/examples/strings.rb +15 -15
- data/examples/transpose.rb +41 -42
- data/html/MIDI/ActiveSense.html +89 -213
- data/html/MIDI/ChannelEvent.html +95 -224
- data/html/MIDI/ChannelPressure.html +103 -241
- data/html/MIDI/Clock.html +89 -213
- data/html/MIDI/Continue.html +89 -213
- data/html/MIDI/Controller.html +105 -246
- data/html/MIDI/Event.html +134 -358
- data/html/MIDI/IO/MIDIFile.html +544 -1148
- data/html/MIDI/IO/SeqReader.html +273 -577
- data/html/MIDI/IO/SeqWriter.html +233 -439
- data/html/MIDI/IO.html +48 -164
- data/html/MIDI/KeySig.html +148 -291
- data/html/MIDI/Marker.html +73 -192
- data/html/MIDI/Measure.html +104 -267
- data/html/MIDI/Measures.html +106 -259
- data/html/MIDI/MetaEvent.html +171 -352
- data/html/MIDI/NoteEvent.html +114 -276
- data/html/MIDI/NoteOff.html +95 -223
- data/html/MIDI/NoteOn.html +95 -223
- data/html/MIDI/PitchBend.html +104 -242
- data/html/MIDI/PolyPressure.html +102 -246
- data/html/MIDI/ProgramChange.html +103 -241
- data/html/MIDI/Realtime.html +96 -230
- data/html/MIDI/Sequence.html +256 -576
- data/html/MIDI/SongPointer.html +104 -242
- data/html/MIDI/SongSelect.html +103 -241
- data/html/MIDI/Start.html +89 -213
- data/html/MIDI/Stop.html +89 -213
- data/html/MIDI/SystemCommon.html +73 -192
- data/html/MIDI/SystemExclusive.html +106 -244
- data/html/MIDI/SystemReset.html +89 -213
- data/html/MIDI/Tempo.html +127 -309
- data/html/MIDI/TimeSig.html +119 -300
- data/html/MIDI/Track.html +214 -494
- data/html/MIDI/TuneRequest.html +96 -230
- data/html/MIDI/Utils.html +91 -233
- data/html/MIDI.html +142 -526
- data/html/Object.html +197 -0
- data/html/README_rdoc.html +280 -486
- data/html/TODO_rdoc.html +68 -145
- data/html/created.rid +15 -14
- data/html/css/fonts.css +167 -0
- data/html/css/rdoc.css +639 -0
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/index.html +230 -446
- data/html/js/darkfish.js +22 -91
- data/html/js/navigation.js +4 -41
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +41 -25
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +9 -8
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +1111 -505
- data/install.rb +53 -34
- data/lib/midilib/consts.rb +406 -408
- data/lib/midilib/event.rb +335 -306
- data/lib/midilib/info.rb +5 -7
- data/lib/midilib/io/midifile.rb +424 -452
- data/lib/midilib/io/seqreader.rb +200 -192
- data/lib/midilib/io/seqwriter.rb +151 -147
- data/lib/midilib/measure.rb +78 -80
- data/lib/midilib/mergesort.rb +39 -0
- data/lib/midilib/sequence.rb +93 -87
- data/lib/midilib/track.rb +71 -118
- data/lib/midilib/utils.rb +17 -20
- data/lib/midilib.rb +5 -5
- data/test/event_equality.rb +50 -52
- data/test/test_event.rb +120 -124
- data/test/test_io.rb +118 -38
- data/test/test_mergesort.rb +37 -0
- data/test/test_midifile.rb +6 -19
- data/test/test_sequence.rb +62 -61
- data/test/test_track.rb +126 -155
- data/test/test_varlen.rb +23 -27
- metadata +67 -62
- data/html/IO.html +0 -259
- data/html/MIDI/MIDI/MIDI/Array.html +0 -353
- data/html/MIDI/MIDI/MIDI.html +0 -204
- data/html/MIDI/MIDI.html +0 -204
- data/html/js/jquery.js +0 -18
- data/html/rdoc.css +0 -543
data/html/MIDI/Track.html
CHANGED
@@ -2,274 +2,135 @@
|
|
2
2
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
|
-
<meta
|
5
|
+
<meta charset="UTF-8">
|
6
6
|
|
7
7
|
<title>class MIDI::Track - midilib</title>
|
8
8
|
|
9
|
-
<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">
|
10
|
-
|
11
9
|
<script type="text/javascript">
|
12
10
|
var rdoc_rel_prefix = "../";
|
11
|
+
var index_rel_prefix = "../";
|
13
12
|
</script>
|
14
13
|
|
15
|
-
<script
|
16
|
-
<script
|
17
|
-
<script
|
18
|
-
<script
|
19
|
-
<script
|
20
|
-
|
14
|
+
<script src="../js/navigation.js" defer></script>
|
15
|
+
<script src="../js/search.js" defer></script>
|
16
|
+
<script src="../js/search_index.js" defer></script>
|
17
|
+
<script src="../js/searcher.js" defer></script>
|
18
|
+
<script src="../js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
21
22
|
|
22
23
|
|
23
|
-
<body id="top" class="class">
|
24
|
-
<nav
|
25
|
-
<
|
26
|
-
|
27
|
-
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
28
34
|
<a href="../table_of_contents.html#classes">Classes</a>
|
29
35
|
<a href="../table_of_contents.html#methods">Methods</a>
|
30
|
-
</
|
31
|
-
</
|
32
|
-
|
36
|
+
</div>
|
37
|
+
</div>
|
33
38
|
|
34
|
-
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
35
40
|
<form action="#" method="get" accept-charset="utf-8">
|
36
|
-
<
|
37
|
-
<input
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
38
45
|
title="Type to search, Up and Down to navigate, Enter to load">
|
39
|
-
</
|
40
|
-
</form>
|
41
|
-
|
42
|
-
<ul id="search-results" class="initially-hidden"></ul>
|
43
|
-
</nav>
|
44
|
-
|
46
|
+
</div>
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
</ul>
|
52
|
-
</nav>
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
53
|
|
54
|
-
|
55
54
|
</div>
|
56
55
|
|
57
|
-
<div id="class-metadata">
|
58
|
-
|
59
|
-
<nav id="parent-class-section" class="section">
|
60
|
-
<h3 class="section-header">Parent</h3>
|
61
|
-
|
62
|
-
<p class="link">Object
|
63
|
-
|
64
|
-
</nav>
|
65
|
-
|
66
|
-
<!-- Included Modules -->
|
67
|
-
<nav id="includes-section" class="section">
|
68
|
-
<h3 class="section-header">Included Modules</h3>
|
69
|
-
|
70
|
-
<ul class="link-list">
|
71
|
-
|
72
|
-
|
73
|
-
<li><span class="include">Enumerable</span>
|
74
|
-
|
75
56
|
|
76
|
-
</ul>
|
77
|
-
</nav>
|
78
57
|
|
79
|
-
|
80
|
-
<nav id="method-list-section" class="section">
|
81
|
-
<h3 class="section-header">Methods</h3>
|
82
|
-
|
83
|
-
<ul class="link-list">
|
84
|
-
|
85
|
-
<li><a href="#method-c-new">::new</a>
|
86
|
-
|
87
|
-
<li><a href="#method-i-each">#each</a>
|
88
|
-
|
89
|
-
<li><a href="#method-i-instrument">#instrument</a>
|
90
|
-
|
91
|
-
<li><a href="#method-i-instrument-3D">#instrument=</a>
|
92
|
-
|
93
|
-
<li><a href="#method-i-merge">#merge</a>
|
94
|
-
|
95
|
-
<li><a href="#method-i-merge_event_lists">#merge_event_lists</a>
|
96
|
-
|
97
|
-
<li><a href="#method-i-name">#name</a>
|
98
|
-
|
99
|
-
<li><a href="#method-i-name-3D">#name=</a>
|
100
|
-
|
101
|
-
<li><a href="#method-i-quantize">#quantize</a>
|
102
|
-
|
103
|
-
<li><a href="#method-i-recalc_delta_from_times">#recalc_delta_from_times</a>
|
104
|
-
|
105
|
-
<li><a href="#method-i-recalc_times">#recalc_times</a>
|
58
|
+
<div id="class-metadata">
|
106
59
|
|
107
|
-
<li><a href="#method-i-sort">#sort</a>
|
108
60
|
|
109
|
-
|
110
|
-
</
|
61
|
+
<div id="parent-class-section" class="nav-section">
|
62
|
+
<h3>Parent</h3>
|
111
63
|
|
112
|
-
</
|
113
|
-
|
114
|
-
<div id="project-metadata">
|
115
|
-
<nav id="fileindex-section" class="section project-section">
|
116
|
-
<h3 class="section-header">Pages</h3>
|
117
|
-
|
118
|
-
<ul>
|
119
|
-
|
120
|
-
<li class="file"><a href="../README_rdoc.html">README</a>
|
121
|
-
|
122
|
-
<li class="file"><a href="../TODO_rdoc.html">TODO</a>
|
123
|
-
|
124
|
-
</ul>
|
125
|
-
</nav>
|
64
|
+
<p class="link"><a href="../Object.html">Object</a>
|
65
|
+
</div>
|
126
66
|
|
127
|
-
|
128
|
-
|
67
|
+
|
68
|
+
<div id="includes-section" class="nav-section">
|
69
|
+
<h3>Included Modules</h3>
|
129
70
|
|
130
71
|
<ul class="link-list">
|
131
|
-
|
132
|
-
<li><a href="../MIDI.html">MIDI</a>
|
133
|
-
|
134
|
-
<li><a href="../MIDI/ActiveSense.html">MIDI::ActiveSense</a>
|
135
|
-
|
136
|
-
<li><a href="../MIDI/ChannelEvent.html">MIDI::ChannelEvent</a>
|
137
|
-
|
138
|
-
<li><a href="../MIDI/ChannelPressure.html">MIDI::ChannelPressure</a>
|
139
|
-
|
140
|
-
<li><a href="../MIDI/Clock.html">MIDI::Clock</a>
|
141
|
-
|
142
|
-
<li><a href="../MIDI/Continue.html">MIDI::Continue</a>
|
143
|
-
|
144
|
-
<li><a href="../MIDI/Controller.html">MIDI::Controller</a>
|
145
|
-
|
146
|
-
<li><a href="../MIDI/Event.html">MIDI::Event</a>
|
147
|
-
|
148
|
-
<li><a href="../MIDI/IO.html">MIDI::IO</a>
|
149
|
-
|
150
|
-
<li><a href="../MIDI/IO/MIDIFile.html">MIDI::IO::MIDIFile</a>
|
151
|
-
|
152
|
-
<li><a href="../MIDI/IO/SeqReader.html">MIDI::IO::SeqReader</a>
|
153
|
-
|
154
|
-
<li><a href="../MIDI/IO/SeqWriter.html">MIDI::IO::SeqWriter</a>
|
155
|
-
|
156
|
-
<li><a href="../MIDI/KeySig.html">MIDI::KeySig</a>
|
157
|
-
|
158
|
-
<li><a href="../MIDI/MIDI.html">MIDI::MIDI</a>
|
159
|
-
|
160
|
-
<li><a href="../MIDI/MIDI/MIDI.html">MIDI::MIDI::MIDI</a>
|
161
|
-
|
162
|
-
<li><a href="../MIDI/MIDI/MIDI/Array.html">MIDI::MIDI::MIDI::Array</a>
|
163
|
-
|
164
|
-
<li><a href="../MIDI/Marker.html">MIDI::Marker</a>
|
165
|
-
|
166
|
-
<li><a href="../MIDI/Measure.html">MIDI::Measure</a>
|
167
|
-
|
168
|
-
<li><a href="../MIDI/Measures.html">MIDI::Measures</a>
|
169
|
-
|
170
|
-
<li><a href="../MIDI/MetaEvent.html">MIDI::MetaEvent</a>
|
171
|
-
|
172
|
-
<li><a href="../MIDI/NoteEvent.html">MIDI::NoteEvent</a>
|
173
|
-
|
174
|
-
<li><a href="../MIDI/NoteOff.html">MIDI::NoteOff</a>
|
175
|
-
|
176
|
-
<li><a href="../MIDI/NoteOff.html">MIDI::NoteOffEvent</a>
|
177
|
-
|
178
|
-
<li><a href="../MIDI/NoteOn.html">MIDI::NoteOn</a>
|
179
|
-
|
180
|
-
<li><a href="../MIDI/NoteOn.html">MIDI::NoteOnEvent</a>
|
181
|
-
|
182
|
-
<li><a href="../MIDI/PitchBend.html">MIDI::PitchBend</a>
|
183
|
-
|
184
|
-
<li><a href="../MIDI/PolyPressure.html">MIDI::PolyPressure</a>
|
185
|
-
|
186
|
-
<li><a href="../MIDI/ProgramChange.html">MIDI::ProgramChange</a>
|
187
|
-
|
188
|
-
<li><a href="../MIDI/Realtime.html">MIDI::Realtime</a>
|
189
|
-
|
190
|
-
<li><a href="../MIDI/Sequence.html">MIDI::Sequence</a>
|
191
|
-
|
192
|
-
<li><a href="../MIDI/SongPointer.html">MIDI::SongPointer</a>
|
193
|
-
|
194
|
-
<li><a href="../MIDI/SongSelect.html">MIDI::SongSelect</a>
|
195
|
-
|
196
|
-
<li><a href="../MIDI/Start.html">MIDI::Start</a>
|
197
|
-
|
198
|
-
<li><a href="../MIDI/Stop.html">MIDI::Stop</a>
|
199
|
-
|
200
|
-
<li><a href="../MIDI/SystemCommon.html">MIDI::SystemCommon</a>
|
201
|
-
|
202
|
-
<li><a href="../MIDI/SystemExclusive.html">MIDI::SystemExclusive</a>
|
203
|
-
|
204
|
-
<li><a href="../MIDI/SystemReset.html">MIDI::SystemReset</a>
|
205
|
-
|
206
|
-
<li><a href="../MIDI/Tempo.html">MIDI::Tempo</a>
|
207
|
-
|
208
|
-
<li><a href="../MIDI/TimeSig.html">MIDI::TimeSig</a>
|
209
|
-
|
210
|
-
<li><a href="../MIDI/Track.html">MIDI::Track</a>
|
211
|
-
|
212
|
-
<li><a href="../MIDI/TuneRequest.html">MIDI::TuneRequest</a>
|
213
|
-
|
214
|
-
<li><a href="../MIDI/Utils.html">MIDI::Utils</a>
|
215
|
-
|
216
|
-
<li><a href="../IO.html">IO</a>
|
217
|
-
|
72
|
+
<li><span class="include">Enumerable</span>
|
218
73
|
</ul>
|
219
|
-
</
|
74
|
+
</div>
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
<!-- Method Quickref -->
|
79
|
+
<div id="method-list-section" class="nav-section">
|
80
|
+
<h3>Methods</h3>
|
81
|
+
|
82
|
+
<ul class="link-list" role="directory">
|
83
|
+
<li ><a href="#method-c-new">::new</a>
|
84
|
+
<li ><a href="#method-i-each">#each</a>
|
85
|
+
<li ><a href="#method-i-instrument">#instrument</a>
|
86
|
+
<li ><a href="#method-i-instrument-3D">#instrument=</a>
|
87
|
+
<li ><a href="#method-i-merge">#merge</a>
|
88
|
+
<li ><a href="#method-i-merge_event_lists">#merge_event_lists</a>
|
89
|
+
<li ><a href="#method-i-name">#name</a>
|
90
|
+
<li ><a href="#method-i-name-3D">#name=</a>
|
91
|
+
<li ><a href="#method-i-quantize">#quantize</a>
|
92
|
+
<li ><a href="#method-i-recalc_delta_from_times">#recalc_delta_from_times</a>
|
93
|
+
<li ><a href="#method-i-recalc_times">#recalc_times</a>
|
94
|
+
<li ><a href="#method-i-sort">#sort</a>
|
95
|
+
</ul>
|
96
|
+
</div>
|
220
97
|
|
221
98
|
</div>
|
222
99
|
</nav>
|
223
100
|
|
224
|
-
<
|
225
|
-
<h1
|
101
|
+
<main role="main" aria-labelledby="class-MIDI::Track">
|
102
|
+
<h1 id="class-MIDI::Track" class="class">
|
103
|
+
class MIDI::Track
|
104
|
+
</h1>
|
226
105
|
|
227
|
-
<
|
106
|
+
<section class="description">
|
228
107
|
|
229
|
-
<p>A <a href="Track.html">Track</a> is a list of events.</p>
|
108
|
+
<p>A <a href="Track.html"><code>Track</code></a> is a list of events.</p>
|
230
109
|
|
231
|
-
<p>When you modify the <code>events</code> array, make sure to call <a
|
232
|
-
href="Track.html#method-i-recalc_times">#recalc_times</a> so each <a
|
233
|
-
href="Event.html">Event</a> gets its <code>time_from_start</code>
|
234
|
-
recalculated.</p>
|
110
|
+
<p>When you modify the <code>events</code> array, make sure to call <a href="Track.html#method-i-recalc_times"><code>recalc_times</code></a> so each <a href="Event.html"><code>Event</code></a> gets its <code>time_from_start</code> recalculated.</p>
|
235
111
|
|
236
|
-
<p>A <a href="Track.html">Track</a> also holds a bitmask that specifies the
|
237
|
-
channels used by the track. This bitmask is set when the track is read from
|
238
|
-
the <a href="MIDI.html">MIDI</a> file by an <a
|
239
|
-
href="IO/SeqReader.html">IO::SeqReader</a> but is <em>not</em> kept up to
|
240
|
-
date by any other methods.</p>
|
112
|
+
<p>A <a href="Track.html"><code>Track</code></a> also holds a bitmask that specifies the channels used by the track. This bitmask is set when the track is read from the <a href="../MIDI.html"><code>MIDI</code></a> file by an <a href="IO/SeqReader.html"><code>IO::SeqReader</code></a> but is <em>not</em> kept up to date by any other methods.</p>
|
241
113
|
|
242
|
-
</
|
114
|
+
</section>
|
243
115
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
116
|
<section id="5Buntitled-5D" class="documentation-section">
|
248
|
-
|
249
117
|
|
250
|
-
|
251
118
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
119
|
+
<section class="constants-list">
|
120
|
+
<header>
|
121
|
+
<h3>Constants</h3>
|
122
|
+
</header>
|
256
123
|
<dl>
|
257
|
-
|
258
124
|
<dt id="UNNAMED">UNNAMED
|
259
|
-
|
260
|
-
<dd class="description">
|
261
|
-
|
262
|
-
|
125
|
+
<dd>
|
263
126
|
</dl>
|
264
127
|
</section>
|
265
|
-
|
266
128
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
129
|
+
<section class="attribute-method-details" class="method-section">
|
130
|
+
<header>
|
131
|
+
<h3>Attributes</h3>
|
132
|
+
</header>
|
271
133
|
|
272
|
-
|
273
134
|
<div id="attribute-i-channels_used" class="method-detail">
|
274
135
|
<div class="method-heading attribute-method-heading">
|
275
136
|
<span class="method-name">channels_used</span><span
|
@@ -278,11 +139,8 @@ date by any other methods.</p>
|
|
278
139
|
|
279
140
|
<div class="method-description">
|
280
141
|
|
281
|
-
|
282
|
-
|
283
142
|
</div>
|
284
143
|
</div>
|
285
|
-
|
286
144
|
<div id="attribute-i-events" class="method-detail">
|
287
145
|
<div class="method-heading attribute-method-heading">
|
288
146
|
<span class="method-name">events</span><span
|
@@ -291,11 +149,8 @@ date by any other methods.</p>
|
|
291
149
|
|
292
150
|
<div class="method-description">
|
293
151
|
|
294
|
-
|
295
|
-
|
296
152
|
</div>
|
297
153
|
</div>
|
298
|
-
|
299
154
|
<div id="attribute-i-sequence" class="method-detail">
|
300
155
|
<div class="method-heading attribute-method-heading">
|
301
156
|
<span class="method-name">sequence</span><span
|
@@ -304,466 +159,331 @@ date by any other methods.</p>
|
|
304
159
|
|
305
160
|
<div class="method-description">
|
306
161
|
|
307
|
-
|
308
|
-
|
309
162
|
</div>
|
310
163
|
</div>
|
311
|
-
|
312
|
-
</section><!-- attribute-method-details -->
|
313
|
-
|
164
|
+
</section>
|
314
165
|
|
315
|
-
<!-- Methods -->
|
316
|
-
|
317
|
-
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
318
|
-
<h3 class="section-header">Public Class Methods</h3>
|
319
166
|
|
320
|
-
|
167
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
168
|
+
<header>
|
169
|
+
<h3>Public Class Methods</h3>
|
170
|
+
</header>
|
171
|
+
|
321
172
|
<div id="method-c-new" class="method-detail ">
|
322
|
-
|
323
173
|
<div class="method-heading">
|
324
174
|
<span class="method-name">new</span><span
|
325
175
|
class="method-args">(sequence)</span>
|
326
176
|
<span class="method-click-advice">click to toggle source</span>
|
327
177
|
</div>
|
328
|
-
|
329
178
|
|
330
179
|
<div class="method-description">
|
331
180
|
|
332
|
-
|
333
|
-
|
334
181
|
|
335
|
-
|
336
182
|
<div class="method-source-code" id="new-source">
|
337
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
338
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">sequence</span>)
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
183
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 22</span>
|
184
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">sequence</span>)
|
185
|
+
<span class="ruby-ivar">@sequence</span> = <span class="ruby-identifier">sequence</span>
|
186
|
+
<span class="ruby-ivar">@events</span> = []
|
187
|
+
|
188
|
+
<span class="ruby-comment"># Bitmask of all channels used. Set when track is read in from</span>
|
189
|
+
<span class="ruby-comment"># a MIDI file.</span>
|
190
|
+
<span class="ruby-ivar">@channels_used</span> = <span class="ruby-value">0</span>
|
191
|
+
<span class="ruby-ivar">@instrument</span> = <span class="ruby-keyword">nil</span>
|
345
192
|
<span class="ruby-keyword">end</span></pre>
|
346
|
-
</div
|
347
|
-
|
193
|
+
</div>
|
348
194
|
</div>
|
349
195
|
|
350
|
-
|
351
196
|
|
352
|
-
|
353
|
-
</div><!-- new-method -->
|
197
|
+
</div>
|
354
198
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
199
|
+
</section>
|
200
|
+
|
201
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
202
|
+
<header>
|
203
|
+
<h3>Public Instance Methods</h3>
|
204
|
+
</header>
|
360
205
|
|
361
|
-
|
362
206
|
<div id="method-i-each" class="method-detail ">
|
363
|
-
|
364
207
|
<div class="method-heading">
|
365
208
|
<span class="method-name">each</span><span
|
366
209
|
class="method-args">() { |event| ... }</span>
|
367
210
|
<span class="method-click-advice">click to toggle source</span>
|
368
211
|
</div>
|
369
|
-
|
370
212
|
|
371
213
|
<div class="method-description">
|
372
|
-
|
373
214
|
<p>Iterate over events.</p>
|
374
|
-
|
375
215
|
|
376
|
-
|
377
216
|
<div class="method-source-code" id="each-source">
|
378
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
379
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">each</span>
|
380
|
-
|
217
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 125</span>
|
218
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yields: event</span>
|
219
|
+
<span class="ruby-ivar">@events</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
381
220
|
<span class="ruby-keyword">end</span></pre>
|
382
|
-
</div
|
383
|
-
|
221
|
+
</div>
|
384
222
|
</div>
|
385
223
|
|
386
|
-
|
387
224
|
|
388
|
-
|
389
|
-
</div><!-- each-method -->
|
225
|
+
</div>
|
390
226
|
|
391
|
-
|
392
227
|
<div id="method-i-instrument" class="method-detail ">
|
393
|
-
|
394
228
|
<div class="method-heading">
|
395
229
|
<span class="method-name">instrument</span><span
|
396
230
|
class="method-args">()</span>
|
397
231
|
<span class="method-click-advice">click to toggle source</span>
|
398
232
|
</div>
|
399
|
-
|
400
233
|
|
401
234
|
<div class="method-description">
|
402
235
|
|
403
|
-
|
404
|
-
|
405
236
|
|
406
|
-
|
407
237
|
<div class="method-source-code" id="instrument-source">
|
408
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
409
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">instrument</span>
|
410
|
-
|
238
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 49</span>
|
239
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">instrument</span>
|
240
|
+
<span class="ruby-constant">MetaEvent</span>.<span class="ruby-identifier">bytes_as_str</span>(<span class="ruby-ivar">@instrument</span>)
|
411
241
|
<span class="ruby-keyword">end</span></pre>
|
412
|
-
</div
|
413
|
-
|
242
|
+
</div>
|
414
243
|
</div>
|
415
244
|
|
416
|
-
|
417
245
|
|
418
|
-
|
419
|
-
</div><!-- instrument-method -->
|
246
|
+
</div>
|
420
247
|
|
421
|
-
|
422
248
|
<div id="method-i-instrument-3D" class="method-detail ">
|
423
|
-
|
424
249
|
<div class="method-heading">
|
425
250
|
<span class="method-name">instrument=</span><span
|
426
251
|
class="method-args">(str_or_bytes)</span>
|
427
252
|
<span class="method-click-advice">click to toggle source</span>
|
428
253
|
</div>
|
429
|
-
|
430
254
|
|
431
255
|
<div class="method-description">
|
432
256
|
|
433
|
-
|
434
|
-
|
435
257
|
|
436
|
-
|
437
258
|
<div class="method-source-code" id="instrument-3D-source">
|
438
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
439
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">instrument=</span>(<span class="ruby-identifier">str_or_bytes</span>)
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
259
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 53</span>
|
260
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">instrument=</span>(<span class="ruby-identifier">str_or_bytes</span>)
|
261
|
+
<span class="ruby-ivar">@instrument</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">str_or_bytes</span>
|
262
|
+
<span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>
|
263
|
+
<span class="ruby-constant">MetaEvent</span>.<span class="ruby-identifier">str_as_bytes</span>(<span class="ruby-identifier">str_or_bytes</span>)
|
264
|
+
<span class="ruby-keyword">else</span>
|
265
|
+
<span class="ruby-identifier">str_or_bytes</span>
|
266
|
+
<span class="ruby-keyword">end</span>
|
446
267
|
<span class="ruby-keyword">end</span></pre>
|
447
|
-
</div
|
448
|
-
|
268
|
+
</div>
|
449
269
|
</div>
|
450
270
|
|
451
|
-
|
452
271
|
|
453
|
-
|
454
|
-
</div><!-- instrument-3D-method -->
|
272
|
+
</div>
|
455
273
|
|
456
|
-
|
457
274
|
<div id="method-i-merge" class="method-detail ">
|
458
|
-
|
459
275
|
<div class="method-heading">
|
460
276
|
<span class="method-name">merge</span><span
|
461
277
|
class="method-args">(event_list)</span>
|
462
278
|
<span class="method-click-advice">click to toggle source</span>
|
463
279
|
</div>
|
464
|
-
|
465
280
|
|
466
281
|
<div class="method-description">
|
467
|
-
|
468
|
-
<p>Merges an array of events into our event list. After merging, the events'
|
469
|
-
time_from_start values are correct so you don't need to worry about calling
|
470
|
-
recalc_times.</p>
|
471
|
-
|
282
|
+
<p>Merges an array of events into our event list. After merging, the events’ time_from_start values are correct so you don’t need to worry about calling recalc_times.</p>
|
472
283
|
|
473
|
-
|
474
284
|
<div class="method-source-code" id="merge-source">
|
475
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
476
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">merge</span>(<span class="ruby-identifier">event_list</span>)
|
477
|
-
|
285
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 65</span>
|
286
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">merge</span>(<span class="ruby-identifier">event_list</span>)
|
287
|
+
<span class="ruby-ivar">@events</span> = <span class="ruby-identifier">merge_event_lists</span>(<span class="ruby-ivar">@events</span>, <span class="ruby-identifier">event_list</span>)
|
478
288
|
<span class="ruby-keyword">end</span></pre>
|
479
|
-
</div
|
480
|
-
|
289
|
+
</div>
|
481
290
|
</div>
|
482
291
|
|
483
|
-
|
484
292
|
|
485
|
-
|
486
|
-
</div><!-- merge-method -->
|
293
|
+
</div>
|
487
294
|
|
488
|
-
|
489
295
|
<div id="method-i-merge_event_lists" class="method-detail ">
|
490
|
-
|
491
296
|
<div class="method-heading">
|
492
297
|
<span class="method-name">merge_event_lists</span><span
|
493
298
|
class="method-args">(list1, list2)</span>
|
494
299
|
<span class="method-click-advice">click to toggle source</span>
|
495
300
|
</div>
|
496
|
-
|
497
301
|
|
498
302
|
<div class="method-description">
|
499
|
-
|
500
303
|
<p>Merges two event arrays together. Does not modify this track.</p>
|
501
|
-
|
502
304
|
|
503
|
-
|
504
305
|
<div class="method-source-code" id="merge_event_lists-source">
|
505
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
506
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">merge_event_lists</span>(<span class="ruby-identifier">list1</span>, <span class="ruby-identifier">list2</span>)
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
306
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 70</span>
|
307
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">merge_event_lists</span>(<span class="ruby-identifier">list1</span>, <span class="ruby-identifier">list2</span>)
|
308
|
+
<span class="ruby-identifier">recalc_times</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">list1</span>)
|
309
|
+
<span class="ruby-identifier">recalc_times</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">list2</span>)
|
310
|
+
<span class="ruby-identifier">list</span> = <span class="ruby-identifier">list1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">list2</span>
|
311
|
+
<span class="ruby-identifier">recalc_delta_from_times</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">list</span>)
|
312
|
+
<span class="ruby-identifier">list</span>
|
512
313
|
<span class="ruby-keyword">end</span></pre>
|
513
|
-
</div
|
514
|
-
|
314
|
+
</div>
|
515
315
|
</div>
|
516
316
|
|
517
|
-
|
518
317
|
|
519
|
-
|
520
|
-
</div><!-- merge_event_lists-method -->
|
318
|
+
</div>
|
521
319
|
|
522
|
-
|
523
320
|
<div id="method-i-name" class="method-detail ">
|
524
|
-
|
525
321
|
<div class="method-heading">
|
526
322
|
<span class="method-name">name</span><span
|
527
323
|
class="method-args">()</span>
|
528
324
|
<span class="method-click-advice">click to toggle source</span>
|
529
325
|
</div>
|
530
|
-
|
531
326
|
|
532
327
|
<div class="method-description">
|
533
|
-
|
534
|
-
<p>Return track name. If there is no name, return <a
|
535
|
-
href="Track.html#UNNAMED">UNNAMED</a>.</p>
|
536
|
-
|
328
|
+
<p>Return track name. If there is no name, return <a href="Track.html#UNNAMED"><code>UNNAMED</code></a>.</p>
|
537
329
|
|
538
|
-
|
539
330
|
<div class="method-source-code" id="name-source">
|
540
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
541
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">name</span>
|
542
|
-
|
543
|
-
|
544
|
-
}
|
545
|
-
<span class="ruby-keyword">return</span> <span class="ruby-identifier">event</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">event</span>.<span class="ruby-identifier">data_as_str</span> <span class="ruby-operator">:</span> <span class="ruby-constant">UNNAMED</span>
|
331
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 33</span>
|
332
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">name</span>
|
333
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-ivar">@events</span>.<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">MetaEvent</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">meta_type</span> <span class="ruby-operator">==</span> <span class="ruby-constant">META_SEQ_NAME</span> }
|
334
|
+
<span class="ruby-identifier">event</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">event</span>.<span class="ruby-identifier">data_as_str</span> <span class="ruby-operator">:</span> <span class="ruby-constant">UNNAMED</span>
|
546
335
|
<span class="ruby-keyword">end</span></pre>
|
547
|
-
</div
|
548
|
-
|
336
|
+
</div>
|
549
337
|
</div>
|
550
338
|
|
551
|
-
|
552
339
|
|
553
|
-
|
554
|
-
</div><!-- name-method -->
|
340
|
+
</div>
|
555
341
|
|
556
|
-
|
557
342
|
<div id="method-i-name-3D" class="method-detail ">
|
558
|
-
|
559
343
|
<div class="method-heading">
|
560
344
|
<span class="method-name">name=</span><span
|
561
345
|
class="method-args">(name)</span>
|
562
346
|
<span class="method-click-advice">click to toggle source</span>
|
563
347
|
</div>
|
564
|
-
|
565
348
|
|
566
349
|
<div class="method-description">
|
567
|
-
|
568
350
|
<p>Set track name. Replaces or creates a name meta-event.</p>
|
569
|
-
|
570
351
|
|
571
|
-
|
572
352
|
<div class="method-source-code" id="name-3D-source">
|
573
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
574
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">name=</span>(<span class="ruby-identifier">name</span>)
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
<span class="ruby-
|
581
|
-
|
582
|
-
<span class="ruby-ivar">@events</span>[<span class="ruby-value">0</span>, <span class="ruby-value">0</span>] = <span class="ruby-identifier">event</span>
|
583
|
-
<span class="ruby-keyword">end</span>
|
353
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 39</span>
|
354
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">name=</span>(<span class="ruby-identifier">name</span>)
|
355
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-ivar">@events</span>.<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">MetaEvent</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">meta_type</span> <span class="ruby-operator">==</span> <span class="ruby-constant">META_SEQ_NAME</span> }
|
356
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">event</span>
|
357
|
+
<span class="ruby-identifier">event</span>.<span class="ruby-identifier">data</span> = <span class="ruby-identifier">name</span>
|
358
|
+
<span class="ruby-keyword">else</span>
|
359
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-constant">MetaEvent</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">META_SEQ_NAME</span>, <span class="ruby-identifier">name</span>, <span class="ruby-value">0</span>)
|
360
|
+
<span class="ruby-ivar">@events</span>[<span class="ruby-value">0</span>, <span class="ruby-value">0</span>] = <span class="ruby-identifier">event</span>
|
361
|
+
<span class="ruby-keyword">end</span>
|
584
362
|
<span class="ruby-keyword">end</span></pre>
|
585
|
-
</div
|
586
|
-
|
363
|
+
</div>
|
587
364
|
</div>
|
588
365
|
|
589
|
-
|
590
366
|
|
591
|
-
|
592
|
-
</div><!-- name-3D-method -->
|
367
|
+
</div>
|
593
368
|
|
594
|
-
|
595
369
|
<div id="method-i-quantize" class="method-detail ">
|
596
|
-
|
597
370
|
<div class="method-heading">
|
598
371
|
<span class="method-name">quantize</span><span
|
599
372
|
class="method-args">(length_or_note)</span>
|
600
373
|
<span class="method-click-advice">click to toggle source</span>
|
601
374
|
</div>
|
602
|
-
|
603
375
|
|
604
376
|
<div class="method-description">
|
605
|
-
|
606
|
-
<p>Quantize every event. length_or_note is either a length (1 = quarter, 0.25
|
607
|
-
= sixteenth, 4 = whole note) or a note name ("sixteenth", "32nd", "8th
|
608
|
-
triplet", "dotted quarter").</p>
|
377
|
+
<p>Quantize every event. length_or_note is either a length (1 = quarter, 0.25 = sixteenth, 4 = whole note) or a note name (“sixteenth”, “32nd”, “8th triplet”, “dotted quarter”).</p>
|
609
378
|
|
610
|
-
<p>Since each event
|
611
|
-
href="Track.html#method-i-recalc_delta_from_times">#recalc_delta_from_times</a>
|
612
|
-
after each event quantizes itself.</p>
|
613
|
-
|
379
|
+
<p>Since each event’s time_from_start is modified, we call <a href="Track.html#method-i-recalc_delta_from_times"><code>recalc_delta_from_times</code></a> after each event quantizes itself.</p>
|
614
380
|
|
615
|
-
|
616
381
|
<div class="method-source-code" id="quantize-source">
|
617
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
618
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">quantize</span>(<span class="ruby-identifier">length_or_note</span>)
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
382
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 84</span>
|
383
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">quantize</span>(<span class="ruby-identifier">length_or_note</span>)
|
384
|
+
<span class="ruby-identifier">delta</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">length_or_note</span>
|
385
|
+
<span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>
|
386
|
+
<span class="ruby-ivar">@sequence</span>.<span class="ruby-identifier">note_to_delta</span>(<span class="ruby-identifier">length_or_note</span>)
|
387
|
+
<span class="ruby-keyword">else</span>
|
388
|
+
<span class="ruby-ivar">@sequence</span>.<span class="ruby-identifier">length_to_delta</span>(<span class="ruby-identifier">length_or_note</span>.<span class="ruby-identifier">to_i</span>)
|
389
|
+
<span class="ruby-keyword">end</span>
|
390
|
+
<span class="ruby-ivar">@events</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">event</span><span class="ruby-operator">|</span> <span class="ruby-identifier">event</span>.<span class="ruby-identifier">quantize_to</span>(<span class="ruby-identifier">delta</span>) }
|
391
|
+
<span class="ruby-identifier">recalc_delta_from_times</span>
|
627
392
|
<span class="ruby-keyword">end</span></pre>
|
628
|
-
</div
|
629
|
-
|
393
|
+
</div>
|
630
394
|
</div>
|
631
395
|
|
632
|
-
|
633
396
|
|
634
|
-
|
635
|
-
</div><!-- quantize-method -->
|
397
|
+
</div>
|
636
398
|
|
637
|
-
|
638
399
|
<div id="method-i-recalc_delta_from_times" class="method-detail ">
|
639
|
-
|
640
400
|
<div class="method-heading">
|
641
401
|
<span class="method-name">recalc_delta_from_times</span><span
|
642
|
-
class="method-args">(starting_at=0, list
|
402
|
+
class="method-args">(starting_at = 0, list = @events)</span>
|
643
403
|
<span class="method-click-advice">click to toggle source</span>
|
644
404
|
</div>
|
645
|
-
|
646
405
|
|
647
406
|
<div class="method-description">
|
648
|
-
|
649
|
-
<p>The opposite of <a
|
650
|
-
href="Track.html#method-i-recalc_times">#recalc_times</a>: recalculates
|
651
|
-
delta_time for each event from each event's time_from_start. This is
|
652
|
-
useful, for example, when merging two event lists. As a side-effect,
|
653
|
-
elements from starting_at are sorted by time_from_start.</p>
|
654
|
-
|
407
|
+
<p>The opposite of <a href="Track.html#method-i-recalc_times"><code>recalc_times</code></a>: recalculates delta_time for each event from each event’s time_from_start. This is useful, for example, when merging two event lists. As a side-effect, elements from starting_at are sorted by time_from_start.</p>
|
655
408
|
|
656
|
-
|
657
409
|
<div class="method-source-code" id="recalc_delta_from_times-source">
|
658
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
659
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">recalc_delta_from_times</span>(<span class="ruby-identifier">starting_at</span
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
410
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 109</span>
|
411
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">recalc_delta_from_times</span>(<span class="ruby-identifier">starting_at</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">list</span> = <span class="ruby-ivar">@events</span>)
|
412
|
+
<span class="ruby-identifier">prev_time_from_start</span> = <span class="ruby-value">0</span>
|
413
|
+
<span class="ruby-comment"># We need to sort the sublist. sublist.sort! does not do what we want.</span>
|
414
|
+
<span class="ruby-comment"># We call mergesort instead of Array.sort because sort is not stable</span>
|
415
|
+
<span class="ruby-comment"># (it can mix up the order of events that have the same start time).</span>
|
416
|
+
<span class="ruby-comment"># See http://wiki.github.com/adamjmurray/cosy/midilib-notes for details.</span>
|
417
|
+
<span class="ruby-identifier">list</span>[<span class="ruby-identifier">starting_at</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] = <span class="ruby-identifier">mergesort</span>(<span class="ruby-identifier">list</span>[<span class="ruby-identifier">starting_at</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e1</span>, <span class="ruby-identifier">e2</span><span class="ruby-operator">|</span>
|
418
|
+
<span class="ruby-identifier">e1</span>.<span class="ruby-identifier">time_from_start</span> <span class="ruby-operator"><=></span> <span class="ruby-identifier">e2</span>.<span class="ruby-identifier">time_from_start</span>
|
419
|
+
<span class="ruby-keyword">end</span>
|
420
|
+
<span class="ruby-identifier">list</span>[<span class="ruby-identifier">starting_at</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
|
421
|
+
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">delta_time</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">time_from_start</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">prev_time_from_start</span>
|
422
|
+
<span class="ruby-identifier">prev_time_from_start</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">time_from_start</span>
|
423
|
+
<span class="ruby-keyword">end</span>
|
672
424
|
<span class="ruby-keyword">end</span></pre>
|
673
|
-
</div
|
674
|
-
|
425
|
+
</div>
|
675
426
|
</div>
|
676
427
|
|
677
|
-
|
678
428
|
<div class="aliases">
|
679
429
|
Also aliased as: <a href="Track.html#method-i-sort">sort</a>
|
680
430
|
</div>
|
681
|
-
|
682
431
|
|
683
|
-
|
684
|
-
</div><!-- recalc_delta_from_times-method -->
|
432
|
+
</div>
|
685
433
|
|
686
|
-
|
687
434
|
<div id="method-i-recalc_times" class="method-detail ">
|
688
|
-
|
689
435
|
<div class="method-heading">
|
690
436
|
<span class="method-name">recalc_times</span><span
|
691
|
-
class="method-args">(starting_at=0, list
|
437
|
+
class="method-args">(starting_at = 0, list = @events)</span>
|
692
438
|
<span class="method-click-advice">click to toggle source</span>
|
693
439
|
</div>
|
694
|
-
|
695
440
|
|
696
441
|
<div class="method-description">
|
697
|
-
|
698
|
-
<p>Recalculate start times for all events in <code>list</code> from
|
699
|
-
starting_at to end.</p>
|
700
|
-
|
442
|
+
<p>Recalculate start times for all events in <code>list</code> from starting_at to end.</p>
|
701
443
|
|
702
|
-
|
703
444
|
<div class="method-source-code" id="recalc_times-source">
|
704
|
-
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line
|
705
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">recalc_times</span>(<span class="ruby-identifier">starting_at</span
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
445
|
+
<pre><span class="ruby-comment"># File lib/midilib/track.rb, line 97</span>
|
446
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">recalc_times</span>(<span class="ruby-identifier">starting_at</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">list</span> = <span class="ruby-ivar">@events</span>)
|
447
|
+
<span class="ruby-identifier">t</span> = <span class="ruby-identifier">starting_at</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">list</span>[<span class="ruby-identifier">starting_at</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>].<span class="ruby-identifier">time_from_start</span>
|
448
|
+
<span class="ruby-identifier">list</span>[<span class="ruby-identifier">starting_at</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
|
449
|
+
<span class="ruby-identifier">t</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">delta_time</span>
|
450
|
+
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">time_from_start</span> = <span class="ruby-identifier">t</span>
|
451
|
+
<span class="ruby-keyword">end</span>
|
711
452
|
<span class="ruby-keyword">end</span></pre>
|
712
|
-
</div
|
713
|
-
|
453
|
+
</div>
|
714
454
|
</div>
|
715
455
|
|
716
|
-
|
717
456
|
|
718
|
-
|
719
|
-
</div><!-- recalc_times-method -->
|
457
|
+
</div>
|
720
458
|
|
721
|
-
|
722
459
|
<div id="method-i-sort" class="method-detail method-alias">
|
723
|
-
|
724
460
|
<div class="method-heading">
|
725
461
|
<span class="method-name">sort</span><span
|
726
|
-
class="method-args">(starting_at=0, list
|
727
|
-
<span class="method-click-advice">click to toggle source</span>
|
462
|
+
class="method-args">(starting_at = 0, list = @events)</span>
|
728
463
|
</div>
|
729
|
-
|
730
464
|
|
731
465
|
<div class="method-description">
|
732
|
-
|
733
|
-
|
734
|
-
href="Track.html#method-i-recalc_delta_from_times"
|
735
|
-
is called to make sure that the delta times reflect the possibly new event
|
736
|
-
order.</p>
|
737
|
-
|
738
|
-
<p>Note: this method is redundant, since <a
|
739
|
-
href="Track.html#method-i-recalc_delta_from_times">#recalc_delta_from_times</a>
|
740
|
-
sorts the events first. This method may go away in a future release, or at
|
741
|
-
least be aliased to recalc_delta_from_times.</p>
|
742
|
-
|
466
|
+
<p>Sort events by their time_from_start. After sorting, <a href="Track.html#method-i-recalc_delta_from_times"><code>recalc_delta_from_times</code></a> is called to make sure that the delta times reflect the possibly new event order.</p>
|
467
|
+
|
468
|
+
<p>Note: this method is redundant, since <a href="Track.html#method-i-recalc_delta_from_times"><code>recalc_delta_from_times</code></a> sorts the events first. This method may go away in a future release, or at least be aliased to recalc_delta_from_times.</p>
|
743
469
|
|
744
|
-
|
745
470
|
</div>
|
746
471
|
|
747
|
-
|
748
472
|
|
749
|
-
|
750
473
|
<div class="aliases">
|
751
474
|
Alias for: <a href="Track.html#method-i-recalc_delta_from_times">recalc_delta_from_times</a>
|
752
475
|
</div>
|
753
|
-
|
754
|
-
</div><!-- sort-method -->
|
476
|
+
</div>
|
755
477
|
|
756
|
-
|
757
|
-
</section><!-- public-instance-method-details -->
|
758
|
-
|
759
|
-
</section><!-- 5Buntitled-5D -->
|
478
|
+
</section>
|
760
479
|
|
761
|
-
</
|
480
|
+
</section>
|
481
|
+
</main>
|
762
482
|
|
763
483
|
|
764
|
-
<footer id="validator-badges">
|
765
|
-
<p><a href="
|
766
|
-
<p>Generated by <a href="https://github.
|
767
|
-
<p>
|
484
|
+
<footer id="validator-badges" role="contentinfo">
|
485
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
486
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.
|
487
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
768
488
|
</footer>
|
769
489
|
|