class MIDIJRuby::Output

Output device class

Public Class Methods

all() click to toggle source

All outputs @return [Array<Output>]

# File lib/midi-jruby/output.rb, line 80
def self.all
  Device.all_by_type[:output]
end
first() click to toggle source

Select the first output @return [Output]

# File lib/midi-jruby/output.rb, line 68
def self.first
  Device.first(:output) 
end
last() click to toggle source

Select the last output @return [Output]

# File lib/midi-jruby/output.rb, line 74
def self.last
  Device.last(:output)  
end

Public Instance Methods

close() click to toggle source

Close this output @return [Boolean]

# File lib/midi-jruby/output.rb, line 10
def close
  API.close_output(@device)
  @enabled = false
end
enable(options = {}) { |self| ... } click to toggle source

Enable this device; also takes a block @param [Hash] options @param [Proc] block @return [Output]

# File lib/midi-jruby/output.rb, line 48
def enable(options = {}, &block)
  unless @enabled
    API.enable_output(@device)
    @enabled = true
  end
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  else
    self
  end
end
Also aliased as: open, start
open(options = {}, &block)
Alias for: enable
puts(*args) click to toggle source

Output the given MIDI message @param [*Fixnum, *String] args @return [Boolean]

# File lib/midi-jruby/output.rb, line 35
def puts(*args)
  case args.first
    when Array then args.each { |arg| puts(*arg) }
    when Numeric then puts_bytes(*args)
    when String then puts_bytestr(*args)
  end
end
Also aliased as: write
puts_bytes(*data) click to toggle source

Output the given MIDI message @param [*Fixnum] data A MIDI messages expressed as Numeric bytes @return [Boolean]

# File lib/midi-jruby/output.rb, line 28
def puts_bytes(*data)
  API.write_output(@device, data)
end
puts_bytestr(data)
Alias for: puts_s
puts_hex(data)
Alias for: puts_s
puts_s(data) click to toggle source

Output the given MIDI message @param [String] data A MIDI message expressed as a string of hex digits @return [Boolean]

# File lib/midi-jruby/output.rb, line 18
def puts_s(data)
  bytes = hex_string_to_numeric_bytes(data)
  puts_bytes(*bytes)
end
Also aliased as: puts_bytestr, puts_hex
start(options = {}, &block)
Alias for: enable
write(*args)
Alias for: puts

Private Instance Methods

hex_string_to_numeric_bytes(string) click to toggle source

Convert a hex string to numeric bytes (eg “904040” -> [0x90, 0x40, 0x40]) @param [String] string @return [Array<Fixnum>]

# File lib/midi-jruby/output.rb, line 89
def hex_string_to_numeric_bytes(string)
  string = string.dup
  bytes = []
  until (string_byte = string.slice!(0,2)) == ""
    bytes << string_byte.hex
  end
  bytes
end