Class: Diamond::Clock

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

Overview

A wrapper for Sequencer::Clock (and thus Topaz::Tempo) that’s geared towards the arpeggiator

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Clock

Returns a new instance of Clock.

Parameters:

  • tempo_or_input (Fixnum, UniMIDI::Input)
  • options (Hash)


13
14
15
16
# File 'lib/diamond/clock.rb', line 13

def initialize(*args)
  @arpeggiators = []
  @clock = Sequencer::Clock.new(*args)
end

Instance Method Details

#add(arpeggiator) ⇒ Boolean Also known as: <<

Add an arpeggiator to this clock’s control

Parameters:

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/diamond/clock.rb', line 42

def add(arpeggiator)
  arpeggiators = [arpeggiator].flatten
  result = arpeggiators.map do |arpeggiator|
    unless @arpeggiators.include?(arpeggiator)
      @arpeggiators << arpeggiator
      reset_tick
      true
    else
      false
    end
  end
  result.any?
end

#remove(arpeggiator) ⇒ Boolean

Remove an arpeggiator from this clock’s control

Parameters:

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/diamond/clock.rb', line 60

def remove(arpeggiator)
  arpeggiators = [arpeggiator].flatten
  result = arpeggiators.map do |arpeggiator|
    if @arpeggiators.include?(arpeggiator)
      @arpeggiators.delete(arpeggiator)
      reset_tick
      true
    else
      false
    end
  end
  result.any?
end

#start(options = {}) ⇒ Boolean

Start the clock

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :blocking (Boolean)

    Whether to run in the foreground (also :focus, :foreground)

  • :suppress_clock (Boolean)

    Whether this clock is a sync-slave

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/diamond/clock.rb', line 23

def start(options = {})
  begin
    @clock.start(options)
  rescue SystemExit, Interrupt => exception
    stop
  end
end

#stopBoolean

Stop the clock (and fire the arpeggiator sequencer stop event)

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/diamond/clock.rb', line 33

def stop
  @arpeggiators.each { |arpeggiator| arpeggiator.sequencer.event.do_stop }
  @clock.stop
  true
end