Class: Burn::Fuel::Rom::ChannelStream
- Inherits:
-
Object
- Object
- Burn::Fuel::Rom::ChannelStream
- Defined in:
- lib/burn/fuel/rom/channel_stream.rb
Constant Summary collapse
- TEMPO_BASE =
tempo 193 ~ 211 (18 levels, 202 is median) see: ja.wikipedia.org/wiki/%E6%BC%94%E5%A5%8F%E8%A8%98%E5%8F%B7
192
- PRESTO =
1 + TEMPO_BASE
- ALLEGRO =
2 + TEMPO_BASE
- MODERATO =
3 + TEMPO_BASE
- ANDANTE =
4 + TEMPO_BASE
- ADAGIO =
5 + TEMPO_BASE
- LARGO =
6 + TEMPO_BASE
- BASS =
instrument number 64~126 (62steps) note no sound for 64, 65~72 seems working right now
65
- PIANO =
66
- STRING =
67
- ARPEGGIO =
68
- STEP =
69
- BELL =
70
- ACOUSTIC =
71
- GUITAR =
72
- THEREMIN =
73
Instance Method Summary collapse
- #default(*args) ⇒ Object
- #generate ⇒ Object
-
#initialize(index, instrument, tempo) ⇒ ChannelStream
constructor
A new instance of ChannelStream.
- #load(&block) ⇒ Object
- #method_missing(method_symbol, *args, &block) ⇒ Object
Constructor Details
#initialize(index, instrument, tempo) ⇒ ChannelStream
Returns a new instance of ChannelStream.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/burn/fuel/rom/channel_stream.rb', line 26 def initialize(index, instrument, tempo) @index = index @duration_list = [:half, :quarter, :eighth, :sixteenth] @duration_numeric_list = {2=>:half, 4=>:quarter, 8=>:eighth, 16=>:sixteenth} @duration_symbol_list = [:dotted, :triplet] @articulation_list = [:tenuto, :staccato, :accent] @instrument_list = [:piano, :bass] @notes = Array.new @notes << ChannelStream.const_get(tempo.upcase) @notes << ChannelStream.const_get(instrument.upcase) @default_duration = :quarter @default_articulation = nil @default_pitch = :c0 @output_buffer = Array.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/burn/fuel/rom/channel_stream.rb', line 58 def method_missing(method_symbol, *args, &block) case method_symbol when :segno then @output_buffer << __translate @output_buffer << "@chn#{@index.to_s}_segno:" @notes = Array.new when :dal_segno then @output_buffer << __translate @output_buffer << " .byte $fe" # end of stream @output_buffer << " .word @chn#{@index.to_s}_segno" @notes = Array.new else note = Note.new(@default_duration, method_symbol, @default_articulation) args.each{ |option| if @duration_numeric_list.include?(option) then note.duration = @duration_numeric_list[option] elsif @duration_list.include?(option) then note.duration = option elsif @articulation_list.include?(option) then note.articulation = option elsif @duration_symbol_list.include?(option) then note.duration_symbol = option end } @notes.concat note.generate end end |
Instance Method Details
#default(*args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/burn/fuel/rom/channel_stream.rb', line 46 def default(*args) args.each{ |option| if @duration_numeric_list.include?(option) then @default_duration = @duration_numeric_list[option] elsif @duration_list.include?(option) then @default_duration = option elsif @articulation_list.include?(option) then @default_articulation = option end } end |
#generate ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/burn/fuel/rom/channel_stream.rb', line 90 def generate if @notes.count>0 then @output_buffer << __translate end @output_buffer.join("\n") # " .byte " + @notes.map{|p| "$%02x" % p}.join(",") # " .byte $c1,$43,$1d,$80,$1f,$80,$21,$82,$1d,$80,$1d,$80,$1f,$92" end |
#load(&block) ⇒ Object
86 87 88 |
# File 'lib/burn/fuel/rom/channel_stream.rb', line 86 def load(&block) self.instance_eval &block end |