Class | Bio::Sequence::NA::MidiTrack |
In: |
lib/bio/shell/plugin/midi.rb
|
Parent: | Object |
MidiProg | = | [ "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric grand Piano", "Honky Tonk Piano", "Eiectric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesra", "Glockenspiel", "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular bells", "Dulcimer", "Drawbar Organ", "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica", "Tango Accordion", "Nylon Accustic Guitar", "Steel Acoustic Guitar", "Jazz Electric Guitar", "Ciean Electric Guitar", "Muted Electric Guitar", "Overdrive Guitar", "Distorted Guitar", "Guitar Harmonics", "Acoustic Bass", "Electric Fingered Bass", "Electric Picked Bass", "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Syn Bass 1", "Syn Bass 2", "Violin", "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp", "Timpani", "String Ensemble 1", "String Ensemble 2 (Slow)", "Syn Strings 1", "Syn Strings 2", "Choir Aahs", "Voice Oohs", "Syn Choir", "Orchestral Hit", "Trumpet", "Trombone", "Tuba", "Muted Trumpet", "French Horn", "Brass Section", "Syn Brass 1", "Syn Brass 2", "Soprano Sax", "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet", "Piccolo", "Flute", "Recorder", "Pan Flute", "Bottle Blow", "Shakuhachi", "Whistle", "Ocarina", "Syn Square Wave", "Syn Sawtooth Wave", "Syn Calliope", "Syn Chiff", "Syn Charang", "Syn Voice", "Syn Fifths Sawtooth Wave", "Syn Brass & Lead", "New Age Syn Pad", "Warm Syn Pad", "Polysynth Syn Pad", "Choir Syn Pad", "Bowed Syn Pad", "Metal Syn Pad", "Halo Syn Pad", "Sweep Syn Pad", "SFX Rain", "SFX Soundtrack", "SFX Crystal", "SFX Atmosphere", "SFX Brightness", "SFX Goblins", "SFX Echoes", "SFX Sci-fi", "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag Pipe", "Fiddle", "Shanai", "Tinkle Bell", "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Syn Drum", "Reverse Cymbal", "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter", "Applause", "Gun Shot" |
Styles | = | { # "Ohno" => { # # http://home.hiroshima-u.ac.jp/cato/bunkakoryuron.html # }, "Ichinose" => { :tempo => 120, :scale => [0, 2, 4, 5, 7, 9, 11], :tones => [ {:prog => 9, :base => 60, :range => 2}, {:prog => 13, :base => 48, :range => 2}, {:prog => 41, :base => 48, :range => 2}, {:prog => 44, :base => 36, :range => 2}, ] |
# File lib/bio/shell/plugin/midi.rb, line 207 207: def initialize(channel = 0, program = nil, base = nil, range = nil, scale = nil) 208: @channel = channel & 0xff 209: @program = program || 0 210: @base = base || 60 211: @range = range || 2 212: @scale = scale || [0, 2, 4, 5, 7, 9, 11] 213: 214: @tunes = [] 215: @tune = 0 216: @code = [] 217: @time = 0 218: 219: @range.times do |i| 220: @scale.each do |c| 221: @tunes.push c + i * 12 222: end 223: end 224: 225: @ttype = { 226: 'aa' => 1, 'at' => 0, 'ac' => 3, 'ag' => -1, 227: 'ta' => 0, 'tt' => -1, 'tc' => 1, 'tg' => -2, 228: 'ca' => 2, 'ct' => 1, 'cc' => 2, 'cg' => 6, 229: 'ga' => -1, 'gt' => -3, 'gc' => 0, 'gg' => -2, 230: } 231: @dtype = [ 232: { 'aa' => 2, 'at' => 4, 'ac' => 4, 'ag' => 2, 233: 'ta' => 2, 'tt' => 4, 'tc' => 4, 'tg' => 2, 234: 'ca' => 2, 'ct' => 3, 'cc' => 1, 'cg' => 2, 235: 'ga' => 1, 'gt' => 2, 'gc' => 2, 'gg' => 3, 236: }, 237: { 'aa' => 3, 'at' => 3, 'ac' => 2, 'ag' => 3, 238: 'ta' => 3, 'tt' => 3, 'tc' => 2, 'tg' => 2, 239: 'ca' => 3, 'ct' => 2, 'cc' => 1, 'cg' => 1, 240: 'ga' => 1, 'gt' => 1, 'gc' => 1, 'gg' => 1, 241: }, 242: { 'aa' => 2, 'at' => 2, 'ac' => 2, 'ag' => 2, 243: 'ta' => 1, 'tt' => 1, 'tc' => 2, 'tg' => 2, 244: 'ca' => 2, 'ct' => 2, 'cc' => 2, 'cg' => 3, 245: 'ga' => 2, 'gt' => 2, 'gc' => 3, 'gg' => 1, 246: }, 247: { 'aa' => 1, 'at' => 1, 'ac' => 1, 'ag' => 1, 248: 'ta' => 1, 'tt' => 1, 'tc' => 1, 'tg' => 1, 249: 'ca' => 1, 'ct' => 1, 'cc' => 1, 'cg' => 3, 250: 'ga' => 1, 'gt' => 1, 'gc' => 1, 'gg' => 1, 251: }, 252: ] 253: 254: @code.concat [0x00, 0xc0 | (@channel & 0xff)] 255: @code.concat icode(@program & 0xff, 1) 256: end
# File lib/bio/shell/plugin/midi.rb, line 277 277: def c2s(code) 278: ans = "" 279: code.each do |c| 280: ans += c.chr 281: end 282: ans 283: end
# File lib/bio/shell/plugin/midi.rb, line 317 317: def encode 318: ans ="MTrk" 319: ans += c2s(icode(@code.length + 4, 4)) 320: ans += c2s(@code) 321: ans += c2s([0x00, 0xff, 0x2f, 0x00]) 322: ans 323: end
# File lib/bio/shell/plugin/midi.rb, line 325 325: def header(num, tempo = 120) 326: ans = "MThd" 327: ans += c2s(icode(6, 4)) 328: ans += c2s(icode(1, 2)) 329: ans += c2s(icode(num + 1, 2)) 330: ans += c2s(icode(480, 2)) 331: ans += "MTrk" 332: ans += c2s(icode(11, 4)) 333: ans += c2s([0x00, 0xff, 0x51, 0x03]) 334: ans += c2s(icode(60000000 / tempo, 3)) 335: ans += c2s([0x00, 0xff, 0x2f, 0x00]) 336: ans 337: end
# File lib/bio/shell/plugin/midi.rb, line 258 258: def icode(num, n) 259: code = [] 260: n.times do |i| 261: code.push num & 0xff 262: num >>= 8 263: end 264: code.reverse 265: end
# File lib/bio/shell/plugin/midi.rb, line 285 285: def push(s) 286: tt = @time % 4 287: t = @ttype[s[0, 2]] 288: d = @dtype[tt][s[2, 2]] 289: if !t.nil? && !d.nil? 290: @tune += t 291: @tune %= @tunes.length 292: if tt == 0 293: vel = 90 294: elsif tt == 1 && d > 1 295: vel = 100 296: elsif tt == 2 297: vel = 60 298: else 299: vel = 50 300: end 301: @code.concat rcode(1) 302: @code.concat [0x90 | @channel, @tunes[@tune] + @base, vel] 303: @code.concat rcode(240 * d) 304: @code.concat [0x80 | @channel, @tunes[@tune] + @base, 0] 305: @time += d 306: end 307: end
# File lib/bio/shell/plugin/midi.rb, line 309 309: def push_silent(d) 310: @code.concat rcode(1) 311: @code.concat [0x90 | @channel, 0, 0] 312: @code.concat rcode(240 * d) 313: @code.concat [0x80 | @channel, 0, 0] 314: @time += d; 315: end