midilib 2.0.2 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Credits +5 -0
- data/README.rdoc +35 -30
- data/examples/reader2text.rb +1 -0
- data/html/IO.html +259 -0
- data/html/MIDI.html +665 -0
- data/html/MIDI/ActiveSense.html +295 -0
- data/html/MIDI/ChannelEvent.html +319 -0
- data/html/MIDI/ChannelPressure.html +350 -0
- data/html/MIDI/Clock.html +295 -0
- data/html/MIDI/Continue.html +295 -0
- data/html/MIDI/Controller.html +365 -0
- data/html/MIDI/Event.html +573 -0
- data/html/MIDI/IO.html +207 -0
- data/html/MIDI/IO/MIDIFile.html +1996 -0
- data/html/MIDI/IO/SeqReader.html +946 -0
- data/html/MIDI/IO/SeqWriter.html +648 -0
- data/html/MIDI/KeySig.html +435 -0
- data/html/MIDI/MIDI.html +204 -0
- data/html/MIDI/MIDI/MIDI.html +204 -0
- data/html/MIDI/MIDI/MIDI/Array.html +353 -0
- data/html/MIDI/Marker.html +257 -0
- data/html/MIDI/Measure.html +423 -0
- data/html/MIDI/Measures.html +375 -0
- data/html/MIDI/MetaEvent.html +534 -0
- data/html/MIDI/NoteEvent.html +417 -0
- data/html/MIDI/NoteOff.html +316 -0
- data/html/MIDI/NoteOn.html +316 -0
- data/html/MIDI/PitchBend.html +351 -0
- data/html/MIDI/PolyPressure.html +360 -0
- data/html/MIDI/ProgramChange.html +350 -0
- data/html/MIDI/Realtime.html +328 -0
- data/html/MIDI/Sequence.html +961 -0
- data/html/MIDI/SongPointer.html +351 -0
- data/html/MIDI/SongSelect.html +350 -0
- data/html/MIDI/Start.html +295 -0
- data/html/MIDI/Stop.html +295 -0
- data/html/MIDI/SystemCommon.html +257 -0
- data/html/MIDI/SystemExclusive.html +353 -0
- data/html/MIDI/SystemReset.html +295 -0
- data/html/MIDI/Tempo.html +474 -0
- data/html/MIDI/TimeSig.html +467 -0
- data/html/MIDI/Track.html +769 -0
- data/html/MIDI/TuneRequest.html +328 -0
- data/html/MIDI/Utils.html +320 -0
- data/html/README_rdoc.html +751 -0
- data/html/TODO_rdoc.html +200 -0
- data/html/created.rid +14 -0
- data/html/images/add.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +750 -0
- data/html/js/darkfish.js +153 -0
- data/html/js/jquery.js +18 -0
- data/html/js/navigation.js +142 -0
- data/html/js/search.js +94 -0
- data/html/js/search_index.js +1 -0
- data/html/js/searcher.js +228 -0
- data/html/rdoc.css +543 -0
- data/html/table_of_contents.html +652 -0
- data/lib/midilib/info.rb +1 -1
- data/lib/midilib/io/seqreader.rb +1 -1
- data/lib/midilib/sequence.rb +7 -0
- data/test/test_sequence.rb +11 -0
- metadata +80 -3
@@ -0,0 +1,648 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>class MIDI::IO::SeqWriter - midilib</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="../../rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "../../";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="../../js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="../../js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="../../js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="../../js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="../../js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body id="top" class="class">
|
24
|
+
<nav id="metadata">
|
25
|
+
<nav id="home-section" class="section">
|
26
|
+
<h3 class="section-header">
|
27
|
+
<a href="../../index.html">Home</a>
|
28
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
29
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
30
|
+
</h3>
|
31
|
+
</nav>
|
32
|
+
|
33
|
+
|
34
|
+
<nav id="search-section" class="section project-section" class="initially-hidden">
|
35
|
+
<form action="#" method="get" accept-charset="utf-8">
|
36
|
+
<h3 class="section-header">
|
37
|
+
<input type="text" name="search" placeholder="Search" id="search-field"
|
38
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
39
|
+
</h3>
|
40
|
+
</form>
|
41
|
+
|
42
|
+
<ul id="search-results" class="initially-hidden"></ul>
|
43
|
+
</nav>
|
44
|
+
|
45
|
+
|
46
|
+
<div id="file-metadata">
|
47
|
+
<nav id="file-list-section" class="section">
|
48
|
+
<h3 class="section-header">Defined In</h3>
|
49
|
+
<ul>
|
50
|
+
<li>lib/midilib/io/seqwriter.rb
|
51
|
+
</ul>
|
52
|
+
</nav>
|
53
|
+
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
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
|
+
|
67
|
+
<!-- Method Quickref -->
|
68
|
+
<nav id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
<li><a href="#method-c-new">::new</a>
|
74
|
+
|
75
|
+
<li><a href="#method-i-possibly_munge_due_to_running_status_byte">#possibly_munge_due_to_running_status_byte</a>
|
76
|
+
|
77
|
+
<li><a href="#method-i-write16">#write16</a>
|
78
|
+
|
79
|
+
<li><a href="#method-i-write32">#write32</a>
|
80
|
+
|
81
|
+
<li><a href="#method-i-write_bytes">#write_bytes</a>
|
82
|
+
|
83
|
+
<li><a href="#method-i-write_header">#write_header</a>
|
84
|
+
|
85
|
+
<li><a href="#method-i-write_instrument">#write_instrument</a>
|
86
|
+
|
87
|
+
<li><a href="#method-i-write_to">#write_to</a>
|
88
|
+
|
89
|
+
<li><a href="#method-i-write_track">#write_track</a>
|
90
|
+
|
91
|
+
<li><a href="#method-i-write_var_len">#write_var_len</a>
|
92
|
+
|
93
|
+
</ul>
|
94
|
+
</nav>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
|
98
|
+
<div id="project-metadata">
|
99
|
+
<nav id="fileindex-section" class="section project-section">
|
100
|
+
<h3 class="section-header">Pages</h3>
|
101
|
+
|
102
|
+
<ul>
|
103
|
+
|
104
|
+
<li class="file"><a href="../../README_rdoc.html">README</a>
|
105
|
+
|
106
|
+
<li class="file"><a href="../../TODO_rdoc.html">TODO</a>
|
107
|
+
|
108
|
+
</ul>
|
109
|
+
</nav>
|
110
|
+
|
111
|
+
<nav id="classindex-section" class="section project-section">
|
112
|
+
<h3 class="section-header">Class and Module Index</h3>
|
113
|
+
|
114
|
+
<ul class="link-list">
|
115
|
+
|
116
|
+
<li><a href="../../MIDI.html">MIDI</a>
|
117
|
+
|
118
|
+
<li><a href="../../MIDI/ActiveSense.html">MIDI::ActiveSense</a>
|
119
|
+
|
120
|
+
<li><a href="../../MIDI/ChannelEvent.html">MIDI::ChannelEvent</a>
|
121
|
+
|
122
|
+
<li><a href="../../MIDI/ChannelPressure.html">MIDI::ChannelPressure</a>
|
123
|
+
|
124
|
+
<li><a href="../../MIDI/Clock.html">MIDI::Clock</a>
|
125
|
+
|
126
|
+
<li><a href="../../MIDI/Continue.html">MIDI::Continue</a>
|
127
|
+
|
128
|
+
<li><a href="../../MIDI/Controller.html">MIDI::Controller</a>
|
129
|
+
|
130
|
+
<li><a href="../../MIDI/Event.html">MIDI::Event</a>
|
131
|
+
|
132
|
+
<li><a href="../../MIDI/IO.html">MIDI::IO</a>
|
133
|
+
|
134
|
+
<li><a href="../../MIDI/IO/MIDIFile.html">MIDI::IO::MIDIFile</a>
|
135
|
+
|
136
|
+
<li><a href="../../MIDI/IO/SeqReader.html">MIDI::IO::SeqReader</a>
|
137
|
+
|
138
|
+
<li><a href="../../MIDI/IO/SeqWriter.html">MIDI::IO::SeqWriter</a>
|
139
|
+
|
140
|
+
<li><a href="../../MIDI/KeySig.html">MIDI::KeySig</a>
|
141
|
+
|
142
|
+
<li><a href="../../MIDI/MIDI.html">MIDI::MIDI</a>
|
143
|
+
|
144
|
+
<li><a href="../../MIDI/MIDI/MIDI.html">MIDI::MIDI::MIDI</a>
|
145
|
+
|
146
|
+
<li><a href="../../MIDI/MIDI/MIDI/Array.html">MIDI::MIDI::MIDI::Array</a>
|
147
|
+
|
148
|
+
<li><a href="../../MIDI/Marker.html">MIDI::Marker</a>
|
149
|
+
|
150
|
+
<li><a href="../../MIDI/Measure.html">MIDI::Measure</a>
|
151
|
+
|
152
|
+
<li><a href="../../MIDI/Measures.html">MIDI::Measures</a>
|
153
|
+
|
154
|
+
<li><a href="../../MIDI/MetaEvent.html">MIDI::MetaEvent</a>
|
155
|
+
|
156
|
+
<li><a href="../../MIDI/NoteEvent.html">MIDI::NoteEvent</a>
|
157
|
+
|
158
|
+
<li><a href="../../MIDI/NoteOff.html">MIDI::NoteOff</a>
|
159
|
+
|
160
|
+
<li><a href="../../MIDI/NoteOff.html">MIDI::NoteOffEvent</a>
|
161
|
+
|
162
|
+
<li><a href="../../MIDI/NoteOn.html">MIDI::NoteOn</a>
|
163
|
+
|
164
|
+
<li><a href="../../MIDI/NoteOn.html">MIDI::NoteOnEvent</a>
|
165
|
+
|
166
|
+
<li><a href="../../MIDI/PitchBend.html">MIDI::PitchBend</a>
|
167
|
+
|
168
|
+
<li><a href="../../MIDI/PolyPressure.html">MIDI::PolyPressure</a>
|
169
|
+
|
170
|
+
<li><a href="../../MIDI/ProgramChange.html">MIDI::ProgramChange</a>
|
171
|
+
|
172
|
+
<li><a href="../../MIDI/Realtime.html">MIDI::Realtime</a>
|
173
|
+
|
174
|
+
<li><a href="../../MIDI/Sequence.html">MIDI::Sequence</a>
|
175
|
+
|
176
|
+
<li><a href="../../MIDI/SongPointer.html">MIDI::SongPointer</a>
|
177
|
+
|
178
|
+
<li><a href="../../MIDI/SongSelect.html">MIDI::SongSelect</a>
|
179
|
+
|
180
|
+
<li><a href="../../MIDI/Start.html">MIDI::Start</a>
|
181
|
+
|
182
|
+
<li><a href="../../MIDI/Stop.html">MIDI::Stop</a>
|
183
|
+
|
184
|
+
<li><a href="../../MIDI/SystemCommon.html">MIDI::SystemCommon</a>
|
185
|
+
|
186
|
+
<li><a href="../../MIDI/SystemExclusive.html">MIDI::SystemExclusive</a>
|
187
|
+
|
188
|
+
<li><a href="../../MIDI/SystemReset.html">MIDI::SystemReset</a>
|
189
|
+
|
190
|
+
<li><a href="../../MIDI/Tempo.html">MIDI::Tempo</a>
|
191
|
+
|
192
|
+
<li><a href="../../MIDI/TimeSig.html">MIDI::TimeSig</a>
|
193
|
+
|
194
|
+
<li><a href="../../MIDI/Track.html">MIDI::Track</a>
|
195
|
+
|
196
|
+
<li><a href="../../MIDI/TuneRequest.html">MIDI::TuneRequest</a>
|
197
|
+
|
198
|
+
<li><a href="../../MIDI/Utils.html">MIDI::Utils</a>
|
199
|
+
|
200
|
+
<li><a href="../../IO.html">IO</a>
|
201
|
+
|
202
|
+
</ul>
|
203
|
+
</nav>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
</nav>
|
207
|
+
|
208
|
+
<div id="documentation">
|
209
|
+
<h1 class="class">class MIDI::IO::SeqWriter</h1>
|
210
|
+
|
211
|
+
<div id="description" class="description">
|
212
|
+
|
213
|
+
</div><!-- description -->
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<!-- Methods -->
|
228
|
+
|
229
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
230
|
+
<h3 class="section-header">Public Class Methods</h3>
|
231
|
+
|
232
|
+
|
233
|
+
<div id="method-c-new" class="method-detail ">
|
234
|
+
|
235
|
+
<div class="method-heading">
|
236
|
+
<span class="method-name">new</span><span
|
237
|
+
class="method-args">(seq, proc = nil) { |num_tracks, index| ... }</span>
|
238
|
+
<span class="method-click-advice">click to toggle source</span>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
<div class="method-description">
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
<div class="method-source-code" id="new-source">
|
249
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 12</span>
|
250
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">seq</span>, <span class="ruby-identifier">proc</span> = <span class="ruby-keyword">nil</span>) <span class="ruby-comment"># :yields: num_tracks, index</span>
|
251
|
+
<span class="ruby-ivar">@seq</span> = <span class="ruby-identifier">seq</span>
|
252
|
+
<span class="ruby-ivar">@update_block</span> = <span class="ruby-identifier">block_given?</span>() <span class="ruby-operator">?</span> <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span>() <span class="ruby-operator">:</span> <span class="ruby-identifier">proc</span>
|
253
|
+
<span class="ruby-keyword">end</span></pre>
|
254
|
+
</div><!-- new-source -->
|
255
|
+
|
256
|
+
</div>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
</div><!-- new-method -->
|
262
|
+
|
263
|
+
|
264
|
+
</section><!-- public-class-method-details -->
|
265
|
+
|
266
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
267
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
268
|
+
|
269
|
+
|
270
|
+
<div id="method-i-possibly_munge_due_to_running_status_byte" class="method-detail ">
|
271
|
+
|
272
|
+
<div class="method-heading">
|
273
|
+
<span class="method-name">possibly_munge_due_to_running_status_byte</span><span
|
274
|
+
class="method-args">(data, prev_status)</span>
|
275
|
+
<span class="method-click-advice">click to toggle source</span>
|
276
|
+
</div>
|
277
|
+
|
278
|
+
|
279
|
+
<div class="method-description">
|
280
|
+
|
281
|
+
<p>If we can use a running status byte, delete the status byte from the given
|
282
|
+
data. Return the status to remember for next time as the running status
|
283
|
+
byte for this event.</p>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
<div class="method-source-code" id="possibly_munge_due_to_running_status_byte-source">
|
288
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 80</span>
|
289
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">possibly_munge_due_to_running_status_byte</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">prev_status</span>)
|
290
|
+
<span class="ruby-identifier">status</span> = <span class="ruby-identifier">data</span>[<span class="ruby-value">0</span>]
|
291
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0xf0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">prev_status</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0xf0</span>
|
292
|
+
|
293
|
+
<span class="ruby-identifier">chan</span> = (<span class="ruby-identifier">status</span> & <span class="ruby-value">0x0f</span>)
|
294
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">chan</span> <span class="ruby-operator">!=</span> (<span class="ruby-identifier">prev_status</span> & <span class="ruby-value">0x0f</span>)
|
295
|
+
|
296
|
+
<span class="ruby-identifier">status</span> = (<span class="ruby-identifier">status</span> & <span class="ruby-value">0xf0</span>)
|
297
|
+
<span class="ruby-identifier">prev_status</span> = (<span class="ruby-identifier">prev_status</span> & <span class="ruby-value">0xf0</span>)
|
298
|
+
|
299
|
+
<span class="ruby-comment"># Both events are on the same channel. If the two status bytes are</span>
|
300
|
+
<span class="ruby-comment"># exactly the same, the rest is trivial. If it's note on/note off,</span>
|
301
|
+
<span class="ruby-comment"># we can combine those further.</span>
|
302
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">prev_status</span>
|
303
|
+
<span class="ruby-identifier">data</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] = [] <span class="ruby-comment"># delete status byte from data</span>
|
304
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">chan</span>
|
305
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-constant">NOTE_OFF</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">data</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">==</span> <span class="ruby-value">64</span>
|
306
|
+
<span class="ruby-comment"># If we see a note off and the velocity is 64, we can store</span>
|
307
|
+
<span class="ruby-comment"># a note on with a velocity of 0. If the velocity isn't 64</span>
|
308
|
+
<span class="ruby-comment"># then storing a note on would be bad because the would be</span>
|
309
|
+
<span class="ruby-comment"># changed to 64 when reading the file back in.</span>
|
310
|
+
<span class="ruby-identifier">data</span>[<span class="ruby-value">2</span>] = <span class="ruby-value">0</span> <span class="ruby-comment"># set vel to 0; do before possible shrinking</span>
|
311
|
+
<span class="ruby-identifier">status</span> = <span class="ruby-constant">NOTE_ON</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">chan</span>
|
312
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">prev_status</span> <span class="ruby-operator">==</span> <span class="ruby-constant">NOTE_ON</span>
|
313
|
+
<span class="ruby-identifier">data</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] = [] <span class="ruby-comment"># delete status byte</span>
|
314
|
+
<span class="ruby-keyword">else</span>
|
315
|
+
<span class="ruby-identifier">data</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">status</span>
|
316
|
+
<span class="ruby-keyword">end</span>
|
317
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">status</span>
|
318
|
+
<span class="ruby-keyword">else</span>
|
319
|
+
<span class="ruby-comment"># Can't compress data</span>
|
320
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">chan</span>
|
321
|
+
<span class="ruby-keyword">end</span>
|
322
|
+
<span class="ruby-keyword">end</span></pre>
|
323
|
+
</div><!-- possibly_munge_due_to_running_status_byte-source -->
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
</div><!-- possibly_munge_due_to_running_status_byte-method -->
|
331
|
+
|
332
|
+
|
333
|
+
<div id="method-i-write16" class="method-detail ">
|
334
|
+
|
335
|
+
<div class="method-heading">
|
336
|
+
<span class="method-name">write16</span><span
|
337
|
+
class="method-args">(val)</span>
|
338
|
+
<span class="method-click-advice">click to toggle source</span>
|
339
|
+
</div>
|
340
|
+
|
341
|
+
|
342
|
+
<div class="method-description">
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
<div class="method-source-code" id="write16-source">
|
349
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 127</span>
|
350
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write16</span>(<span class="ruby-identifier">val</span>)
|
351
|
+
<span class="ruby-identifier">val</span> = (<span class="ruby-operator">-</span><span class="ruby-identifier">val</span> <span class="ruby-operator">|</span> <span class="ruby-value">0x8000</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>
|
352
|
+
|
353
|
+
<span class="ruby-identifier">buffer</span> = []
|
354
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>((<span class="ruby-identifier">val</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) & <span class="ruby-value">0xff</span>)
|
355
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>(<span class="ruby-identifier">val</span> & <span class="ruby-value">0xff</span>)
|
356
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-value">2</span>
|
357
|
+
<span class="ruby-keyword">end</span></pre>
|
358
|
+
</div><!-- write16-source -->
|
359
|
+
|
360
|
+
</div>
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
</div><!-- write16-method -->
|
366
|
+
|
367
|
+
|
368
|
+
<div id="method-i-write32" class="method-detail ">
|
369
|
+
|
370
|
+
<div class="method-heading">
|
371
|
+
<span class="method-name">write32</span><span
|
372
|
+
class="method-args">(val)</span>
|
373
|
+
<span class="method-click-advice">click to toggle source</span>
|
374
|
+
</div>
|
375
|
+
|
376
|
+
|
377
|
+
<div class="method-description">
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
<div class="method-source-code" id="write32-source">
|
384
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 136</span>
|
385
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write32</span>(<span class="ruby-identifier">val</span>)
|
386
|
+
<span class="ruby-identifier">val</span> = (<span class="ruby-operator">-</span><span class="ruby-identifier">val</span> <span class="ruby-operator">|</span> <span class="ruby-value">0x80000000</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>
|
387
|
+
|
388
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>((<span class="ruby-identifier">val</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) & <span class="ruby-value">0xff</span>)
|
389
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>((<span class="ruby-identifier">val</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) & <span class="ruby-value">0xff</span>)
|
390
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>((<span class="ruby-identifier">val</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) & <span class="ruby-value">0xff</span>)
|
391
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>(<span class="ruby-identifier">val</span> & <span class="ruby-value">0xff</span>)
|
392
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
|
393
|
+
<span class="ruby-keyword">end</span></pre>
|
394
|
+
</div><!-- write32-source -->
|
395
|
+
|
396
|
+
</div>
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
</div><!-- write32-method -->
|
402
|
+
|
403
|
+
|
404
|
+
<div id="method-i-write_bytes" class="method-detail ">
|
405
|
+
|
406
|
+
<div class="method-heading">
|
407
|
+
<span class="method-name">write_bytes</span><span
|
408
|
+
class="method-args">(bytes)</span>
|
409
|
+
<span class="method-click-advice">click to toggle source</span>
|
410
|
+
</div>
|
411
|
+
|
412
|
+
|
413
|
+
<div class="method-description">
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
<div class="method-source-code" id="write_bytes-source">
|
420
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 146</span>
|
421
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_bytes</span>(<span class="ruby-identifier">bytes</span>)
|
422
|
+
<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@io</span>.<span class="ruby-identifier">putc</span>(<span class="ruby-identifier">b</span>) }
|
423
|
+
<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">length</span>
|
424
|
+
<span class="ruby-keyword">end</span></pre>
|
425
|
+
</div><!-- write_bytes-source -->
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
</div><!-- write_bytes-method -->
|
433
|
+
|
434
|
+
|
435
|
+
<div id="method-i-write_header" class="method-detail ">
|
436
|
+
|
437
|
+
<div class="method-heading">
|
438
|
+
<span class="method-name">write_header</span><span
|
439
|
+
class="method-args">()</span>
|
440
|
+
<span class="method-click-advice">click to toggle source</span>
|
441
|
+
</div>
|
442
|
+
|
443
|
+
|
444
|
+
<div class="method-description">
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
<div class="method-source-code" id="write_header-source">
|
451
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 29</span>
|
452
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_header</span>
|
453
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">'MThd'</span>
|
454
|
+
<span class="ruby-identifier">write32</span>(<span class="ruby-value">6</span>)
|
455
|
+
<span class="ruby-identifier">write16</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># Ignore sequence format; write as format 1</span>
|
456
|
+
<span class="ruby-identifier">write16</span>(<span class="ruby-ivar">@seq</span>.<span class="ruby-identifier">tracks</span>.<span class="ruby-identifier">length</span>)
|
457
|
+
<span class="ruby-identifier">write16</span>(<span class="ruby-ivar">@seq</span>.<span class="ruby-identifier">ppqn</span>)
|
458
|
+
<span class="ruby-keyword">end</span></pre>
|
459
|
+
</div><!-- write_header-source -->
|
460
|
+
|
461
|
+
</div>
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
</div><!-- write_header-method -->
|
467
|
+
|
468
|
+
|
469
|
+
<div id="method-i-write_instrument" class="method-detail ">
|
470
|
+
|
471
|
+
<div class="method-heading">
|
472
|
+
<span class="method-name">write_instrument</span><span
|
473
|
+
class="method-args">(instrument)</span>
|
474
|
+
<span class="method-click-advice">click to toggle source</span>
|
475
|
+
</div>
|
476
|
+
|
477
|
+
|
478
|
+
<div class="method-description">
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
<div class="method-source-code" id="write_instrument-source">
|
485
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 115</span>
|
486
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_instrument</span>(<span class="ruby-identifier">instrument</span>)
|
487
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-constant">MetaEvent</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">META_INSTRUMENT</span>, <span class="ruby-identifier">instrument</span>)
|
488
|
+
<span class="ruby-identifier">write_var_len</span>(<span class="ruby-value">0</span>)
|
489
|
+
<span class="ruby-identifier">data</span> = <span class="ruby-identifier">event</span>.<span class="ruby-identifier">data_as_bytes</span>()
|
490
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">write_bytes</span>(<span class="ruby-identifier">data</span>)
|
491
|
+
<span class="ruby-keyword">end</span></pre>
|
492
|
+
</div><!-- write_instrument-source -->
|
493
|
+
|
494
|
+
</div>
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
</div><!-- write_instrument-method -->
|
500
|
+
|
501
|
+
|
502
|
+
<div id="method-i-write_to" class="method-detail ">
|
503
|
+
|
504
|
+
<div class="method-heading">
|
505
|
+
<span class="method-name">write_to</span><span
|
506
|
+
class="method-args">(io)</span>
|
507
|
+
<span class="method-click-advice">click to toggle source</span>
|
508
|
+
</div>
|
509
|
+
|
510
|
+
|
511
|
+
<div class="method-description">
|
512
|
+
|
513
|
+
<p>Writes a <a href="../MIDI.html">MIDI</a> format 1 file.</p>
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
<div class="method-source-code" id="write_to-source">
|
518
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 18</span>
|
519
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_to</span>(<span class="ruby-identifier">io</span>)
|
520
|
+
<span class="ruby-ivar">@io</span> = <span class="ruby-identifier">io</span>
|
521
|
+
<span class="ruby-ivar">@bytes_written</span> = <span class="ruby-value">0</span>
|
522
|
+
<span class="ruby-identifier">write_header</span>()
|
523
|
+
<span class="ruby-ivar">@update_block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-ivar">@seq</span>.<span class="ruby-identifier">tracks</span>.<span class="ruby-identifier">length</span>, <span class="ruby-value">0</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@update_block</span>
|
524
|
+
<span class="ruby-ivar">@seq</span>.<span class="ruby-identifier">tracks</span>.<span class="ruby-identifier">each_with_index</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">track</span>, <span class="ruby-identifier">i</span> <span class="ruby-operator">|</span>
|
525
|
+
<span class="ruby-identifier">write_track</span>(<span class="ruby-identifier">track</span>)
|
526
|
+
<span class="ruby-ivar">@update_block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">track</span>, <span class="ruby-ivar">@seq</span>.<span class="ruby-identifier">tracks</span>.<span class="ruby-identifier">length</span>, <span class="ruby-identifier">i</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@update_block</span>
|
527
|
+
}
|
528
|
+
<span class="ruby-keyword">end</span></pre>
|
529
|
+
</div><!-- write_to-source -->
|
530
|
+
|
531
|
+
</div>
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
</div><!-- write_to-method -->
|
537
|
+
|
538
|
+
|
539
|
+
<div id="method-i-write_track" class="method-detail ">
|
540
|
+
|
541
|
+
<div class="method-heading">
|
542
|
+
<span class="method-name">write_track</span><span
|
543
|
+
class="method-args">(track)</span>
|
544
|
+
<span class="method-click-advice">click to toggle source</span>
|
545
|
+
</div>
|
546
|
+
|
547
|
+
|
548
|
+
<div class="method-description">
|
549
|
+
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
<div class="method-source-code" id="write_track-source">
|
555
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 37</span>
|
556
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_track</span>(<span class="ruby-identifier">track</span>)
|
557
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">'MTrk'</span>
|
558
|
+
<span class="ruby-identifier">track_size_file_pos</span> = <span class="ruby-ivar">@io</span>.<span class="ruby-identifier">tell</span>()
|
559
|
+
<span class="ruby-identifier">write32</span>(<span class="ruby-value">0</span>) <span class="ruby-comment"># Dummy byte count; overwritten later</span>
|
560
|
+
<span class="ruby-ivar">@bytes_written</span> = <span class="ruby-value">0</span> <span class="ruby-comment"># Reset after previous write</span>
|
561
|
+
|
562
|
+
<span class="ruby-identifier">write_instrument</span>(<span class="ruby-identifier">track</span>.<span class="ruby-identifier">instrument</span>)
|
563
|
+
|
564
|
+
<span class="ruby-identifier">prev_event</span> = <span class="ruby-keyword">nil</span>
|
565
|
+
<span class="ruby-identifier">prev_status</span> = <span class="ruby-value">0</span>
|
566
|
+
<span class="ruby-identifier">track</span>.<span class="ruby-identifier">events</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">event</span> <span class="ruby-operator">|</span>
|
567
|
+
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">event</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Realtime</span>)
|
568
|
+
<span class="ruby-identifier">write_var_len</span>(<span class="ruby-identifier">event</span>.<span class="ruby-identifier">delta_time</span>)
|
569
|
+
<span class="ruby-keyword">end</span>
|
570
|
+
|
571
|
+
<span class="ruby-identifier">data</span> = <span class="ruby-identifier">event</span>.<span class="ruby-identifier">data_as_bytes</span>()
|
572
|
+
<span class="ruby-identifier">status</span> = <span class="ruby-identifier">data</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># status byte plus channel number, if any</span>
|
573
|
+
|
574
|
+
<span class="ruby-comment"># running status byte</span>
|
575
|
+
<span class="ruby-identifier">status</span> = <span class="ruby-identifier">possibly_munge_due_to_running_status_byte</span>(<span class="ruby-identifier">data</span>,
|
576
|
+
<span class="ruby-identifier">prev_status</span>)
|
577
|
+
|
578
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">write_bytes</span>(<span class="ruby-identifier">data</span>)
|
579
|
+
|
580
|
+
<span class="ruby-identifier">prev_event</span> = <span class="ruby-identifier">event</span>
|
581
|
+
<span class="ruby-identifier">prev_status</span> = <span class="ruby-identifier">status</span>
|
582
|
+
}
|
583
|
+
|
584
|
+
<span class="ruby-comment"># Write track end event.</span>
|
585
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-constant">MetaEvent</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">META_TRACK_END</span>)
|
586
|
+
<span class="ruby-identifier">write_var_len</span>(<span class="ruby-value">0</span>)
|
587
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">write_bytes</span>(<span class="ruby-identifier">event</span>.<span class="ruby-identifier">data_as_bytes</span>())
|
588
|
+
|
589
|
+
<span class="ruby-comment"># Go back to beginning of track data and write number of bytes,</span>
|
590
|
+
<span class="ruby-comment"># then come back here to end of file.</span>
|
591
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-identifier">track_size_file_pos</span>)
|
592
|
+
<span class="ruby-identifier">write32</span>(<span class="ruby-ivar">@bytes_written</span>)
|
593
|
+
<span class="ruby-ivar">@io</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">0</span>, <span class="ruby-operator">::</span><span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-constant">SEEK_END</span>)
|
594
|
+
<span class="ruby-keyword">end</span></pre>
|
595
|
+
</div><!-- write_track-source -->
|
596
|
+
|
597
|
+
</div>
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
</div><!-- write_track-method -->
|
603
|
+
|
604
|
+
|
605
|
+
<div id="method-i-write_var_len" class="method-detail ">
|
606
|
+
|
607
|
+
<div class="method-heading">
|
608
|
+
<span class="method-name">write_var_len</span><span
|
609
|
+
class="method-args">(val)</span>
|
610
|
+
<span class="method-click-advice">click to toggle source</span>
|
611
|
+
</div>
|
612
|
+
|
613
|
+
|
614
|
+
<div class="method-description">
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
<div class="method-source-code" id="write_var_len-source">
|
621
|
+
<pre><span class="ruby-comment"># File lib/midilib/io/seqwriter.rb, line 122</span>
|
622
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_var_len</span>(<span class="ruby-identifier">val</span>)
|
623
|
+
<span class="ruby-identifier">buffer</span> = <span class="ruby-constant">Utils</span>.<span class="ruby-identifier">as_var_len</span>(<span class="ruby-identifier">val</span>)
|
624
|
+
<span class="ruby-ivar">@bytes_written</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">write_bytes</span>(<span class="ruby-identifier">buffer</span>)
|
625
|
+
<span class="ruby-keyword">end</span></pre>
|
626
|
+
</div><!-- write_var_len-source -->
|
627
|
+
|
628
|
+
</div>
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
</div><!-- write_var_len-method -->
|
634
|
+
|
635
|
+
|
636
|
+
</section><!-- public-instance-method-details -->
|
637
|
+
|
638
|
+
</section><!-- 5Buntitled-5D -->
|
639
|
+
|
640
|
+
</div><!-- documentation -->
|
641
|
+
|
642
|
+
|
643
|
+
<footer id="validator-badges">
|
644
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
645
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
|
646
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
647
|
+
</footer>
|
648
|
+
|