midilib 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/Credits +5 -0
  3. data/html/MIDI/ActiveSense.html +171 -0
  4. data/html/MIDI/ChannelEvent.html +190 -0
  5. data/html/MIDI/ChannelPressure.html +212 -0
  6. data/html/MIDI/Clock.html +171 -0
  7. data/html/MIDI/Continue.html +171 -0
  8. data/html/MIDI/Controller.html +224 -0
  9. data/html/MIDI/Event.html +349 -0
  10. data/html/MIDI/IO/MIDIFile.html +1392 -0
  11. data/html/MIDI/IO/SeqReader.html +642 -0
  12. data/html/MIDI/IO/SeqWriter.html +442 -0
  13. data/html/MIDI/IO.html +91 -0
  14. data/html/MIDI/KeySig.html +292 -0
  15. data/html/MIDI/Marker.html +138 -0
  16. data/html/MIDI/Measure.html +260 -0
  17. data/html/MIDI/Measures.html +222 -0
  18. data/html/MIDI/MetaEvent.html +353 -0
  19. data/html/MIDI/NoteEvent.html +255 -0
  20. data/html/MIDI/NoteOff.html +188 -0
  21. data/html/MIDI/NoteOn.html +188 -0
  22. data/html/MIDI/PitchBend.html +213 -0
  23. data/html/MIDI/PolyPressure.html +216 -0
  24. data/html/MIDI/ProgramChange.html +212 -0
  25. data/html/MIDI/Realtime.html +194 -0
  26. data/html/MIDI/Sequence.html +641 -0
  27. data/html/MIDI/SongPointer.html +213 -0
  28. data/html/MIDI/SongSelect.html +212 -0
  29. data/html/MIDI/Start.html +171 -0
  30. data/html/MIDI/Stop.html +171 -0
  31. data/html/MIDI/SystemCommon.html +138 -0
  32. data/html/MIDI/SystemExclusive.html +215 -0
  33. data/html/MIDI/SystemReset.html +171 -0
  34. data/html/MIDI/Tempo.html +292 -0
  35. data/html/MIDI/TimeSig.html +286 -0
  36. data/html/MIDI/Track.html +489 -0
  37. data/html/MIDI/TuneRequest.html +194 -0
  38. data/html/MIDI/Utils.html +178 -0
  39. data/html/MIDI.html +281 -0
  40. data/html/Object.html +197 -0
  41. data/html/README_rdoc.html +545 -0
  42. data/html/TODO_rdoc.html +123 -0
  43. data/html/created.rid +15 -0
  44. data/html/css/fonts.css +167 -0
  45. data/html/css/rdoc.css +639 -0
  46. data/html/fonts/Lato-Light.ttf +0 -0
  47. data/html/fonts/Lato-LightItalic.ttf +0 -0
  48. data/html/fonts/Lato-Regular.ttf +0 -0
  49. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  50. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  51. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  52. data/html/images/add.png +0 -0
  53. data/html/images/arrow_up.png +0 -0
  54. data/html/images/brick.png +0 -0
  55. data/html/images/brick_link.png +0 -0
  56. data/html/images/bug.png +0 -0
  57. data/html/images/bullet_black.png +0 -0
  58. data/html/images/bullet_toggle_minus.png +0 -0
  59. data/html/images/bullet_toggle_plus.png +0 -0
  60. data/html/images/date.png +0 -0
  61. data/html/images/delete.png +0 -0
  62. data/html/images/find.png +0 -0
  63. data/html/images/loadingAnimation.gif +0 -0
  64. data/html/images/macFFBgHack.png +0 -0
  65. data/html/images/package.png +0 -0
  66. data/html/images/page_green.png +0 -0
  67. data/html/images/page_white_text.png +0 -0
  68. data/html/images/page_white_width.png +0 -0
  69. data/html/images/plugin.png +0 -0
  70. data/html/images/ruby.png +0 -0
  71. data/html/images/tag_blue.png +0 -0
  72. data/html/images/tag_green.png +0 -0
  73. data/html/images/transparent.png +0 -0
  74. data/html/images/wrench.png +0 -0
  75. data/html/images/wrench_orange.png +0 -0
  76. data/html/images/zoom.png +0 -0
  77. data/html/index.html +534 -0
  78. data/html/js/darkfish.js +84 -0
  79. data/html/js/navigation.js +105 -0
  80. data/html/js/navigation.js.gz +0 -0
  81. data/html/js/search.js +110 -0
  82. data/html/js/search_index.js +1 -0
  83. data/html/js/search_index.js.gz +0 -0
  84. data/html/js/searcher.js +229 -0
  85. data/html/js/searcher.js.gz +0 -0
  86. data/html/table_of_contents.html +1258 -0
  87. data/lib/midilib/info.rb +2 -2
  88. data/lib/midilib/io/seqreader.rb +18 -5
  89. data/test/test_io.rb +18 -5
  90. metadata +85 -1
@@ -0,0 +1,489 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>class MIDI::Track - midilib</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "../";
11
+ var index_rel_prefix = "../";
12
+ </script>
13
+
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">
22
+
23
+
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>
34
+ <a href="../table_of_contents.html#classes">Classes</a>
35
+ <a href="../table_of_contents.html#methods">Methods</a>
36
+ </div>
37
+ </div>
38
+
39
+ <div id="search-section" role="search" class="project-section initially-hidden">
40
+ <form action="#" method="get" accept-charset="utf-8">
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"
45
+ title="Type to search, Up and Down to navigate, Enter to load">
46
+ </div>
47
+
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
+
54
+ </div>
55
+
56
+
57
+
58
+ <div id="class-metadata">
59
+
60
+
61
+ <div id="parent-class-section" class="nav-section">
62
+ <h3>Parent</h3>
63
+
64
+ <p class="link"><a href="../Object.html">Object</a>
65
+ </div>
66
+
67
+
68
+ <div id="includes-section" class="nav-section">
69
+ <h3>Included Modules</h3>
70
+
71
+ <ul class="link-list">
72
+ <li><span class="include">Enumerable</span>
73
+ </ul>
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>
97
+
98
+ </div>
99
+ </nav>
100
+
101
+ <main role="main" aria-labelledby="class-MIDI::Track">
102
+ <h1 id="class-MIDI::Track" class="class">
103
+ class MIDI::Track
104
+ </h1>
105
+
106
+ <section class="description">
107
+
108
+ <p>A <a href="Track.html"><code>Track</code></a> is a list of events.</p>
109
+
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>
111
+
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>
113
+
114
+ </section>
115
+
116
+ <section id="5Buntitled-5D" class="documentation-section">
117
+
118
+
119
+ <section class="constants-list">
120
+ <header>
121
+ <h3>Constants</h3>
122
+ </header>
123
+ <dl>
124
+ <dt id="UNNAMED">UNNAMED
125
+ <dd>
126
+ </dl>
127
+ </section>
128
+
129
+ <section class="attribute-method-details" class="method-section">
130
+ <header>
131
+ <h3>Attributes</h3>
132
+ </header>
133
+
134
+ <div id="attribute-i-channels_used" class="method-detail">
135
+ <div class="method-heading attribute-method-heading">
136
+ <span class="method-name">channels_used</span><span
137
+ class="attribute-access-type">[RW]</span>
138
+ </div>
139
+
140
+ <div class="method-description">
141
+
142
+ </div>
143
+ </div>
144
+ <div id="attribute-i-events" class="method-detail">
145
+ <div class="method-heading attribute-method-heading">
146
+ <span class="method-name">events</span><span
147
+ class="attribute-access-type">[RW]</span>
148
+ </div>
149
+
150
+ <div class="method-description">
151
+
152
+ </div>
153
+ </div>
154
+ <div id="attribute-i-sequence" class="method-detail">
155
+ <div class="method-heading attribute-method-heading">
156
+ <span class="method-name">sequence</span><span
157
+ class="attribute-access-type">[R]</span>
158
+ </div>
159
+
160
+ <div class="method-description">
161
+
162
+ </div>
163
+ </div>
164
+ </section>
165
+
166
+
167
+ <section id="public-class-5Buntitled-5D-method-details" class="method-section">
168
+ <header>
169
+ <h3>Public Class Methods</h3>
170
+ </header>
171
+
172
+ <div id="method-c-new" class="method-detail ">
173
+ <div class="method-heading">
174
+ <span class="method-name">new</span><span
175
+ class="method-args">(sequence)</span>
176
+ <span class="method-click-advice">click to toggle source</span>
177
+ </div>
178
+
179
+ <div class="method-description">
180
+
181
+
182
+ <div class="method-source-code" id="new-source">
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>
192
+ <span class="ruby-keyword">end</span></pre>
193
+ </div>
194
+ </div>
195
+
196
+
197
+ </div>
198
+
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>
205
+
206
+ <div id="method-i-each" class="method-detail ">
207
+ <div class="method-heading">
208
+ <span class="method-name">each</span><span
209
+ class="method-args">() { |event| ... }</span>
210
+ <span class="method-click-advice">click to toggle source</span>
211
+ </div>
212
+
213
+ <div class="method-description">
214
+ <p>Iterate over events.</p>
215
+
216
+ <div class="method-source-code" id="each-source">
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">&amp;</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">&amp;</span><span class="ruby-identifier">block</span>)
220
+ <span class="ruby-keyword">end</span></pre>
221
+ </div>
222
+ </div>
223
+
224
+
225
+ </div>
226
+
227
+ <div id="method-i-instrument" class="method-detail ">
228
+ <div class="method-heading">
229
+ <span class="method-name">instrument</span><span
230
+ class="method-args">()</span>
231
+ <span class="method-click-advice">click to toggle source</span>
232
+ </div>
233
+
234
+ <div class="method-description">
235
+
236
+
237
+ <div class="method-source-code" id="instrument-source">
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>)
241
+ <span class="ruby-keyword">end</span></pre>
242
+ </div>
243
+ </div>
244
+
245
+
246
+ </div>
247
+
248
+ <div id="method-i-instrument-3D" class="method-detail ">
249
+ <div class="method-heading">
250
+ <span class="method-name">instrument=</span><span
251
+ class="method-args">(str_or_bytes)</span>
252
+ <span class="method-click-advice">click to toggle source</span>
253
+ </div>
254
+
255
+ <div class="method-description">
256
+
257
+
258
+ <div class="method-source-code" id="instrument-3D-source">
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>
267
+ <span class="ruby-keyword">end</span></pre>
268
+ </div>
269
+ </div>
270
+
271
+
272
+ </div>
273
+
274
+ <div id="method-i-merge" class="method-detail ">
275
+ <div class="method-heading">
276
+ <span class="method-name">merge</span><span
277
+ class="method-args">(event_list)</span>
278
+ <span class="method-click-advice">click to toggle source</span>
279
+ </div>
280
+
281
+ <div class="method-description">
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>
283
+
284
+ <div class="method-source-code" id="merge-source">
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>)
288
+ <span class="ruby-keyword">end</span></pre>
289
+ </div>
290
+ </div>
291
+
292
+
293
+ </div>
294
+
295
+ <div id="method-i-merge_event_lists" class="method-detail ">
296
+ <div class="method-heading">
297
+ <span class="method-name">merge_event_lists</span><span
298
+ class="method-args">(list1, list2)</span>
299
+ <span class="method-click-advice">click to toggle source</span>
300
+ </div>
301
+
302
+ <div class="method-description">
303
+ <p>Merges two event arrays together. Does not modify this track.</p>
304
+
305
+ <div class="method-source-code" id="merge_event_lists-source">
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>
313
+ <span class="ruby-keyword">end</span></pre>
314
+ </div>
315
+ </div>
316
+
317
+
318
+ </div>
319
+
320
+ <div id="method-i-name" class="method-detail ">
321
+ <div class="method-heading">
322
+ <span class="method-name">name</span><span
323
+ class="method-args">()</span>
324
+ <span class="method-click-advice">click to toggle source</span>
325
+ </div>
326
+
327
+ <div class="method-description">
328
+ <p>Return track name. If there is no name, return <a href="Track.html#UNNAMED"><code>UNNAMED</code></a>.</p>
329
+
330
+ <div class="method-source-code" id="name-source">
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">&amp;&amp;</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>
335
+ <span class="ruby-keyword">end</span></pre>
336
+ </div>
337
+ </div>
338
+
339
+
340
+ </div>
341
+
342
+ <div id="method-i-name-3D" class="method-detail ">
343
+ <div class="method-heading">
344
+ <span class="method-name">name=</span><span
345
+ class="method-args">(name)</span>
346
+ <span class="method-click-advice">click to toggle source</span>
347
+ </div>
348
+
349
+ <div class="method-description">
350
+ <p>Set track name. Replaces or creates a name meta-event.</p>
351
+
352
+ <div class="method-source-code" id="name-3D-source">
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">&amp;&amp;</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>
362
+ <span class="ruby-keyword">end</span></pre>
363
+ </div>
364
+ </div>
365
+
366
+
367
+ </div>
368
+
369
+ <div id="method-i-quantize" class="method-detail ">
370
+ <div class="method-heading">
371
+ <span class="method-name">quantize</span><span
372
+ class="method-args">(length_or_note)</span>
373
+ <span class="method-click-advice">click to toggle source</span>
374
+ </div>
375
+
376
+ <div class="method-description">
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>
378
+
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>
380
+
381
+ <div class="method-source-code" id="quantize-source">
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>
392
+ <span class="ruby-keyword">end</span></pre>
393
+ </div>
394
+ </div>
395
+
396
+
397
+ </div>
398
+
399
+ <div id="method-i-recalc_delta_from_times" class="method-detail ">
400
+ <div class="method-heading">
401
+ <span class="method-name">recalc_delta_from_times</span><span
402
+ class="method-args">(starting_at = 0, list = @events)</span>
403
+ <span class="method-click-advice">click to toggle source</span>
404
+ </div>
405
+
406
+ <div class="method-description">
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>
408
+
409
+ <div class="method-source-code" id="recalc_delta_from_times-source">
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">&lt;=&gt;</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>
424
+ <span class="ruby-keyword">end</span></pre>
425
+ </div>
426
+ </div>
427
+
428
+ <div class="aliases">
429
+ Also aliased as: <a href="Track.html#method-i-sort">sort</a>
430
+ </div>
431
+
432
+ </div>
433
+
434
+ <div id="method-i-recalc_times" class="method-detail ">
435
+ <div class="method-heading">
436
+ <span class="method-name">recalc_times</span><span
437
+ class="method-args">(starting_at = 0, list = @events)</span>
438
+ <span class="method-click-advice">click to toggle source</span>
439
+ </div>
440
+
441
+ <div class="method-description">
442
+ <p>Recalculate start times for all events in <code>list</code> from starting_at to end.</p>
443
+
444
+ <div class="method-source-code" id="recalc_times-source">
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>
452
+ <span class="ruby-keyword">end</span></pre>
453
+ </div>
454
+ </div>
455
+
456
+
457
+ </div>
458
+
459
+ <div id="method-i-sort" class="method-detail method-alias">
460
+ <div class="method-heading">
461
+ <span class="method-name">sort</span><span
462
+ class="method-args">(starting_at = 0, list = @events)</span>
463
+ </div>
464
+
465
+ <div class="method-description">
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>
469
+
470
+ </div>
471
+
472
+
473
+ <div class="aliases">
474
+ Alias for: <a href="Track.html#method-i-recalc_delta_from_times">recalc_delta_from_times</a>
475
+ </div>
476
+ </div>
477
+
478
+ </section>
479
+
480
+ </section>
481
+ </main>
482
+
483
+
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>.
488
+ </footer>
489
+