smf 0.15.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/MANUAL +172 -0
  2. data/MANUAL.en +135 -0
  3. data/MANUAL.en.html +150 -0
  4. data/MANUAL.en.rd +144 -0
  5. data/MANUAL.html +201 -0
  6. data/MANUAL.rd +179 -0
  7. data/README +33 -0
  8. data/README.en +33 -0
  9. data/lib/smf.rb +736 -0
  10. data/lib/smf/divert.rb +21 -0
  11. data/lib/smf/io.rb +1278 -0
  12. data/lib/smf/toy/beatmap.rb +73 -0
  13. data/lib/smf/toy/gm.rb +327 -0
  14. data/lib/smf/toy/groove.rb +34 -0
  15. data/lib/smf/toy/macro.rb +282 -0
  16. data/lib/smf/toy/macro/mml.rb +34 -0
  17. data/lib/smf/toy/macro/mml/parser.rb +545 -0
  18. data/lib/smf/toy/macro/mml/parser.ry +239 -0
  19. data/lib/smf/toy/macro/stt.rb +33 -0
  20. data/lib/smf/toy/morse.rb +126 -0
  21. data/lib/smf/toy/quantize.rb +32 -0
  22. data/lib/smf/toy/rmi.rb +29 -0
  23. data/lib/smf/toy/searchsegment.rb +24 -0
  24. data/lib/smf/toy/shuffle.rb +39 -0
  25. data/lib/smf/toy/tempomap.rb +75 -0
  26. data/lib/smf/toy/text.rb +369 -0
  27. data/lib/smf/toy/velcomp.rb +42 -0
  28. data/lib/smf/toy/virtual.rb +118 -0
  29. data/lib/smf/toy/xml.rb +377 -0
  30. data/sample/Makefile +58 -0
  31. data/sample/bwv772.mid +0 -0
  32. data/sample/bwv772.mml +94 -0
  33. data/sample/bwv775.mid +0 -0
  34. data/sample/bwv775.mml +157 -0
  35. data/sample/bwv787.mid +0 -0
  36. data/sample/bwv787.mml +129 -0
  37. data/sample/groove.grv +33 -0
  38. data/sample/groove.rb +45 -0
  39. data/sample/ltvddpd2.mid +0 -0
  40. data/sample/ltvddpd2.stt +60 -0
  41. data/sample/merge.rb +38 -0
  42. data/sample/mml-samp.rb +19 -0
  43. data/sample/mml.rb +36 -0
  44. data/sample/morse-samp.rb +11 -0
  45. data/sample/morse.rb +31 -0
  46. data/sample/play-oss.rb +215 -0
  47. data/sample/play-oss2.rb +253 -0
  48. data/sample/play-oss3.rb +150 -0
  49. data/sample/play-spkr.rb +97 -0
  50. data/sample/play-win.rb +195 -0
  51. data/sample/quantize.rb +41 -0
  52. data/sample/rand1.rb +21 -0
  53. data/sample/rand2.rb +24 -0
  54. data/sample/rmi2smf.rb +26 -0
  55. data/sample/shuffle.rb +43 -0
  56. data/sample/smf2rmi.rb +26 -0
  57. data/sample/smf2smf.rb +26 -0
  58. data/sample/smf2text.rb +27 -0
  59. data/sample/smf2wav.rb +123 -0
  60. data/sample/smf2xml.rb +27 -0
  61. data/sample/split.rb +40 -0
  62. data/sample/stt-samp.rb +19 -0
  63. data/sample/stt.rb +36 -0
  64. data/sample/text2smf.rb +28 -0
  65. data/sample/velcomp.rb +45 -0
  66. data/sample/virtual-samp.rb +19 -0
  67. data/sample/xml2smf.rb +28 -0
  68. metadata +128 -0
@@ -0,0 +1,34 @@
1
+ # mml.rb: Written by Tadayoshi Funaba 2005
2
+ # $Id: mml.rb,v 1.1 2005-07-17 17:08:20+09 tadf Exp $
3
+
4
+ require 'smf/toy/macro/mml/parser'
5
+
6
+ module SMF
7
+
8
+ class MML
9
+
10
+ def initialize(sq)
11
+ @sq = sq << Track.new
12
+ @list = []
13
+ end
14
+
15
+ def << (s) @list << s << "\n" end
16
+
17
+ def generate
18
+ so = @list.join
19
+ sh = Sheet.new(@sq)
20
+ de = Descripter.new(sh)
21
+ pa = MMLParser.new
22
+ ev = MMLEvaluator.new(de)
23
+ begin
24
+ st = pa.parse(so)
25
+ ev.evaluate(st)
26
+ sh.generate
27
+ rescue ParseError
28
+ raise ParseError, format('%d: syntax error', pa.lineno)
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,545 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by racc 1.4.5
4
+ # from racc grammer file "parser.ry".
5
+ #
6
+
7
+ require 'racc/parser'
8
+
9
+
10
+
11
+ require 'smf'
12
+ require 'smf/toy/macro'
13
+ require 'rational'
14
+
15
+ class SemanticError < StandardError; end
16
+
17
+
18
+ module SMF
19
+
20
+ class MMLParser < Racc::Parser
21
+
22
+ module_eval <<'..end parser.ry modeval..id74aaf71953', 'parser.ry', 66
23
+
24
+ STEPTAB = { 'w'=>1.to_r/1, 'h'=>1.to_r/2,
25
+ 'q'=>1.to_r/4, 'i'=>1.to_r/8,
26
+ 's'=>1.to_r/16,'z'=>1.to_r/32,
27
+ 'u'=>1.to_r/1920 }
28
+
29
+ NOTETAB = { 'a'=>9, 'b'=>11, 'c'=>0, 'd'=>2, 'e'=>4, 'f'=>5, 'g'=>7 }
30
+
31
+ def lineno() @co end
32
+
33
+ def parse(str)
34
+ @co = 1
35
+ @str = str
36
+ do_parse
37
+ end
38
+
39
+ def next_token
40
+ loop do
41
+ @str = @str.sub(/\A([\s\v]+)/, '')
42
+ if $1
43
+ @co += $1.count("\n")
44
+ end
45
+ @str = @str.sub(%r|\A(//.*)$|, '')
46
+ break unless $1
47
+ end
48
+ return [false, false] if @str.size == 0
49
+
50
+ if /\A([whqiszu])\b(\.+)?/i =~ @str
51
+ @str = $'
52
+ n = STEPTAB[$1.downcase]
53
+ i = if $2 then $2.size else 0 end
54
+ p = 1
55
+ i.times do |j|
56
+ p += Rational(1, 2 ** (j + 1))
57
+ end
58
+ s = n * p
59
+ return [:STEP, s]
60
+ end
61
+
62
+ if /\Ar\b/i =~ @str
63
+ @str = $'
64
+ return [:NOTE, nil]
65
+ end
66
+
67
+ if /\A([abcdefg])\b([$%#]+)?([,']+)?/i =~ @str
68
+ @str = $'
69
+ na = NOTETAB[$1.downcase]
70
+ if $2
71
+ s1 = 0
72
+ s1 -= $2.count('$')
73
+ s1 += $2.count('#')
74
+ end
75
+ if $3
76
+ s12 = 0
77
+ s12 -= $3.count(",") * 12
78
+ s12 += $3.count("'") * 12
79
+ end
80
+ return [:NOTE, [na, s1, s12]]
81
+ end
82
+
83
+ if /\A"/ =~ @str
84
+ @str = $'
85
+ s = '"'
86
+ until /\A"/ =~ @str
87
+ case @str
88
+ when /\A(\\.|.)/m; s << $1
89
+ end
90
+ @co += $1.count("\n")
91
+ @str = $'
92
+ end
93
+ s << '"'
94
+ @str = $'
95
+ return [:TEXT, eval(s)]
96
+ end
97
+
98
+ if /\A([a-z][a-z0-9]*)/i =~ @str
99
+ @str = $'
100
+ return [:VAR, $1]
101
+ end
102
+
103
+ if %r|\A([-+*/]?=)| =~ @str
104
+ @str = $'
105
+ return [:AOP, $1[0]]
106
+ end
107
+
108
+ if /\A(\d+)/ =~ @str
109
+ @str = $'
110
+ return [:NUM, Rational($1.to_i)]
111
+ end
112
+
113
+ if /\A(.)/ =~ @str
114
+ @str = $'
115
+ return [$1, $1]
116
+ end
117
+ end
118
+
119
+ ..end parser.ry modeval..id74aaf71953
120
+
121
+ ##### racc 1.4.5 generates ###
122
+
123
+ racc_reduce_table = [
124
+ 0, 0, :racc_error,
125
+ 1, 20, :_reduce_1,
126
+ 0, 21, :_reduce_2,
127
+ 2, 21, :_reduce_3,
128
+ 1, 22, :_reduce_4,
129
+ 2, 22, :_reduce_5,
130
+ 1, 23, :_reduce_6,
131
+ 1, 23, :_reduce_none,
132
+ 1, 23, :_reduce_none,
133
+ 1, 23, :_reduce_none,
134
+ 3, 23, :_reduce_10,
135
+ 1, 25, :_reduce_11,
136
+ 1, 26, :_reduce_12,
137
+ 3, 27, :_reduce_13,
138
+ 5, 27, :_reduce_14,
139
+ 3, 24, :_reduce_15,
140
+ 3, 24, :_reduce_16,
141
+ 3, 24, :_reduce_17,
142
+ 3, 24, :_reduce_18,
143
+ 3, 24, :_reduce_19,
144
+ 1, 24, :_reduce_20,
145
+ 3, 28, :_reduce_21,
146
+ 3, 28, :_reduce_22,
147
+ 3, 28, :_reduce_23,
148
+ 3, 28, :_reduce_24,
149
+ 2, 28, :_reduce_25,
150
+ 3, 28, :_reduce_26,
151
+ 1, 28, :_reduce_27 ]
152
+
153
+ racc_reduce_n = 28
154
+
155
+ racc_shift_n = 48
156
+
157
+ racc_action_table = [
158
+ 19, 20, 21, 22, 37, 39, 40, 41, 18, 26,
159
+ 26, 26, 10, 33, 13, 26, 26, 42, 25, 25,
160
+ 25, 28, 28, 28, 25, 25, 26, 28, 28, 17,
161
+ 26, 26, 26, 37, 39, 25, 26, 16, 28, 25,
162
+ 25, 25, 28, 28, 28, 25, 19, 20, 28, 37,
163
+ 39, 40, 41, 3, 14, 34, 15, 4, 6, nil,
164
+ 38, 10, 14, 13, 15, 4, 6, nil, 10, 10,
165
+ 13, 13, 37, 39, 40, 41, 19, 20, 21, 22,
166
+ 10, nil, 13, 19, 20, 37, 39 ]
167
+
168
+ racc_action_check = [
169
+ 23, 23, 23, 23, 35, 35, 35, 35, 7, 26,
170
+ 38, 41, 10, 23, 10, 37, 40, 35, 26, 38,
171
+ 41, 26, 38, 41, 37, 40, 17, 37, 40, 6,
172
+ 19, 20, 25, 46, 46, 17, 39, 3, 17, 19,
173
+ 20, 25, 19, 20, 25, 39, 32, 32, 39, 27,
174
+ 27, 27, 27, 1, 24, 24, 24, 24, 24, nil,
175
+ 27, 24, 2, 24, 2, 2, 2, nil, 21, 2,
176
+ 21, 2, 44, 44, 44, 44, 8, 8, 8, 8,
177
+ 22, nil, 22, 31, 31, 47, 47 ]
178
+
179
+ racc_action_pointer = [
180
+ nil, 53, 54, 37, nil, nil, 16, 1, 73, nil,
181
+ -3, nil, nil, nil, nil, nil, nil, 20, nil, 24,
182
+ 25, 53, 65, -3, 46, 26, 3, 46, nil, nil,
183
+ nil, 80, 43, nil, nil, 1, nil, 9, 4, 30,
184
+ 10, 5, nil, nil, 69, nil, 30, 82 ]
185
+
186
+ racc_action_default = [
187
+ -2, -28, -1, -28, -12, -3, -28, -4, -6, -7,
188
+ -28, -8, -9, -20, -2, -11, 48, -28, -5, -28,
189
+ -28, -28, -28, -28, -28, -28, -28, -13, -27, -17,
190
+ -18, -15, -16, -19, -10, -28, -25, -28, -28, -28,
191
+ -28, -28, -26, -23, -14, -24, -21, -22 ]
192
+
193
+ racc_goto_table = [
194
+ 27, 2, 29, 30, 1, 23, nil, nil, 35, 36,
195
+ nil, nil, nil, nil, nil, 24, 31, 32, nil, nil,
196
+ 43, 44, 45, 46, 47 ]
197
+
198
+ racc_goto_check = [
199
+ 9, 2, 9, 9, 1, 5, nil, nil, 9, 9,
200
+ nil, nil, nil, nil, nil, 2, 5, 5, nil, nil,
201
+ 9, 9, 9, 9, 9 ]
202
+
203
+ racc_goto_pointer = [
204
+ nil, 4, 1, nil, nil, -5, nil, nil, nil, -17 ]
205
+
206
+ racc_goto_default = [
207
+ nil, nil, nil, 5, 7, 8, 9, 11, 12, nil ]
208
+
209
+ racc_token_table = {
210
+ false => 0,
211
+ Object.new => 1,
212
+ :UMINUS => 2,
213
+ "*" => 3,
214
+ "/" => 4,
215
+ "+" => 5,
216
+ "-" => 6,
217
+ "&" => 7,
218
+ "{" => 8,
219
+ "}" => 9,
220
+ :NOTE => 10,
221
+ :TEXT => 11,
222
+ :VAR => 12,
223
+ :AOP => 13,
224
+ "," => 14,
225
+ "(" => 15,
226
+ ")" => 16,
227
+ :STEP => 17,
228
+ :NUM => 18 }
229
+
230
+ racc_use_result_var = true
231
+
232
+ racc_nt_base = 19
233
+
234
+ Racc_arg = [
235
+ racc_action_table,
236
+ racc_action_check,
237
+ racc_action_default,
238
+ racc_action_pointer,
239
+ racc_goto_table,
240
+ racc_goto_check,
241
+ racc_goto_default,
242
+ racc_goto_pointer,
243
+ racc_nt_base,
244
+ racc_reduce_table,
245
+ racc_token_table,
246
+ racc_shift_n,
247
+ racc_reduce_n,
248
+ racc_use_result_var ]
249
+
250
+ Racc_token_to_s_table = [
251
+ '$end',
252
+ 'error',
253
+ 'UMINUS',
254
+ '"*"',
255
+ '"/"',
256
+ '"+"',
257
+ '"-"',
258
+ '"&"',
259
+ '"{"',
260
+ '"}"',
261
+ 'NOTE',
262
+ 'TEXT',
263
+ 'VAR',
264
+ 'AOP',
265
+ '","',
266
+ '"("',
267
+ '")"',
268
+ 'STEP',
269
+ 'NUM',
270
+ '$start',
271
+ 'prog',
272
+ 'list',
273
+ 'stmt',
274
+ 'expr',
275
+ 'step',
276
+ 'note',
277
+ 'text',
278
+ 'asgn',
279
+ 'num']
280
+
281
+ Racc_debug_parser = false
282
+
283
+ ##### racc system variables end #####
284
+
285
+ # reduce 0 omitted
286
+
287
+ module_eval <<'.,.,', 'parser.ry', 13
288
+ def _reduce_1( val, _values, result )
289
+ result = val[0]
290
+ result
291
+ end
292
+ .,.,
293
+
294
+ module_eval <<'.,.,', 'parser.ry', 15
295
+ def _reduce_2( val, _values, result )
296
+ result = [:list, []]
297
+ result
298
+ end
299
+ .,.,
300
+
301
+ module_eval <<'.,.,', 'parser.ry', 16
302
+ def _reduce_3( val, _values, result )
303
+ val[0][1] << val[1]; result = val[0]
304
+ result
305
+ end
306
+ .,.,
307
+
308
+ module_eval <<'.,.,', 'parser.ry', 19
309
+ def _reduce_4( val, _values, result )
310
+ result = [:stmt, val[0]]
311
+ result
312
+ end
313
+ .,.,
314
+
315
+ module_eval <<'.,.,', 'parser.ry', 20
316
+ def _reduce_5( val, _values, result )
317
+ result = [:stmt, val[0], val[1]]
318
+ result
319
+ end
320
+ .,.,
321
+
322
+ module_eval <<'.,.,', 'parser.ry', 23
323
+ def _reduce_6( val, _values, result )
324
+ result = [:step, val[0]]
325
+ result
326
+ end
327
+ .,.,
328
+
329
+ # reduce 7 omitted
330
+
331
+ # reduce 8 omitted
332
+
333
+ # reduce 9 omitted
334
+
335
+ module_eval <<'.,.,', 'parser.ry', 25
336
+ def _reduce_10( val, _values, result )
337
+ result = val[1]
338
+ result
339
+ end
340
+ .,.,
341
+
342
+ module_eval <<'.,.,', 'parser.ry', 28
343
+ def _reduce_11( val, _values, result )
344
+ result = [:note, val[0]]
345
+ result
346
+ end
347
+ .,.,
348
+
349
+ module_eval <<'.,.,', 'parser.ry', 29
350
+ def _reduce_12( val, _values, result )
351
+ result = [:text, val[0]]
352
+ result
353
+ end
354
+ .,.,
355
+
356
+ module_eval <<'.,.,', 'parser.ry', 32
357
+ def _reduce_13( val, _values, result )
358
+ result = [:asgn, val[0], val[1], val[2]]
359
+ result
360
+ end
361
+ .,.,
362
+
363
+ module_eval <<'.,.,', 'parser.ry', 34
364
+ def _reduce_14( val, _values, result )
365
+ result = [:asgn, val[0], val[1], val[2], val[4]]
366
+ result
367
+ end
368
+ .,.,
369
+
370
+ module_eval <<'.,.,', 'parser.ry', 37
371
+ def _reduce_15( val, _values, result )
372
+ result = [:add, val[0], val[2]]
373
+ result
374
+ end
375
+ .,.,
376
+
377
+ module_eval <<'.,.,', 'parser.ry', 38
378
+ def _reduce_16( val, _values, result )
379
+ result = [:sub, val[0], val[2]]
380
+ result
381
+ end
382
+ .,.,
383
+
384
+ module_eval <<'.,.,', 'parser.ry', 39
385
+ def _reduce_17( val, _values, result )
386
+ result = [:mul, val[0], val[2]]
387
+ result
388
+ end
389
+ .,.,
390
+
391
+ module_eval <<'.,.,', 'parser.ry', 40
392
+ def _reduce_18( val, _values, result )
393
+ result = [:div, val[0], val[2]]
394
+ result
395
+ end
396
+ .,.,
397
+
398
+ module_eval <<'.,.,', 'parser.ry', 41
399
+ def _reduce_19( val, _values, result )
400
+ result = val[1]
401
+ result
402
+ end
403
+ .,.,
404
+
405
+ module_eval <<'.,.,', 'parser.ry', 42
406
+ def _reduce_20( val, _values, result )
407
+ result = [:imm, val[0]]
408
+ result
409
+ end
410
+ .,.,
411
+
412
+ module_eval <<'.,.,', 'parser.ry', 45
413
+ def _reduce_21( val, _values, result )
414
+ result = [:add, val[0], val[2]]
415
+ result
416
+ end
417
+ .,.,
418
+
419
+ module_eval <<'.,.,', 'parser.ry', 46
420
+ def _reduce_22( val, _values, result )
421
+ result = [:sub, val[0], val[2]]
422
+ result
423
+ end
424
+ .,.,
425
+
426
+ module_eval <<'.,.,', 'parser.ry', 47
427
+ def _reduce_23( val, _values, result )
428
+ result = [:mul, val[0], val[2]]
429
+ result
430
+ end
431
+ .,.,
432
+
433
+ module_eval <<'.,.,', 'parser.ry', 48
434
+ def _reduce_24( val, _values, result )
435
+ result = [:div, val[0], val[2]]
436
+ result
437
+ end
438
+ .,.,
439
+
440
+ module_eval <<'.,.,', 'parser.ry', 49
441
+ def _reduce_25( val, _values, result )
442
+ result = [:negate, val[1]]
443
+ result
444
+ end
445
+ .,.,
446
+
447
+ module_eval <<'.,.,', 'parser.ry', 50
448
+ def _reduce_26( val, _values, result )
449
+ result = val[1]
450
+ result
451
+ end
452
+ .,.,
453
+
454
+ module_eval <<'.,.,', 'parser.ry', 51
455
+ def _reduce_27( val, _values, result )
456
+ result = [:imm, val[0]]
457
+ result
458
+ end
459
+ .,.,
460
+
461
+ def _reduce_none( val, _values, result )
462
+ result
463
+ end
464
+
465
+ end # class MMLParser
466
+
467
+ end # module SMF
468
+
469
+
470
+ module SMF
471
+
472
+ class MMLEvaluator
473
+
474
+ def initialize(de) @de = de end
475
+
476
+ def evaluate(st)
477
+ case st[0]
478
+ when :list
479
+ @de.push
480
+ st[1].each do |st2|
481
+ evaluate(st2)
482
+ end
483
+ of = @de[:of]
484
+ @de.pop
485
+ @de[:of] = of
486
+ @de.snap
487
+ when :stmt
488
+ of = @de[:of]
489
+ evaluate(st[1])
490
+ if st[2]
491
+ @de[:of] = of
492
+ end
493
+ when :step
494
+ @de[:le] = evaluate(st[1])
495
+ when :add
496
+ return evaluate(st[1]) + evaluate(st[2])
497
+ when :sub
498
+ return evaluate(st[1]) - evaluate(st[2])
499
+ when :mul
500
+ return evaluate(st[1]) * evaluate(st[2])
501
+ when :div
502
+ return evaluate(st[1]) / evaluate(st[2])
503
+ when :negate
504
+ return - evaluate(st[1])
505
+ when :imm
506
+ return st[1]
507
+ when :note
508
+ @de[:_no] = st[1]
509
+ @de.snap
510
+ @de[:_no] = nil
511
+ @de[:of] += @de[:le]
512
+ when :text
513
+ @de[:_tx] = st[1]
514
+ @de.snap
515
+ @de[:_tx] = nil
516
+ when :asgn
517
+ va = st[1]
518
+ op = st[2]
519
+ ob = evaluate(st[3])
520
+ if st[4]
521
+ ob2 = evaluate(st[4])
522
+ ob = [ob, ob2]
523
+ end
524
+ va = va.intern
525
+ v = @de[va]
526
+ case op
527
+ when ?+; v += ob
528
+ when ?-; v -= ob
529
+ when ?*; v *= ob
530
+ when ?/; v /= ob
531
+ when ?=; v = ob
532
+ end
533
+ if va == :ke
534
+ @de[:_ke] = v
535
+ @de.snap
536
+ @de[:_ke] = nil
537
+ end
538
+ @de[va] = v
539
+ @de.snap
540
+ end
541
+ end
542
+
543
+ end
544
+
545
+ end