Class: MIDI::MMC

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

Constant Summary collapse

DEVICE_ID_ALL =
0x7F
TYPES =
{
  command:        0x06,
  response:       0x07,
}
COMMANDS =
{
  stop:           0x01,
  play:           0x02,
  deferred_play:  0x03,
  fast_forward:   0x04,
  rewind:         0x05,
  record_strobe:  0x06,
  record_exit:    0x07,
  record_pause:   0x08,
  pause:          0x09,
  eject:          0x0A,
  chase:          0x0B,
  reset:          0x0D,
  write:          0x40,
  locate:         0x44,
  shuttle:        0x47,
}
WRITE_MODES =
{
  record_ready:   0x4F,
  sync_monitor:   0x52,
  input_monitor:  0x53,
  mute:           0x62,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: nil, device_id: nil, debug: nil) ⇒ MMC

Returns a new instance of MMC.



40
41
42
43
44
# File 'lib/midi-mmc.rb', line 40

def initialize(output: nil, device_id: nil, debug: nil)
  @output = output
  @device_id = device_id || DEVICE_ID_ALL
  @debug = debug
end

Instance Attribute Details

#device_idObject

Returns the value of attribute device_id.



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

def device_id
  @device_id
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/midi-mmc.rb', line 5

def output
  @output
end

Instance Method Details

#arm_tracks(tracks) ⇒ Object Also known as: record_ready



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/midi-mmc.rb', line 96

def arm_tracks(tracks)
  tracks = case tracks
  when nil
    []
  when Numeric
    [tracks]
  when Range
    tracks.to_a
  when Array
    tracks
  else
    raise
  end
  bytes = track_bitmap_bytes(tracks)
  track_bitmap = [bytes.length, *bytes]
  mode_id = WRITE_MODES[:record_ready] or raise
  send_command_message(:write, track_bitmap.length, mode_id, *track_bitmap)
end

#chaseObject



88
89
90
# File 'lib/midi-mmc.rb', line 88

def chase
  send_command_message(:chase)
end

#deferred_playObject



54
55
56
# File 'lib/midi-mmc.rb', line 54

def deferred_play
  send_command_message(:deferred_play)
end

#ejectObject



84
85
86
# File 'lib/midi-mmc.rb', line 84

def eject
  send_command_message(:eject)
end

#fast_forwardObject



58
59
60
# File 'lib/midi-mmc.rb', line 58

def fast_forward
  send_command_message(:fast_forward)
end

#locate(location) ⇒ Object Also known as: goto



116
117
118
# File 'lib/midi-mmc.rb', line 116

def locate(location)
  send_command_message(:locate, 0x06, 0x01, *location, wait: 1)
end

#locate_zeroObject Also known as: goto_zero



121
122
123
# File 'lib/midi-mmc.rb', line 121

def locate_zero
  locate([0, 0, 0, 0, 0])
end

#message_to_str(msg) ⇒ Object



130
131
132
# File 'lib/midi-mmc.rb', line 130

def message_to_str(msg)
  msg.map { |b| '%02X' % b }.join(' ')
end

#pauseObject



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

def pause
  send_command_message(:pause)
end

#playObject



50
51
52
# File 'lib/midi-mmc.rb', line 50

def play
  send_command_message(:play)
end

#record_exitObject Also known as: punch_out



71
72
73
# File 'lib/midi-mmc.rb', line 71

def record_exit
  send_command_message(:record_exit)
end

#record_pauseObject



76
77
78
# File 'lib/midi-mmc.rb', line 76

def record_pause
  send_command_message(:record_pause)
end

#record_strobeObject Also known as: punch_in



66
67
68
# File 'lib/midi-mmc.rb', line 66

def record_strobe
  send_command_message(:record_strobe)
end

#resetObject



92
93
94
# File 'lib/midi-mmc.rb', line 92

def reset
  send_command_message(:reset)
end

#rewindObject



62
63
64
# File 'lib/midi-mmc.rb', line 62

def rewind
  send_command_message(:rewind)
end

#shuffleObject



126
127
128
# File 'lib/midi-mmc.rb', line 126

def shuffle
  send_command_message(:shuffle)
end

#stopObject



46
47
48
# File 'lib/midi-mmc.rb', line 46

def stop
  send_command_message(:stop)
end