Class: Ruck::MIDI::MIDIOutput
- Inherits:
-
Object
- Object
- Ruck::MIDI::MIDIOutput
- Defined in:
- lib/ruck/midi/midi.rb
Instance Method Summary collapse
- #bpm ⇒ Object
- #control_change(controller, value, channel = 0, track = 0) ⇒ Object
-
#initialize(real_time, save_filename = nil, num_tracks = 1) ⇒ MIDIOutput
constructor
A new instance of MIDIOutput.
- #note_off(note, channel = 0, track = 0) ⇒ Object
- #note_on(note, velocity = 127, channel = 0, track = 0) ⇒ Object
- #ppqn ⇒ Object
- #program_change(program, channel = 0, track = 0) ⇒ Object
- #save ⇒ Object
- #tick(delta) ⇒ Object
Constructor Details
#initialize(real_time, save_filename = nil, num_tracks = 1) ⇒ MIDIOutput
Returns a new instance of MIDIOutput.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruck/midi/midi.rb', line 41 def initialize(real_time, save_filename = nil, num_tracks = 1) if save_filename @filename = save_filename @sequence = ::MIDI::Sequence.new @tracks = (1..num_tracks).map { ::MIDI::Track.new(@sequence) } @track_deltas = @tracks.map { 0 } @tracks.each do |track| @sequence.tracks << track #track.events << ::MIDI::Tempo.new(::MIDI::Tempo.bpm_to_mpq(120)) end end if real_time @player = MIDIator::Interface.new @player.use :dls_synth @player.instruct_user! end end |
Instance Method Details
#bpm ⇒ Object
65 66 67 |
# File 'lib/ruck/midi/midi.rb', line 65 def bpm @sequence.bpm end |
#control_change(controller, value, channel = 0, track = 0) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/ruck/midi/midi.rb', line 99 def control_change(controller, value, channel = 0, track = 0) if @sequence @tracks[track].events << ::MIDI::Controller.new(channel, controller, value) end if @player @player.driver.control_change(controller, channel, value) end end |
#note_off(note, channel = 0, track = 0) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ruck/midi/midi.rb', line 88 def note_off(note, channel = 0, track = 0) if @sequence @tracks[track].events << ::MIDI::NoteOffEvent.new(channel, note, 0, @track_deltas[track].to_i) @track_deltas[track] = 0 end if @player @player.driver.note_on(note, channel, 0) end end |
#note_on(note, velocity = 127, channel = 0, track = 0) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruck/midi/midi.rb', line 77 def note_on(note, velocity = 127, channel = 0, track = 0) if @sequence @tracks[track].events << ::MIDI::NoteOnEvent.new(channel, note, velocity, @track_deltas[track].to_i) @track_deltas[track] = 0 end if @player @player.driver.note_on(note, channel, velocity) end end |
#ppqn ⇒ Object
61 62 63 |
# File 'lib/ruck/midi/midi.rb', line 61 def ppqn @sequence.ppqn end |
#program_change(program, channel = 0, track = 0) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/ruck/midi/midi.rb', line 109 def program_change(program, channel = 0, track = 0) if @sequence @tracks[track].events << ::MIDI::ProgramChange.new(channel, program) end if @player @player.driver.program_change(channel, program) end end |
#save ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ruck/midi/midi.rb', line 119 def save return if @saved return unless @sequence @saved = true File.open(@filename, "wb") do |file| @sequence.write(file) end end |
#tick(delta) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/ruck/midi/midi.rb', line 69 def tick(delta) if @sequence @track_deltas.each_with_index do |track_delta, i| @track_deltas[i] = track_delta + delta end end end |