Class: InevitableCacophony::MidiGenerator
- Inherits:
-
Object
- Object
- InevitableCacophony::MidiGenerator
- Defined in:
- lib/inevitable_cacophony/midi_generator.rb,
lib/inevitable_cacophony/midi_generator/frequency_table.rb
Defined Under Namespace
Classes: FrequencyTable
Instance Attribute Summary collapse
-
#frequency_table ⇒ Object
readonly
Returns the value of attribute frequency_table.
Instance Method Summary collapse
-
#add_phrase(phrase) ⇒ Object
Add a phrase to the MIDI output we will generate.
-
#initialize(octave_structure, tonic) ⇒ MidiGenerator
constructor
Set up a MIDI generator for a specific octave structure and tonic We need to know the octave structure because it determines how we allocate MIDI note indices to frequencies.
-
#notes_track(sequence = build_sequence) ⇒ Midi::Track
Notes to be output to MIDI; mainly for testing.
-
#write(io) ⇒ Object
Write MIDI output to the given stream.
Constructor Details
#initialize(octave_structure, tonic) ⇒ MidiGenerator
Set up a MIDI generator for a specific octave structure and tonic We need to know the octave structure because it determines how we allocate MIDI note indices to frequencies.
16 17 18 |
# File 'lib/inevitable_cacophony/midi_generator.rb', line 16 def initialize(octave_structure, tonic) @frequency_table = FrequencyTable.new(octave_structure, tonic) end |
Instance Attribute Details
#frequency_table ⇒ Object (readonly)
Returns the value of attribute frequency_table.
20 21 22 |
# File 'lib/inevitable_cacophony/midi_generator.rb', line 20 def frequency_table @frequency_table end |
Instance Method Details
#add_phrase(phrase) ⇒ Object
Add a phrase to the MIDI output we will generate.
23 24 25 26 |
# File 'lib/inevitable_cacophony/midi_generator.rb', line 23 def add_phrase(phrase) @phrases ||= [] @phrases << phrase end |
#notes_track(sequence = build_sequence) ⇒ Midi::Track
Returns Notes to be output to MIDI; mainly for testing.
29 30 31 |
# File 'lib/inevitable_cacophony/midi_generator.rb', line 29 def notes_track(sequence=build_sequence) build_notes_track(sequence, @phrases) end |
#write(io) ⇒ Object
Write MIDI output to the given stream.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inevitable_cacophony/midi_generator.rb', line 34 def write(io) sequence = build_sequence sequence.tracks << notes_track(sequence) # Buffer output so this method can be called on stdout. buffer = StringIO.new sequence.write(buffer) io.write(buffer.string) end |