Class: Musicality::PartSequencer
- Inherits:
-
Object
- Object
- Musicality::PartSequencer
- Defined in:
- lib/musicality/performance/midi/part_sequencer.rb
Instance Method Summary collapse
-
#initialize(part, dynamics_sample_rate: 50, cents_per_step: 10) ⇒ PartSequencer
constructor
A new instance of PartSequencer.
- #make_midi_track(midi_sequence, part_name, channel, ppqn, program) ⇒ Object
Constructor Details
#initialize(part, dynamics_sample_rate: 50, cents_per_step: 10) ⇒ PartSequencer
Returns a new instance of PartSequencer.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/musicality/performance/midi/part_sequencer.rb', line 4 def initialize part, dynamics_sample_rate: 50, cents_per_step: 10 notes = part.notes.map {|n| n.clone } replace_portamento_with_glissando(notes) extractor = NoteSequenceExtractor.new(notes) note_sequences = extractor.extract_sequences(cents_per_step) note_events = gather_note_events(note_sequences) dynamic_events = gather_dynamic_events(part.start_dynamic, part.dynamic_changes, dynamics_sample_rate) @events = (note_events + dynamic_events).sort end |
Instance Method Details
#make_midi_track(midi_sequence, part_name, channel, ppqn, program) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/musicality/performance/midi/part_sequencer.rb', line 18 def make_midi_track midi_sequence, part_name, channel, ppqn, program track = begin_track(midi_sequence, part_name, channel, program) prev_offset = 0 @events.each do |offset, event| if offset == prev_offset delta = 0 else delta = MidiUtil.delta(offset - prev_offset, ppqn) end track.events << case event when MidiEvent::NoteOn vel = MidiUtil.note_velocity(event.attack) MIDI::NoteOn.new(channel, event.notenum, vel, delta) when MidiEvent::NoteOff MIDI::NoteOff.new(channel, event.notenum, 127, delta) when MidiEvent::Expression MIDI::Controller.new(channel, MIDI::CC_EXPRESSION_CONTROLLER, event.volume, delta) end prev_offset = offset end return track end |