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.



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

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

Instance Attribute Details

#messages_with_timestampsObject (readonly)

The recorded [message,timestamp] pairs.

Timestamps are in floating point seconds.



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

def messages_with_timestamps
  @messages_with_timestamps
end

Instance Method Details

#clearObject

clear any recorded messages



28
29
30
# File 'lib/jsound/midi/devices/recorder.rb', line 28

def clear
  @messages_with_timestamps = []
end

#closeObject Also known as: stop

stop recording



39
40
41
# File 'lib/jsound/midi/devices/recorder.rb', line 39

def close
  @recording = false
end

#message(message) ⇒ Object



54
55
56
# File 'lib/jsound/midi/devices/recorder.rb', line 54

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

#messagesObject

The recorded messages without timestamps



14
15
16
# File 'lib/jsound/midi/devices/recorder.rb', line 14

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

#openObject Also known as: start

start recording



33
34
35
# File 'lib/jsound/midi/devices/recorder.rb', line 33

def open
  @recording = true
end

#open?Boolean Also known as: recording?

true if this object is currently recording

Returns:

  • (Boolean)


45
46
47
# File 'lib/jsound/midi/devices/recorder.rb', line 45

def open?
  @recording
end

#output=(device) ⇒ Object



50
51
52
# File 'lib/jsound/midi/devices/recorder.rb', line 50

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