Class: Diamond::Sequence

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/diamond/sequence.rb

Overview

The note event sequence from where the arpeggiator output is derived

Instance Method Summary collapse

Constructor Details

#initializeSequence

Returns a new instance of Sequence



10
11
12
13
14
15
16
# File 'lib/diamond/sequence.rb', line 10

def initialize 
  @parameter = nil
  # realtime
  @changed = false
  @input_queue = []
  @queue = []
end

Instance Method Details

#add(*note_messages) ⇒ Boolean

Add inputted note_messages

Parameters:

  • note_messages (Array<MIDIMessage::NoteOn>, MIDIMessage::NoteOn, *MIDIMessage::NoteOn)

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/diamond/sequence.rb', line 39

def add(*note_messages)
  messages = [note_messages].flatten.compact
  @input_queue.concat(messages)
  mark_changed
  true
end

#at(pointer) ⇒ Array<MIDIMessage>

The bucket of messages for the given pointer

Parameters:

  • pointer (Fixnum)

Returns:

  • (Array<MIDIMessage>)


21
22
23
24
25
26
27
28
# File 'lib/diamond/sequence.rb', line 21

def at(pointer)
  if changed? && (pointer % @parameter.rate == 0)
    update
  end
  enqueue_next(pointer)
  messages = @queue.shift || []
  messages
end

#changed?Boolean

Has the sequence changed since the last update?

Returns:

  • (Boolean)


32
33
34
# File 'lib/diamond/sequence.rb', line 32

def changed?
  @changed
end

#mark_changedBoolean

Mark the sequence as changed

Returns:

  • (Boolean)


78
79
80
# File 'lib/diamond/sequence.rb', line 78

def mark_changed
  @changed = true
end

#pending_note_offsArray<MIDIMessage::NoteOff>

All NoteOff messages in the queue

Returns:

  • (Array<MIDIMessage::NoteOff>)


67
68
69
70
71
72
73
74
# File 'lib/diamond/sequence.rb', line 67

def pending_note_offs
  messages = @queue.map do |bucket|
    unless bucket.nil?
      bucket.select { |m| m.class == MIDIMessage::NoteOff }       
    end
  end
  messages.flatten.compact
end

#remove(*note_messages) ⇒ Boolean

Remove input note messages with the same note value

Parameters:

  • note_messages (Array<MIDIMessage::NoteOn, MIDIMessage::NoteOff>, MIDIMessage::NoteOff, MIDIMessage::NoteOn, *MIDIMessage::NoteOff, *MIDIMessage::NoteOn)

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/diamond/sequence.rb', line 49

def remove(*note_messages)
  messages = [note_messages].flatten
  deletion_queue = messages.map(&:note)
  @input_queue.delete_if { |message| deletion_queue.include?(message.note) }
  mark_changed
  true
end

#remove_allBoolean

Remove all input note messages

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/diamond/sequence.rb', line 59

def remove_all
  @input_queue.clear
  mark_changed
  true
end