Module: Webmidi::Message

Defined in:
lib/webmidi/message.rb,
lib/webmidi/message/ump.rb,
lib/webmidi/message/base.rb,
lib/webmidi/message/parser.rb,
lib/webmidi/message/system.rb,
lib/webmidi/message/channel.rb

Defined Under Namespace

Modules: Channel, Parser, System, UMP Classes: Base

Constant Summary collapse

DEFAULT_ARGUMENT =
Object.new.freeze

Class Method Summary collapse

Class Method Details

.active_sensing(timestamp: nil) ⇒ Object



103
104
105
# File 'lib/webmidi/message.rb', line 103

def self.active_sensing(timestamp: nil)
  System::ActiveSensing.new(timestamp: timestamp)
end

.channel_pressure(pressure, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/webmidi/message.rb', line 50

def self.channel_pressure(pressure, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::ChannelPressure.new(
    pressure: pressure,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.clock(timestamp: nil) ⇒ Object



87
88
89
# File 'lib/webmidi/message.rb', line 87

def self.clock(timestamp: nil)
  System::Clock.new(timestamp: timestamp)
end

.continue(timestamp: nil) ⇒ Object



95
96
97
# File 'lib/webmidi/message.rb', line 95

def self.continue(timestamp: nil)
  System::Continue.new(timestamp: timestamp)
end

.control_change(cc, value, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/webmidi/message.rb', line 33

def self.control_change(cc, value, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::ControlChange.new(
    cc: cc,
    value: value,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.downgrade(midi2_message) ⇒ Object



140
141
142
# File 'lib/webmidi/message.rb', line 140

def self.downgrade(midi2_message)
  UMP.downgrade(midi2_message)
end

.from_bytes(*bytes, normalize_note_on_zero: true) ⇒ Object



127
128
129
130
# File 'lib/webmidi/message.rb', line 127

def self.from_bytes(*bytes, normalize_note_on_zero: true)
  bytes = bytes.flatten
  Parser.parse_single(bytes, normalize_note_on_zero: normalize_note_on_zero)
end

.note_off(note, velocity: 0, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/webmidi/message.rb', line 24

def self.note_off(note, velocity: 0, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::NoteOff.new(
    note: coerce_note(note),
    velocity: velocity,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.note_on(note, velocity: DEFAULT_ARGUMENT, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object

Factory methods



15
16
17
18
19
20
21
22
# File 'lib/webmidi/message.rb', line 15

def self.note_on(note, velocity: DEFAULT_ARGUMENT, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::NoteOn.new(
    note: coerce_note(note),
    velocity: default_value(velocity, Webmidi.configuration.default_velocity),
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.parse_many(bytes, normalize_note_on_zero: true) ⇒ Object



132
133
134
# File 'lib/webmidi/message.rb', line 132

def self.parse_many(bytes, normalize_note_on_zero: true)
  Parser.parse_many(bytes, normalize_note_on_zero: normalize_note_on_zero)
end

.pitch_bend(value = Channel::PitchBend::CENTER, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/webmidi/message.rb', line 67

def self.pitch_bend(value = Channel::PitchBend::CENTER, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::PitchBend.new(
    value: value,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.pitch_bend_signed(value, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/webmidi/message.rb', line 75

def self.pitch_bend_signed(value, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::PitchBend.from_signed(
    value,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.polyphonic_pressure(note, pressure, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/webmidi/message.rb', line 58

def self.polyphonic_pressure(note, pressure, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::PolyphonicPressure.new(
    note: coerce_note(note),
    pressure: pressure,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.program_change(program, channel: DEFAULT_ARGUMENT, timestamp: nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/webmidi/message.rb', line 42

def self.program_change(program, channel: DEFAULT_ARGUMENT, timestamp: nil)
  Channel::ProgramChange.new(
    program: program,
    channel: default_value(channel, Webmidi.configuration.default_channel),
    timestamp: timestamp
  )
end

.song_position(position, timestamp: nil) ⇒ Object



115
116
117
# File 'lib/webmidi/message.rb', line 115

def self.song_position(position, timestamp: nil)
  System::SongPosition.new(position: position, timestamp: timestamp)
end

.song_select(song, timestamp: nil) ⇒ Object



119
120
121
# File 'lib/webmidi/message.rb', line 119

def self.song_select(song, timestamp: nil)
  System::SongSelect.new(song: song, timestamp: timestamp)
end

.start(timestamp: nil) ⇒ Object



91
92
93
# File 'lib/webmidi/message.rb', line 91

def self.start(timestamp: nil)
  System::Start.new(timestamp: timestamp)
end

.stop(timestamp: nil) ⇒ Object



99
100
101
# File 'lib/webmidi/message.rb', line 99

def self.stop(timestamp: nil)
  System::Stop.new(timestamp: timestamp)
end

.sysex(*data, timestamp: nil) ⇒ Object



83
84
85
# File 'lib/webmidi/message.rb', line 83

def self.sysex(*data, timestamp: nil)
  System::SysEx.new(data: data, timestamp: timestamp)
end

.system_reset(timestamp: nil) ⇒ Object



107
108
109
# File 'lib/webmidi/message.rb', line 107

def self.system_reset(timestamp: nil)
  System::SystemReset.new(timestamp: timestamp)
end

.time_code(type, value, timestamp: nil) ⇒ Object



111
112
113
# File 'lib/webmidi/message.rb', line 111

def self.time_code(type, value, timestamp: nil)
  System::TimeCode.new(type: type, value: value, timestamp: timestamp)
end

.tune_request(timestamp: nil) ⇒ Object



123
124
125
# File 'lib/webmidi/message.rb', line 123

def self.tune_request(timestamp: nil)
  System::TuneRequest.new(timestamp: timestamp)
end

.upgrade(midi1_message, group: DEFAULT_ARGUMENT) ⇒ Object



136
137
138
# File 'lib/webmidi/message.rb', line 136

def self.upgrade(midi1_message, group: DEFAULT_ARGUMENT)
  UMP.upgrade(midi1_message, group: default_value(group, Webmidi.configuration.default_group))
end