Support for custom scales?

Could there be a method for creating custom scales? In another thread I created a simple monkey patch for adding new scales and chords.

This feature could however be part of Sonic Pi’s core methods or added to existing scale method, for example something like this would be very useful:

ioanian1s = scale :C, [1,2,1,2,2,2,2]
3 Likes

It would be great to have the possibility to create scales that are not bound to the octave interval

my_scale = scale :C, [1,2,1,2,2,2,1,2,1,2,3,2,2,1]

In this scale there is no octave note in the middle. Don’t know whether people would come up with new music based on such scales, but to enable it is a first step.

1 Like

Huh, it been a while … but was thinking about this again and made a monkeypatch for it:

#scale_patch.rb
class SonicPi::Scale

  def initialize(tonic, name, num_octaves=1)
    if name.is_a?(Array)
      intervals = name
      name = :custom
    else
      name = name.to_sym
      intervals = SCALE[name]
    end
    raise InvalidScaleError, "Unknown scale name: #{name.inspect}" unless intervals
    intervals = intervals * num_octaves
    current = SonicPi::Note.resolve_midi_note(tonic)
    res = [current]
    intervals.each do |i|
      current += i
      res << current
    end

    @name = name
    @tonic = tonic
    @num_octaves = num_octaves
    @notes = res
    super(res)
  end

end

Example usage:

load scale_patch.rb
my_scale = scale :C, [1,2,1,2,2,2,1,2,1,2,3,2,2,1]
play_pattern_timed my_scale, 0.125

or something more fun like

24.times do
  my_scale = scale :E3, [1,2,3,4].pick(12)
  play_pattern_timed my_scale, 0.125
end