Class: MTK::IO::JSoundOutput

Inherits:
MIDIOutput show all
Defined in:
lib/mtk/io/jsound_output.rb

Overview

Note:

This class is optional and only available if you require ‘mtk/midi/jsound_output’. It depends on the ‘jsound’ and ‘gamelan’ gems.

Provides realtime MIDI output for JRuby via the jsound and gamelan gems.

Instance Attribute Summary

Attributes inherited from MIDIOutput

#device

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MIDIOutput

available_output_types, find_by_name, open, output_types_by_device, #play

Constructor Details

#initialize(device, options = {}) ⇒ JSoundOutput

Returns a new instance of JSoundOutput.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mtk/io/jsound_output.rb', line 22

def initialize(device, options={})
  @device = device

  # and create an object for generating MIDI message to send to the output:
  @generator = ::JSound::Midi::Devices::Generator.new

  if options[:monitor]
    @monitor = ::JSound::Midi::Devices::Monitor.new
    @generator >> [@monitor, @device]
  else
    @generator >> @device
  end
  @device.open
end

Class Method Details

.devicesObject



13
14
15
# File 'lib/mtk/io/jsound_output.rb', line 13

def self.devices
  @devices ||= ::JSound::Midi::OUTPUTS.devices
end

.devices_by_nameObject



17
18
19
# File 'lib/mtk/io/jsound_output.rb', line 17

def self.devices_by_name
  @devices_by_name ||= devices.each_with_object( Hash.new ){|device,hash| hash[device.description] = device }
end

Instance Method Details

#bend(midi_value, channel) ⇒ Object (protected)

Send a pitch bend event to the MIDI output.



70
71
72
# File 'lib/mtk/io/jsound_output.rb', line 70

def bend(midi_value, channel)
  @generator.pitch_bend(midi_value, channel)
end

#channel_pressure(midi_value, channel) ⇒ Object (protected)

Send a channel pressure event to the MIDI output.



60
61
62
# File 'lib/mtk/io/jsound_output.rb', line 60

def channel_pressure(midi_value, channel)
  @generator.channel_pressure(midi_value, channel)
end

#control(number, midi_value, channel) ⇒ Object (protected)

Send a control change event to the MIDI output



55
56
57
# File 'lib/mtk/io/jsound_output.rb', line 55

def control(number, midi_value, channel)
  @generator.control_change(number, midi_value, channel)
end

#nameObject



37
38
39
# File 'lib/mtk/io/jsound_output.rb', line 37

def name
  @device.description
end

#note_off(pitch, velocity, channel) ⇒ Object (protected)

Send a note off event to the MIDI output



50
51
52
# File 'lib/mtk/io/jsound_output.rb', line 50

def note_off(pitch, velocity, channel)
  @generator.note_off(pitch, velocity, channel)
end

#note_on(pitch, velocity, channel) ⇒ Object (protected)

Send a note on event to the MIDI output



45
46
47
# File 'lib/mtk/io/jsound_output.rb', line 45

def note_on(pitch, velocity, channel)
  @generator.note_on(pitch, velocity, channel)
end

#poly_pressure(pitch, midi_value, channel) ⇒ Object (protected)

Send a poly pressure event to the MIDI output.



65
66
67
# File 'lib/mtk/io/jsound_output.rb', line 65

def poly_pressure(pitch, midi_value, channel)
  @generator.poly_pressure(pitch, midi_value, channel)
end

#program(number, channel) ⇒ Object (protected)

Send a program change event to the MIDI output.



75
76
77
# File 'lib/mtk/io/jsound_output.rb', line 75

def program(number, channel)
  @generator.program_change(number, channel)
end