Class: Diamond::SequenceParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/diamond/sequence_parameters.rb

Overview

User-controller parameters that are used to formulate the note event sequence

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence, resolution, options = {}, &callback) ⇒ SequenceParameters

Returns a new instance of SequenceParameters.

Parameters:

  • sequence (Sequence)
  • resolution (Fixnum)
  • options (Hash) (defaults to: {})
  • callback (Proc)

Options Hash (options):

  • :gate (Fixnum)

    Duration of the arpeggiated notes. The value is a percentage based on the rate. If the rate is 4, then a gate of 100 is equal to a quarter note. (default: 75). must be 1..500

  • :interval (Fixnum)

    Increment (pattern) over (interval) scale degrees (range) times. May be positive or negative. (default: 12)

  • :pattern_offset (Fixnum)

    Begin on the nth note of the sequence (but not omit any notes). (default: 0)

  • :pattern (String, Pattern)

    Computes the contour of the arpeggiated melody. Can be the name of a pattern or a pattern object.

  • :range (Fixnum)

    Increment the (pattern) over (interval) scale degrees (range) times. Must be positive (abs will be used). (default: 3)

  • :rate (Fixnum)

    How fast the arpeggios will be played. Must be positive (abs will be used). (default: 8, eighth note.) must be 0..resolution


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

def initialize(sequence, resolution, options = {}, &callback)
  @transpose = 0
  @resolution = resolution
  @callback = callback
  apply_options(options)
  sequence.send(:use_parameters, self)
end

Instance Attribute Details

#gateObject

Returns the value of attribute gate


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def gate
  @gate
end

#intervalObject

Returns the value of attribute interval


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def interval
  @interval
end

#patternObject

Returns the value of attribute pattern


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def pattern
  @pattern
end

#pattern_offsetObject

Returns the value of attribute pattern_offset


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def pattern_offset
  @pattern_offset
end

#rangeObject

Returns the value of attribute range


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def range
  @range
end

#rateObject

Returns the value of attribute rate


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def rate
  @rate
end

#resolutionObject (readonly)

Returns the value of attribute resolution


6
7
8
# File 'lib/diamond/sequence_parameters.rb', line 6

def resolution
  @resolution
end

Instance Method Details

#computed_patternArray<Fixnum>

The computed pattern given the sequence options

Returns:

  • (Array<Fixnum>)

133
134
135
# File 'lib/diamond/sequence_parameters.rb', line 133

def computed_pattern
  @pattern.compute(@range, @interval)
end

#constraints(param) ⇒ Range

Dynamically produce an acceptable range for the given param

Parameters:

  • param (Symbol)

Returns:

  • (Range)

35
36
37
38
39
40
41
42
43
44
45
# File 'lib/diamond/sequence_parameters.rb', line 35

def constraints(param)
  ranges = {
    :gate => proc { get_lowest_gate..500 },
    :interval => proc { -48..48 },
    :pattern_offset => proc { -16..16 },
    :range => proc { 0..10 },
    :rate => proc { 0..@resolution },
    :transpose => proc { -72..72 }
  }
  ranges[param].call
end

#durationNumeric

The note duration given the sequence options

Returns:

  • (Numeric)

139
140
141
# File 'lib/diamond/sequence_parameters.rb', line 139

def duration
  @resolution / @rate
end

#transpose(num = nil) ⇒ Fixnum? Also known as: transpose=

Transpose everything by the given number of scale degrees. Can be used as a getter

Parameters:

  • num (Fixnum, nil) (defaults to: nil)

Returns:

  • (Fixnum, nil)

124
125
126
127
128
# File 'lib/diamond/sequence_parameters.rb', line 124

def transpose(num = nil)
  @transpose = num unless num.nil?
  mark_changed
  @transpose      
end