Class: JSound::Midi::Devices::Recorder

Inherits:
JSound::Midi::Device show all
Defined in:
lib/jsound/midi/devices/recorder.rb

Overview

A Device that records incoming messages, and the timestamp at which they were received.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from JSound::Midi::Device

#<=, #>>, #output, #to_s, #type

Methods included from TypeFromClassName

included

Constructor Details

#initialize(autostart = true) ⇒ Recorder

Returns a new instance of Recorder.



16
17
18
19
20
21
22
23
# File 'lib/jsound/midi/devices/recorder.rb', line 16

def initialize(autostart=true)
  clear
  if autostart
    start
  else
    stop
  end
end

Instance Attribute Details

#messages_with_timestampsObject (readonly)

The recorded [message,timestamp] pairs



9
10
11
# File 'lib/jsound/midi/devices/recorder.rb', line 9

def messages_with_timestamps
  @messages_with_timestamps
end

Instance Method Details

#clearObject

clear any recorded messages



26
27
28
# File 'lib/jsound/midi/devices/recorder.rb', line 26

def clear
  @messages_with_timestamps = []
end

#closeObject Also known as: stop

stop recording



37
38
39
# File 'lib/jsound/midi/devices/recorder.rb', line 37

def close
  @recording = false
end

#message(message) ⇒ Object



52
53
54
# File 'lib/jsound/midi/devices/recorder.rb', line 52

def message(message)
  @messages_with_timestamps << [message, Time.now.to_i] if recording?
end

#messagesObject

The recorded messages without timestamps



12
13
14
# File 'lib/jsound/midi/devices/recorder.rb', line 12

def messages
  @messages_with_timestamps.map{|m,t| m }
end

#openObject Also known as: start

start recording



31
32
33
# File 'lib/jsound/midi/devices/recorder.rb', line 31

def open
  @recording = true
end

#open?Boolean Also known as: recording?

true if this object is currently recording

Returns:

  • (Boolean)


43
44
45
# File 'lib/jsound/midi/devices/recorder.rb', line 43

def open?
  @recording
end

#output=(device) ⇒ Object



48
49
50
# File 'lib/jsound/midi/devices/recorder.rb', line 48

def output= device
  raise "#{self.class} cannot be assigned an output"
end