Class: MIDIJRuby::Output

Inherits:
Object
  • Object
show all
Includes:
Device
Defined in:
lib/midi-jruby/output.rb

Overview

Output device class

Instance Attribute Summary

Attributes included from Device

#description, #enabled, #id, #name, #type, #vendor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Device

all_by_type, #initialize

Class Method Details

.allArray<Output>

All outputs

Returns:



80
81
82
# File 'lib/midi-jruby/output.rb', line 80

def self.all
  Device.all_by_type[:output]
end

.firstOutput

Select the first output

Returns:



68
69
70
# File 'lib/midi-jruby/output.rb', line 68

def self.first
  Device.first(:output)
end

.lastOutput

Select the last output

Returns:



74
75
76
# File 'lib/midi-jruby/output.rb', line 74

def self.last
  Device.last(:output)
end

Instance Method Details

#closeBoolean

Close this output

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/midi-jruby/output.rb', line 10

def close
  API.close_output(@device)
  @enabled = false
end

#enable(_options = {}) ⇒ Output Also known as: open, start

Enable this device; also takes a block

Parameters:

  • options (Hash)
  • block (Proc)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/midi-jruby/output.rb', line 48

def enable(_options = {})
  unless @enabled
    API.enable_output(@device)
    @enabled = true
  end
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  else
    self
  end
end

#puts(*args) ⇒ Boolean Also known as: write

Output the given MIDI message

Parameters:

  • args (*Fixnum, *String)

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# 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

#puts_bytes(*data) ⇒ Boolean

Output the given MIDI message

Parameters:

  • data (*Fixnum)

    A MIDI messages expressed as Numeric bytes

Returns:

  • (Boolean)


28
29
30
# File 'lib/midi-jruby/output.rb', line 28

def puts_bytes(*data)
  API.write_output(@device, data)
end

#puts_s(data) ⇒ Boolean Also known as: puts_bytestr, puts_hex

Output the given MIDI message

Parameters:

  • data (String)

    A MIDI message expressed as a string of hex digits

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/midi-jruby/output.rb', line 18

def puts_s(data)
  bytes = hex_string_to_numeric_bytes(data)
  puts_bytes(*bytes)
end