smml 0.1.1 → 0.1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smml/msm.rb +122 -43
  3. data/lib/smml/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17054e465ae5c0f404fa3670cd8baed2c8084ad0
4
- data.tar.gz: 5f256889f73d29076c707924367ba4ead7a51a07
3
+ metadata.gz: 2f74a9766abd50fb796e9df2a78d248b23005f6e
4
+ data.tar.gz: 0210dcb9aa9e45746f97c03b33d47da43d28065c
5
5
  SHA512:
6
- metadata.gz: b6aa7ea713b36761c92e9d931f7414f045a136b601015038f56ff86eda259211e34d83a2fd7a3523f72cfdb78f4b21c686e800acc143c2f08d122821bae8c051
7
- data.tar.gz: a7f56ee6a605dd5033dde9404342bed36f5a97ca4b68ba6a108610b1f463dfa3eaf538bbbe7ad6f43275fe91d65c1a88bc6c9109e5b574748b6991f29843b01e
6
+ metadata.gz: 2758b65b3eed4fc493e623d5e6ccbb0650b4a0ce408d767e29ff7dd47a5427c16cc7870a97bc63aee1eee6a1f8176b30418341eece1db314a7864d38325a2aae
7
+ data.tar.gz: 92efb48db8b72f629556a4bd6c633d45b8d3beb528150760ace8dad285a7426f76d9ca84a846e08bdfb642c2e3f382da3c40a10afcd63049c318703610740197
data/lib/smml/msm.rb CHANGED
@@ -5,12 +5,21 @@ require 'optparse'
5
5
 
6
6
  $debuglevel=0
7
7
 
8
- def hint
9
- cmd=File.basename($0)
8
+ def hintminimum
9
+ cmd="smml"
10
10
  puts "Smml v#{Smml::VERSION}"
11
11
  puts <<EOF
12
- usage: #{cmd} -d \"dddd dr3 dddd r4 drdrdrdr dddd dr3\" -o outfile.mid -t bpm
13
- #{cmd} -i infile.txt -o outfile.mid -t bpm
12
+ usage:
13
+ data to mid
14
+ #{cmd} -d \"cdef gabc cbag rfed c4\" -o outfile.mid
15
+ file to mid
16
+ #{cmd} -i infile.txt -o outfile.mid
17
+ show syntax
18
+ #{cmd} -s
19
+ EOF
20
+ end
21
+ def showsyntax
22
+ puts <<EOF
14
23
 
15
24
  syntax: ...( will be changed time after time)
16
25
  abcdefg =tone; capital letters are sharps. followed by number as length.
@@ -101,6 +110,10 @@ syntax: ...( will be changed time after time)
101
110
  and other commands are with parentheses.
102
111
  EOF
103
112
  end
113
+ def hint
114
+ hintminimum
115
+ showsyntax
116
+ end
104
117
 
105
118
  1.round(2) rescue (
106
119
  class Float
@@ -118,6 +131,13 @@ class Fixnum
118
131
  end
119
132
  end
120
133
  )
134
+ [].rotate rescue (
135
+ class Array
136
+ def rotate
137
+ self.size>0 ? self[1..-1]+self[0..0] : []
138
+ end
139
+ end
140
+ )
121
141
  def multilineTrim l,com
122
142
  r=[]
123
143
  on=false
@@ -145,9 +165,18 @@ class String
145
165
  def setcmark c
146
166
  @@cmark=c
147
167
  end
168
+ def setpagesep c
169
+ @@pagesep=c
170
+ end
171
+ def settracksep c
172
+ @@tracksep=c
173
+ end
148
174
  def cmark
149
175
  @@cmark
150
176
  end
177
+ def pagesep
178
+ @@pagesep
179
+ end
151
180
  def commentoff ofs="",com=@@cmark
152
181
  lines=self.split("\n")
153
182
  d=multilineTrim(lines,com)
@@ -157,7 +186,7 @@ class String
157
186
  def sharp2cmark
158
187
  self.gsub!("#"){@@cmark}
159
188
  end
160
- def tracksep pspl
189
+ def tracksep pspl=@@pagesep
161
190
  tracks={}
162
191
  pages=self.split(/#{pspl}+/)
163
192
  markc=0
@@ -167,7 +196,7 @@ class String
167
196
  tracks.values.each{|v| v << p }
168
197
  markc+=1
169
198
  else
170
- p.split('|||').each_with_index{|t,i|
199
+ p.split(@@tracksep).each_with_index{|t,i|
171
200
  if tracks[i]
172
201
  tracks[i] << t
173
202
  else
@@ -200,7 +229,7 @@ class Array
200
229
  end
201
230
  class Notes < Hash
202
231
  @@rythmChannel=9
203
- @@n={
232
+ @@notes={
204
233
  "c"=>0,
205
234
  "C"=>1,
206
235
  "d"=>2,
@@ -217,17 +246,17 @@ class Notes < Hash
217
246
  "s"=>[3,@@rythmChannel],
218
247
  "u"=>[6,@@rythmChannel]
219
248
  }
220
- @@invert=@@n.invert
249
+ @@invert=@@notes.invert
221
250
  @@octave=12
222
251
  def initialize
223
- @@n.each{|k,v|self[k]=v}
252
+ @@notes.each{|k,v|self[k]=v}
224
253
  end
225
- def self.get last,n=0
254
+ def self.get last,dist=0
226
255
  last=~/(\-*)(\+*)([[:alpha:]])/
227
256
  oct=$1.size*(-1)+$2.size
228
257
  last=$3
229
- lastnote=@@n[last]+oct*@@octave
230
- num=lastnote+n.to_i
258
+ lastnote=@@notes[last]+oct*@@octave
259
+ num=lastnote+dist.to_i
231
260
  octave= num / @@octave
232
261
  pre=if octave>0
233
262
  "+"*octave
@@ -243,6 +272,25 @@ class ScaleNotes < Array
243
272
  def setSampleRate c
244
273
  @samplerate=c
245
274
  end
275
+ def modeinit
276
+ return if defined?(@@mode)
277
+ s=[:ionian,:dorian,:phrygian,:lydian,:mixolydian,:aeorian,:locrian,:ionian]
278
+ @@mode={}
279
+ @@mode[:ionian]=[0,2,4,5,7,9,11]
280
+ 6.times{|i|
281
+ tmp=@@mode[s[i]].rotate
282
+ root=tmp[0]
283
+ tmp=tmp.map{|t|(t-root+12)%12}
284
+ @@mode[s[i+1]]=tmp
285
+ }
286
+ end
287
+ def keys
288
+ @@mode.keys
289
+ end
290
+ def setmode first,mode=:ionian
291
+ self<<first
292
+ @@mode[mode][1..-1].each{|i|self<<Notes.get(first,"+#{i}")}
293
+ end
246
294
  # todo: use sample rate
247
295
  def sample
248
296
  self[rand(self.size)]
@@ -255,6 +303,7 @@ class ScaleNotes < Array
255
303
  end
256
304
  end
257
305
  def reset
306
+ modeinit
258
307
  initialize
259
308
  end
260
309
  end
@@ -769,6 +818,9 @@ class MarkTrack
769
818
  @diff
770
819
  end
771
820
  end
821
+ def guitarTuning
822
+ %W[-e -a d g b +e]
823
+ end
772
824
  module MidiHex
773
825
  # 設定のため最初に呼ばなければならない
774
826
  def self.prepare bpm=120,tbase=480,vel=0x40,oct=:near,vfuzzy=2
@@ -797,8 +849,9 @@ module MidiHex
797
849
  @bendrange=2
798
850
  @bendCent=1
799
851
  @pancenter=64
800
- @scalenotes=ScaleNotes.new
801
- @prepareSet=[@tbase,@ch,@velocity,@velocityFuzzy,@basekey,@gateRate,@bendrange,@bendCent,@scalenotes]
852
+ @scalenotes=ScaleNotes.new.reset
853
+ @gtune=guitarTuning
854
+ @prepareSet=[@tbase,@ch,@velocity,@velocityFuzzy,@basekey,@gateRate,@bendrange,@bendCent,@scalenotes,@gtune]
802
855
  @chmax=15
803
856
  @bendrangemax=127
804
857
  file="midi-programChange-list.txt"
@@ -808,6 +861,13 @@ module MidiHex
808
861
  pfile=File.expand_path(pfile,base) if not File.exist?(pfile)
809
862
  self.loadProgramChange(file)
810
863
  self.loadPercussionMap(pfile)
864
+ self.dumpstatus if $DEBUG && $debuglevel>3
865
+ end
866
+ def self.dumpstatus
867
+ self.instance_variables.each{|i|
868
+ val=self.instance_variable_get(i)
869
+ p [i, val] if "#{val}".size<100
870
+ }
811
871
  end
812
872
  def self.setmidiname name
813
873
  @midiname=name
@@ -834,7 +894,7 @@ module MidiHex
834
894
  @data
835
895
  end
836
896
  def self.setdata d
837
- @data=d
897
+ @data=d.size>0 ? d : false
838
898
  end
839
899
  def self.accent a
840
900
  @accentPlus=a.to_i
@@ -863,7 +923,7 @@ module MidiHex
863
923
  @bendCent=8192/@bendrange/100.0 if on
864
924
  end
865
925
  def self.trackPrepare tc=0
866
- @tbase,@ch,@velocity,@velocityFuzzy,@basekey,@gateRate,@bendrange,@bendCent,@scalenotes=@prepareSet
926
+ @tbase,@ch,@velocity,@velocityFuzzy,@basekey,@gateRate,@bendrange,@bendCent,@scalenotes,@gtune=@prepareSet
867
927
  @strokespeed=0
868
928
  @preGate=[]
869
929
  @preVelocity=[]
@@ -1376,19 +1436,19 @@ module MidiHex
1376
1436
  end
1377
1437
  k
1378
1438
  end
1379
- def self.basekeySet d
1439
+ def self.basekeySet d,num=1
1380
1440
  case d
1381
1441
  when "-"
1382
- if @basekey<12
1442
+ if @basekey-12*num < 0
1383
1443
  STDERR.puts "octave too low."
1384
1444
  else
1385
- @basekey-=12
1445
+ @basekey-=12*num
1386
1446
  end
1387
1447
  when "+"
1388
- if @basekey>0x7f-12
1448
+ if @basekey+12*num > 0x7f
1389
1449
  STDERR.puts "octave too high."
1390
1450
  else
1391
- @basekey+=12
1451
+ @basekey+=12*num
1392
1452
  end
1393
1453
  else
1394
1454
  @basekey=d
@@ -1417,13 +1477,22 @@ module MidiHex
1417
1477
  @scalenotes.reset
1418
1478
  s=s.split(",")
1419
1479
  first=s.first
1420
- s.each{|i|
1421
- note=i
1422
- note=Notes.get(first,i) if i=~/^[-+]+[[:digit:]]+$/
1423
- @scalenotes<<note
1424
- }
1480
+ mode=s[1]
1481
+ if @scalenotes.keys.member?(:"#{mode}")
1482
+ @scalenotes.setmode(first,:"#{mode}")
1483
+ else
1484
+ s.each{|i|
1485
+ note=i
1486
+ note=Notes.get(first,i) if i=~/^[-+]+[[:digit:]]+$/
1487
+ @scalenotes<<note
1488
+ }
1489
+ end
1425
1490
  p @scalenotes if $DEBUG
1426
1491
  end
1492
+ def self.gtuning s
1493
+ @gtune=s.split(",")
1494
+ p @gtune
1495
+ end
1427
1496
  def self.preLength v
1428
1497
  @preLength=v.map{|i|
1429
1498
  case i
@@ -1608,7 +1677,7 @@ module MidiHex
1608
1677
  accent=false
1609
1678
  sharp=0
1610
1679
  @h<<[:controlChange,"10,#{@panoftrack}"] if @autopan
1611
- cmd=rundata.scan(/&\([^)]+\)|\([-+]*[[:digit:]]?\)|:[^\(,]+\([^\)\(]+\),|:[^,]+,|\([^:]*:[^)\(]*\)|_[^!_]+!|_[^_]__[^\?]+\?|v[[:digit:]]+|[<>][[:digit:]]*|\*?[[:digit:]]+\.[[:digit:]]+|\*?[[:digit:]]+|[-+[:alpha:]]|\^|`|'|./)
1680
+ cmd=rundata.scan(/&\([^)]+\)|\([-+]*[[:digit:]]?\)|:[^\(,]+\([^\)\(]+\),|:[^,]+,|\([^:]*:[^)\(]*\)|_[^!_]+!|_[^_]__[^\?]+\?|v[[:digit:]]+|[<>][[:digit:]]*|\*?[[:digit:]]+\.[[:digit:]]+|[-+][[:digit:]]*|\*?[[:digit:]]+|[[:alpha:]]|\^|`|'|./)
1612
1681
  cmd<<" " # dummy
1613
1682
  p "track hex; start making: ",cmd if $DEBUG
1614
1683
  cmd.each{|i|
@@ -1786,6 +1855,8 @@ module MidiHex
1786
1855
  @h<<[:soundOff,$1]
1787
1856
  when /^\(scale:(.*)\)/
1788
1857
  @h<<[:call,:scale,$1]
1858
+ when /^\(gtune:(.*)\)/
1859
+ @h<<[:call,:gtuning,$1]
1789
1860
  when /^\(chordcenter:(.*)\)/
1790
1861
  @h<<[:call,:chordCenter,$1]
1791
1862
  when /^\(stroke:(.*)\)/
@@ -1826,10 +1897,10 @@ module MidiHex
1826
1897
  end
1827
1898
  @bpm=@bpm*rate
1828
1899
  @h<<[:tempo,@bpm]
1829
- when "-"
1830
- @h<<[:call,:basekeySet,"-"]
1831
- when "+"
1832
- @h<<[:call,:basekeySet,"+"]
1900
+ when /([-+])([[:digit:]]+)?/
1901
+ plus=$1
1902
+ num=$2 ? $2.to_i : 1
1903
+ @h<<[:call,:basekeySet,plus,num]
1833
1904
  when /^\*?[0-9]+/
1834
1905
  # (i.to_i-1).times{@h<<@h[-1]}
1835
1906
  when "`"
@@ -2009,32 +2080,32 @@ def multiplet d,tbase
2009
2080
  else
2010
2081
  total=tbase*rate
2011
2082
  end
2012
- r=i.scan(/=|\(\?:[^\]]+\)|\(x:[^\]]+\)|\(chord:[^)]+\)|\(C:[^)]+\)|:[^\(,]+\([^\)]+\),|:[^,]+,|[[:digit:]\.]+|_[^!]+!|~|\([-+]*[[:digit:]]?\)|[-+^`'<>]|./)
2013
- wait=[]
2083
+ r=i.scan(/=|\(\?:[^\]]+\)|\(x:[^\]]+\)|\(chord:[^)]+\)|\(C:[^)]+\)|:[^\(,]+\([^\)]+\),|:[^,]+,|[[:digit:]\.]+|_[^!]+!|~|\([-+]*[[:digit:]]?\)|[-+]+[[:digit:]]*|[\^`'<>]|./)
2084
+ lengths=[]
2014
2085
  notes=[]
2015
2086
  mod=[]
2016
2087
  r.each{|i|
2017
2088
  case i
2018
2089
  # modifier
2019
- when /^[-+^`',<>]/,/^\([-+]*[[:digit:]]?\)/
2090
+ when /^[-+]+[[:digit:]]*/,/^[\^`',<>]/,/^\([-+]*[[:digit:]]?\)/
2020
2091
  mod<<i
2021
2092
  # note
2022
2093
  when /^\((\?|x|C|chord):[^\)]+\)|^\^?:[^,]+,|^=/
2023
- wait<<1
2094
+ lengths<<1
2024
2095
  notes<<"#{mod*""}#{i}"
2025
2096
  mod=[]
2026
2097
  # length
2027
2098
  when /^[[:digit:]]+/
2028
- wait[-1]*=i.to_f
2099
+ lengths[-1]*=i.to_f
2029
2100
  when " "
2030
2101
  else
2031
- wait<<1
2102
+ lengths<<1
2032
2103
  notes<<"#{mod*""}#{i}"
2033
2104
  mod=[]
2034
2105
  end
2035
2106
  }
2036
- sum=wait.inject{|s,i|s+i}
2037
- ls=wait.map{|i|(i*1.0/sum*total).round} # .map{|i|i.round(dep)}
2107
+ sum=lengths.inject{|s,i|s+i}
2108
+ ls=lengths.map{|i|(i*1.0/sum*total).round} # .map{|i|i.round(dep)}
2038
2109
  er=(total-ls.inject{|s,i|s+i}).to_i
2039
2110
  if er>0
2040
2111
  er.times{|i|
@@ -2052,6 +2123,8 @@ def multiplet d,tbase
2052
2123
  result<<notes[i]
2053
2124
  result<<"*#{ls[i]}"
2054
2125
  }
2126
+ # rest of mod
2127
+ result+=mod
2055
2128
  p "multiplet: ",total,ls.inject{|s,i|s+i} if $DEBUG && $debuglevel>1
2056
2129
  result*""
2057
2130
  end
@@ -2148,7 +2221,7 @@ def tie d,tbase
2148
2221
  res=[]
2149
2222
  # if no length word after '~' length is 1
2150
2223
  d.gsub!(/~([^*[:digit:]])?/){$1 ? "~1#{$1}" : $&} while d=~/~[^*[:digit:]]/
2151
- li=d.scan(/\$\{[^\}]+\}|\$[^ ;\$_*^`'+-]+|\([^)\(]*\)|:[^\(,]+\([^)]+\),|:[^,]+,|_[^!]+!|_[^_]__[^?]+\?|v[[:digit:]]+|[<>][[:digit:]]*|\*?[[:digit:].]+|\([VGABLN]:[^)]+\)|~|./)
2224
+ li=d.scan(/\$\{[^\}]+\}|\$[^ ;\$_*^`'+-]+|\([^)\(]*\)|:[^\(,]+\([^)]+\),|:[^,]+,|_[^!]+!|_[^_]__[^?]+\?|v[[:digit:]]+|[<>\-+][[:digit:]]*|\*?[[:digit:].]+|\([VGABLN]:[^)]+\)|~|./)
2152
2225
  li.each{|i|
2153
2226
  case i
2154
2227
  when /^(\*)?([[:digit:].]+)/
@@ -2334,7 +2407,10 @@ class Smml
2334
2407
  attr_accessor :tracknum, :tbase, :rundatas, :rawdatas, :mx
2335
2408
  attr_accessor :bpm, :velocity, :octave, :vfuzzy, :data, :infile, :outfile, :autopan
2336
2409
  def initialize tbase=480,pagesep='///',expfile=false,cmark=';;'
2410
+ @tracksep='|||'
2337
2411
  String.new.setcmark(cmark)
2412
+ String.new.setpagesep(pagesep)
2413
+ String.new.settracksep(@tracksep)
2338
2414
  @mx=MidiHex
2339
2415
  @rundatas=[]
2340
2416
  @rawdatas=[]
@@ -2351,6 +2427,9 @@ class Smml
2351
2427
  @vfuzzy=2
2352
2428
  @autopan=true
2353
2429
  end
2430
+ def self.syntax
2431
+ hintminimum
2432
+ end
2354
2433
  def pmap
2355
2434
  puts @mx.programList
2356
2435
  end
@@ -2368,9 +2447,9 @@ class Smml
2368
2447
  @mx.setfile(@infile)
2369
2448
  @mx.setmidiname(@outfile) if @outfile
2370
2449
  @mx.setdata(@data) if ! @mx.getdata
2371
- (hint;exit) if (! @mx.getdata || ! @mx.getmidiname ) && ! test
2450
+ (hintminimum;exit) if (! @mx.getdata || ! @mx.getmidiname ) && ! test
2372
2451
  settest if test
2373
- @tracks=@mx.getdata.tracksep(@pagesep)
2452
+ @tracks=@mx.getdata.tracksep
2374
2453
  showtracks if $DEBUG && $debuglevel>1
2375
2454
  fuzzy(fz)
2376
2455
  end
@@ -2411,7 +2490,7 @@ class Smml
2411
2490
  }
2412
2491
  p @macro if$DEBUG
2413
2492
  @rawdatas.flatten!
2414
- open(@expfile,"w"){|f|f.puts @rundatas*"|||"} if @expfile
2493
+ open(@expfile,"w"){|f|f.puts @rundatas*@tracksep} if @expfile
2415
2494
  @tracknum=@rawdatas.size+@rundatas.size
2416
2495
  @tracknum=@tracks.size
2417
2496
  end
data/lib/smml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Smml
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tabasano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-24 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler