# Scales and tunings without Scale or Tuning

I’ve always found the Scale and Tuning classes weird as hell and I just roll my own scale logic for every piece. Here’s how to do it.

Here’s a simple EDO:

``````var edo, degreeToFreq;

degreeToFreq = { |n|
reference * (2 ** (n / edo))
};
``````

Here, `reference` is the frequency in Hz of the note that you get when n is 0. Really this isn’t a “degree” but rather a pitch index analogous to MIDI note numbers.

Here’s a scale:

``````var scale, edo, degreeToFreq;

scale = [0, 2, 4, 5, 7, 9, 11];

degreeToFreq = { |n|
reference * (2 ** ((scale.wrapAt(n) / edo) + floor(n / scale.size)))
};
``````

If you want an equal tuning that’s not at the octave, replace 2 with whatever the period is. Dunno why anyone thinks Bohlen-Pierce sounds good, but it’s not my place to judge.

Not using equal temperaments? Here’s a scale with JI ratios:

``````var scale, degreeToFreq;

scale = [1, 9 / 8, 5 / 4, 4 / 3, 3 / 2, 13 / 8, 9 / 4];

degreeToFreq = { |n|
432 * scale.wrapAt(n) * (2 ** floor(n / scale.size))
};
``````

Chakras aligned, baby! Behold the power of binaural Ayurvedic quantum mindfulness!

If you use Scale or Tuning and you’re making great music, then you do you! If you use Scale or Tuning and you will ardently defend all their design decisions in the replies, then please leave me alone!

5 Likes

Nice!

…the library of scales and tunings is a cool convenience though, I write `"1 3 5 7".df(\c)` to get a C-major7 chord and `"1 3 5 7".df(\c,\mixolydian)` to get a C-dominant 7th. I know I could just write “1 3 5 6.5” but being a music-theory type it can be nice to just read the usual scales and modes. (my `.df` method uses Scale and Tuning under the hood)

…and Scale and Tuning are explicitly used by the default Event type. So new users bump into them…

It would be cool if these classes were not so wonky. (and/or had note-names and 1-indexed options so that trad music can look like trad music) - or if we built in some simple convenience methods for Array and Simple Number to help newbs out.

and as @prko suggests maybe `SinOsc.ar('c3'.cps, 0, 0.1)` ought to work? or even `SinOsc.ar('c3')` or `SinOsc.ar('c3'.tune(\just))`

1 Like

I use only a small fraction of SC’s class library, and I’m also trying to move away from SC in the long run, so I don’t have a lot of stake in SC’s specific design. However, I will nevertheless offer my opinions, because my opinions are extremely good, always right, and everyone wants to hear them.

Some standard features for pitch notation entry in a genre-agnostic computer music language aren’t a bad idea. However they should have a narrow scope, should be based on an established literature standard, and should never try to be extensible or generic — otherwise we get really confused APIs like Tuning/Scale. A function to convert `C#4` to frequency is OK in my book, but if someone asks for stretched octaves or Sagittal notation then they should do it themselves. There are systems that let you implement any quantitative pitch paradigm in a highly extensible and modular way, and they’re called general-purpose programming languages

I’m also not on board with a core scale library, because it raises the question of what the inclusion criteria are and who defines what scales are. For example, there’s a “pelog” scale in the class library that appears to be a cheesy 12edo imitation of pelog, and it’s incorrectly labeled as it appears to be only one of the three classical pelog pathet.

3 Likes

Great points.

One simple idea might be to support Scala scales and tuning (in which case we are not responsible for the library)

( and totally agree re: inclusion + defaulting to et12 irritates me esthetically. )

1 Like

interesting thoughts to include Scale scales… you have a link to them, possibly?

1 Like

for later reference, I found this document that explains the file format: Scala scale file (.scl) format

1 Like

Here’s a “parser” I just built:

https://sccode.org/1-5hj

I hope it is useful to someone

Just to understand the `Scale` class (finally, after about a decade of ignorance from my side):
An idea on how to turn these into proper `Scale` objects would be much appreciated.

1 Like

You can load the scala files using TuningLib as well, FYI

1 Like

thanks for the heads up, @madskjeldgaard, and thanks for the great introduction to Scales/Tuning, Celeste Hutchins!

(also, this thread seems to be related to what we’re discussing here: Scale documentation incomplete? - #10 by jordan)

@Yann_Ics just looping you into this thread in case you don’t see it