Class: AlsaRawMIDI::Output

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

Overview

Output device class

Instance Attribute Summary

Attributes included from Device

#enabled, #id, #name, #subname, #system_id, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Device

included, #initialize

Methods included from Device::ClassMethods

#all, #all_by_type, #first, #last

Class Method Details

.allArray<Output>

All outputs

Returns:



90
91
92
# File 'lib/alsa-rawmidi/output.rb', line 90

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

.firstOutput

The first available output

Returns:



78
79
80
# File 'lib/alsa-rawmidi/output.rb', line 78

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

.lastOutput

The last available output

Returns:



84
85
86
# File 'lib/alsa-rawmidi/output.rb', line 84

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

Instance Method Details

#closeBoolean

Close this output

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
# File 'lib/alsa-rawmidi/output.rb', line 10

def close
  if @enabled
    API::Device.close(@resource)
    @enabled = false
    true
  else
    false
  end
end

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

Enable this device; yields

Parameters:

  • options (Hash)
  • block (Proc)

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/alsa-rawmidi/output.rb', line 59

def enable(_options = {})
  unless @enabled
    @resource = API::Output.open(@system_id)
    @enabled = true
  end
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
  self
end

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

Output the given MIDI message

Parameters:

  • args (*Integer, *String)

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/alsa-rawmidi/output.rb', line 46

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 a MIDI message in numeric byte format

Parameters:

  • data (*Integer)

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/alsa-rawmidi/output.rb', line 38

def puts_bytes(*data)
  API::Output.puts(@resource, data)
  true
end

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

Output a MIDI message in hex string format

Parameters:

  • data (String)

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/alsa-rawmidi/output.rb', line 23

def puts_s(data)
  data = data.dup
  output = []
  until (str = data.slice!(0, 2)) == ''
    output << str.hex
  end
  puts_bytes(*output)
  true
end