Class: Proc_Midi
- Inherits:
-
Object
- Object
- Proc_Midi
- Defined in:
- lib/midinous/proc_midi.rb
Overview
Copyright © 2019 James “Nornec” Ratliff
This file is part of Midinous
Midinous is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Midinous is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Midinous. If not, see <https://www.gnu.org/licenses/>.
Instance Attribute Summary collapse
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#in_chan ⇒ Object
Returns the value of attribute in_chan.
-
#in_id ⇒ Object
readonly
Returns the value of attribute in_id.
-
#in_list ⇒ Object
Returns the value of attribute in_list.
-
#midi_in ⇒ Object
readonly
Returns the value of attribute midi_in.
-
#out_id ⇒ Object
readonly
Returns the value of attribute out_id.
-
#out_list ⇒ Object
Returns the value of attribute out_list.
Instance Method Summary collapse
-
#initialize(oid, iid) ⇒ Proc_Midi
constructor
A new instance of Proc_Midi.
-
#note_rlse(channel, note) ⇒ Object
Release a note.
-
#note_send(channel, note, velocity) ⇒ Object
Sends a note to an instrument.
- #regenerate ⇒ Object
-
#sel_in(id) ⇒ Object
Select the input device.
-
#sel_out(id) ⇒ Object
Select the output device.
-
#set_listener ⇒ Object
Restart the listener.
Constructor Details
#initialize(oid, iid) ⇒ Proc_Midi
Returns a new instance of Proc_Midi.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/midinous/proc_midi.rb', line 22 def initialize(oid,iid) @out_list = [] @in_list = [] @in_chan = 1 @out_id = oid @out_list = UniMIDI::Output.all @out = UniMIDI::Output.use(@out_id) @in_id = iid @in_list = UniMIDI::Input.all unless @in_list.length <= 1 @in = UniMIDI::Input.use(@in_id) set_listener end end |
Instance Attribute Details
#in ⇒ Object (readonly)
Returns the value of attribute in.
20 21 22 |
# File 'lib/midinous/proc_midi.rb', line 20 def in @in end |
#in_chan ⇒ Object
Returns the value of attribute in_chan.
19 20 21 |
# File 'lib/midinous/proc_midi.rb', line 19 def in_chan @in_chan end |
#in_id ⇒ Object (readonly)
Returns the value of attribute in_id.
20 21 22 |
# File 'lib/midinous/proc_midi.rb', line 20 def in_id @in_id end |
#in_list ⇒ Object
Returns the value of attribute in_list.
19 20 21 |
# File 'lib/midinous/proc_midi.rb', line 19 def in_list @in_list end |
#midi_in ⇒ Object (readonly)
Returns the value of attribute midi_in.
20 21 22 |
# File 'lib/midinous/proc_midi.rb', line 20 def midi_in @midi_in end |
#out_id ⇒ Object (readonly)
Returns the value of attribute out_id.
20 21 22 |
# File 'lib/midinous/proc_midi.rb', line 20 def out_id @out_id end |
#out_list ⇒ Object
Returns the value of attribute out_list.
19 20 21 |
# File 'lib/midinous/proc_midi.rb', line 19 def out_list @out_list end |
Instance Method Details
#note_rlse(channel, note) ⇒ Object
Release a note. Does not require a duration. Is called when a release signal is received.
96 97 98 |
# File 'lib/midinous/proc_midi.rb', line 96 def note_rlse(channel,note) @out.puts(0x80+channel-1,note,0x00) end |
#note_send(channel, note, velocity) ⇒ Object
Sends a note to an instrument
91 92 93 |
# File 'lib/midinous/proc_midi.rb', line 91 def note_send(channel,note,velocity) @out.puts(0x90+channel-1,note,velocity) end |
#regenerate ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/midinous/proc_midi.rb', line 38 def regenerate @midi_in.close unless @midi_in.nil? @in_list.each do |i| #i.clear_buffer i.close end @out_list.each {|o| o.close} UniMIDI::Input.all.each {|i| i = nil} UniMIDI::Output.all.each {|o| o = nil} @in = nil @out = nil @in_list = [] @out_list = [] UniMIDI::Loader.clear_devices @in_list = UniMIDI::Input.all @out_list = UniMIDI::Output.all UI.set_device(0,"i") UI.set_device(0,"o") set_listener unless @in_list.length <= 1 end |
#sel_in(id) ⇒ Object
Select the input device
82 83 84 85 86 87 88 |
# File 'lib/midinous/proc_midi.rb', line 82 def sel_in(id) @in = UniMIDI::Input.all[@in_id].close @in = UniMIDI::Input.use(id) @in_id = id @midi_in.close unless @midi_in.nil? set_listener end |
#sel_out(id) ⇒ Object
Select the output device
75 76 77 78 79 |
# File 'lib/midinous/proc_midi.rb', line 75 def sel_out(id) @out = UniMIDI::Output.all[@out_id].close @out = UniMIDI::Output.use(id) @out_id = id end |
#set_listener ⇒ Object
Restart the listener
66 67 68 69 70 71 72 |
# File 'lib/midinous/proc_midi.rb', line 66 def set_listener @midi_in = GuiListener.new(@in) @midi_in.listen_for(:class => [MIDIMessage::NoteOn]) do |e| Pl.set_note_via_devc(e[:message].note.clamp(0,127)) if e[:message].velocity <= 127 end @midi_in.gui_listen end |