Class: Wavify::Sequencer::NoteSequence
- Inherits:
-
Object
- Object
- Wavify::Sequencer::NoteSequence
- Includes:
- Enumerable, Enumerable[Event]
- Defined in:
- lib/wavify/sequencer/note_sequence.rb,
sig/sequencer.rbs
Overview
Note sequence parser for note/rest/MIDI token notation.
Defined Under Namespace
Classes: Event
Constant Summary collapse
- NOTE_OFFSETS =
Note-name to semitone offset lookup table.
{ "C" => 0, "C#" => 1, "DB" => 1, "D" => 2, "D#" => 3, "EB" => 3, "E" => 4, "F" => 5, "F#" => 6, "GB" => 6, "G" => 7, "G#" => 8, "AB" => 8, "A" => 9, "A#" => 10, "BB" => 10, "B" => 11 }.freeze
Instance Attribute Summary collapse
-
#default_octave ⇒ Integer
readonly
Returns the value of attribute default_octave.
-
#events ⇒ Array[Event]
readonly
Returns the value of attribute events.
-
#notation ⇒ String
readonly
Returns the value of attribute notation.
Instance Method Summary collapse
-
#[](index) ⇒ Event?
Returns an event at the given index.
-
#each {|event| ... } ⇒ Enumerator
Enumerates parsed events.
-
#initialize(notation, default_octave: 4) ⇒ NoteSequence
constructor
A new instance of NoteSequence.
-
#length ⇒ Integer
(also: #size)
Number of parsed events.
-
#midi_notes ⇒ Array<Integer, nil>
MIDI notes preserving rests as nil.
-
#note_events ⇒ Array<Event>
Events excluding rests.
Constructor Details
#initialize(notation, default_octave: 4) ⇒ NoteSequence
Returns a new instance of NoteSequence.
43 44 45 46 47 48 49 50 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 43 def initialize(notation, default_octave: 4) raise InvalidNoteError, "note sequence notation must be String" unless notation.is_a?(String) @notation = notation.dup.freeze @default_octave = validate_default_octave!(default_octave) @events = parse_events(@notation).each(&:freeze).freeze freeze end |
Instance Attribute Details
#default_octave ⇒ Integer (readonly)
Returns the value of attribute default_octave.
41 42 43 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 41 def default_octave @default_octave end |
#events ⇒ Array[Event] (readonly)
Returns the value of attribute events.
41 42 43 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 41 def events @events end |
#notation ⇒ String (readonly)
Returns the value of attribute notation.
41 42 43 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 41 def notation @notation end |
Instance Method Details
#[](index) ⇒ Event?
Returns an event at the given index.
67 68 69 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 67 def [](index) @events[index] end |
#each ⇒ NoteSequence #each ⇒ Enumerator[Event, NoteSequence]
Enumerates parsed events.
57 58 59 60 61 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 57 def each(&) return enum_for(:each) unless block_given? @events.each(&) end |
#length ⇒ Integer Also known as: size
Returns number of parsed events.
72 73 74 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 72 def length @events.length end |
#midi_notes ⇒ Array<Integer, nil>
Returns MIDI notes preserving rests as nil.
79 80 81 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 79 def midi_notes @events.map(&:midi_note) end |
#note_events ⇒ Array<Event>
Returns events excluding rests.
84 85 86 |
# File 'lib/wavify/sequencer/note_sequence.rb', line 84 def note_events @events.reject(&:rest?) end |