Class: MIDIMessage::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-message/context.rb

Overview

A DSL for instantiating message objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Context

Returns a new instance of Context.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)


11
12
13
14
# File 'lib/midi-message/context.rb', line 11

def initialize(options = {})
  @channel = options[:channel]
  @velocity = options[:velocity]
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



6
7
8
# File 'lib/midi-message/context.rb', line 6

def channel
  @channel
end

#velocityObject

Returns the value of attribute velocity.



6
7
8
# File 'lib/midi-message/context.rb', line 6

def velocity
  @velocity
end

Instance Method Details

#channel_aftertouch(value, options = {}) ⇒ Object Also known as: ChannelAftertouch, ChannelPressure, channel_pressure

A channel pressure message

Parameters:

  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)


109
110
111
112
113
# File 'lib/midi-message/context.rb', line 109

def channel_aftertouch(value, options = {})
  channel = options[:channel] || @channel
  raise "channel_aftertouch requires a channel" if channel.nil?
  ChannelAftertouch.new(channel, value, options)
end

#control_change(index, value, options = {}) ⇒ Object Also known as: ControlChange, Controller, controller

A control change message

Parameters:

  • index (Fixnum, String)
  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)


71
72
73
74
75
76
77
78
79
# File 'lib/midi-message/context.rb', line 71

def control_change(index, value, options = {})
  channel = options[:channel] || @channel
  raise "control_change requires channel" if channel.nil?
  if index.kind_of?(String)
    ControlChange[index].new(channel, value, options)
  else
    ControlChange.new(channel, index, value, options)
  end
end

#note_off(note, options = {}) ⇒ Object Also known as: NoteOff

A note off message

Parameters:

  • note (Fixnum, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)


21
22
23
24
25
26
27
28
29
30
# File 'lib/midi-message/context.rb', line 21

def note_off(note, options = {})
  channel = options[:channel] || @channel
  velocity = options[:velocity] || @velocity
  raise "note_off requires both channel and velocity" if channel.nil? || velocity.nil?
  if note.kind_of?(String)
    NoteOff[note].new(channel, velocity, options)
  else
    NoteOff.new(channel, note, velocity, options)
  end
end

#note_on(note, options = {}) ⇒ Object Also known as: NoteOn

A note on message

Parameters:

  • note (Fixnum, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)


38
39
40
41
42
43
44
45
46
47
# File 'lib/midi-message/context.rb', line 38

def note_on(note, options = {})
  channel = options[:channel] || @channel
  velocity = options[:velocity] || @velocity
  raise "note_on requires both channel and velocity" if channel.nil? || velocity.nil?
  if note.kind_of?(String)
    NoteOn[note].new(channel, velocity, options)
  else
    NoteOn.new(channel, note, velocity, options)
  end
end

#pitch_bend(low, high, options = {}) ⇒ Object Also known as: PitchBend

A poly pressure message

Parameters:

  • low (Fixnum)
  • high (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)


123
124
125
126
127
# File 'lib/midi-message/context.rb', line 123

def pitch_bend(low, high, options = {})
  channel = options[:channel] || @channel
  raise "channel_aftertouch requires a channel" if channel.nil?
  PitchBend.new(channel, low, high, options)
end

#polyphonic_aftertouch(note, value, options = {}) ⇒ Object Also known as: PolyphonicAftertouch, PolyAftertouch, PolyphonicPressure, PolyPressure, poly_aftertouch, poly_pressure

A poly pressure message

Parameters:

  • note (Fixnum, String)
  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)


89
90
91
92
93
94
95
96
97
# File 'lib/midi-message/context.rb', line 89

def polyphonic_aftertouch(note, value, options = {})
  channel = options[:channel] || @channel
  raise "channel_aftertouch requires a channel" if channel.nil?
  if note.kind_of?(String)
    PolyphonicAftertouch[note].new(channel, value, options)
  else
    PolyphonicAftertouch.new(channel, note, value, options)
  end
end

#program_change(program, options = {}) ⇒ Object Also known as: ProgramChange

A program change message

Parameters:

  • program (Fixnum, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)


54
55
56
57
58
59
60
61
62
# File 'lib/midi-message/context.rb', line 54

def program_change(program, options = {})
  channel = options[:channel] || @channel
  raise "program_change requires channel" if channel.nil?
  if program.kind_of?(String)
    ProgramChange[program].new(channel, options)
  else
    ProgramChange.new(channel, program, options)
  end
end