Class: Diamond::Clock

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

Overview

A wrapper for Topaz::Tempo that’s geared towards the arpeggiator

Instance Method Summary collapse

Constructor Details

#initialize(tempo_or_input, options = {}) ⇒ Clock

Returns a new instance of Clock.

Parameters:

  • tempo_or_input (Fixnum, UniMIDI::Input)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :output (Array<UniMIDI::Output>, UniMIDI::Output)

    MIDI output device(s) (also: :outputs)



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

def initialize(tempo_or_input, options = {})
  @arpeggiators = []
  output = options[:output] || options[:outputs] || options[:midi]
  initialize_clock(tempo_or_input, :output => output)
  initialize_events
end

Instance Method Details

#add(arpeggiator) ⇒ Array<Arpeggiator> Also known as: <<

Add arpeggiator(s) to this clock’s control

Parameters:

Returns:



50
51
52
53
54
# File 'lib/diamond/clock.rb', line 50

def add(arpeggiator)
  arpeggiators = [arpeggiator].flatten
  @arpeggiators += arpeggiators
  @arpeggiators
end

#midi_outputsArray<UniMIDI::Output>

Shortcut to the clock’s MIDI output devices

Returns:

  • (Array<UniMIDI::Output>)


22
23
24
# File 'lib/diamond/clock.rb', line 22

def midi_outputs
  @clock.midi_output.devices
end

#remove(arpeggiator) ⇒ Array<Arpeggiator>

Remove arpeggiator(s) from this clock’s control

Parameters:

Returns:



60
61
62
63
64
# File 'lib/diamond/clock.rb', line 60

def remove(arpeggiator)
  arpeggiators = [arpeggiator].flatten
  @arpeggiators.delete_if { |arpeggiator| arpeggiators.include?(arpeggiator) }
  @arpeggiators
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)


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

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)


41
42
43
44
45
# File 'lib/diamond/clock.rb', line 41

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