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
2 Likes

This should be added to the source code.

On that topic, I thought I would do it myself, but then I ran into a small dilemma, partly due to my limited experience with software but also simply because I’m not sure I have the right perspective for how sonic pi should be. What do you all think is the right way to go about this, if it should be done at all?