Class: UniMIDI::Output

Inherits:
Object
  • Object
show all
Extended by:
Device::ClassMethods
Includes:
Device::InstanceMethods
Defined in:
lib/unimidi/output.rb

Overview

A MIDI output device

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Device::ClassMethods

at, each, find_by_name, first, gets, last, list, use

Methods included from Device::InstanceMethods

#close, #closed?, included, #initialize, #open, #pretty_name

Class Method Details

.allArray<Output>

All MIDI output devices – used to populate the class

Returns:



11
12
13
# File 'lib/unimidi/output.rb', line 11

def self.all
  Loader.devices(direction: :output)
end

Instance Method Details

#puts(*messages) ⇒ Array<Integer>, Array<String>

Sends a message to the output.

The message format can be:

  1. Numeric bytes eg output.puts(0x90, 0x40, 0x40)

  2. An array of numeric bytes [0x90, 0x40, 0x40]

  3. A string of bytes eg “904040”

  4. An array of strings [“904040”, “804040”]

Parameters:

  • messages (*Array<Integer>, *Array<String>, *Integer, *String)

Returns:

  • (Array<Integer>, Array<String>)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/unimidi/output.rb', line 26

def puts(*messages)
  message = messages.first
  case message
  when Array then messages.each { |array| puts(*array.flatten) }
  when Integer then puts_bytes(*messages)
  when String then puts_s(*messages)
  else
    if message.respond_to?(:to_bytes)
      puts_bytes(*message.to_bytes.flatten)
    elsif message.respond_to?(:to_a)
      puts_bytes(*message.to_a.flatten)
    end
  end
end

#puts_bytes(*messages) ⇒ Array<Integer>+

Sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40). This method does not do type checking.

Parameters:

  • messages (*Array<Integer>)

Returns:

  • (Array<Integer>, Array<Array<Integer>>)


56
57
58
59
# File 'lib/unimidi/output.rb', line 56

def puts_bytes(*messages)
  @device.puts_bytes(*messages)
  messages.count < 2 ? messages[0] : messages
end

#puts_s(*messages) ⇒ Array<String>+ Also known as: puts_bytestr, puts_hex

Sends a message to the output in a form of a string eg “904040”. This method does not do type checking

Parameters:

  • messages (*String)

Returns:

  • (Array<String>, Array<Array<String>>)


45
46
47
48
# File 'lib/unimidi/output.rb', line 45

def puts_s(*messages)
  @device.puts_s(*messages)
  messages.count < 2 ? messages[0] : messages
end