Kyma Forum
  Kyma Support
  problem combining two scripts into one

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   problem combining two scripts into one
Phi Curtis
Member
posted 05 December 2008 17:16         Edit/Delete Message   Reply w/Quote

ModeCalculator.kym

 
Hi,

I have two bits of code that, when I combine them together into a single script, seem to interfere with each other.

I'm trying to define scale formulas in a script that I can then reference in pitch fields within my sound.

The scales are defined like so:
majorScale := #(0 2 4 5 7 9 11 12 14 16 17 19 21 23 24 26 28 29 31 33 35 36 38 40 41 43 45 47 48 50 52 53 55 57 59 60 62 64 65 67 69 71 72).
sound start: 0 s
major: majorScale

You can see that this defines the scale as a series of intervals above a tonic note. I would then use, in a pitch field, a formula like:

(((!ScaleDegree - 1) of: ?major) + 24) nn

Here's my question:

I would like to have the script also automatically generate the modes of the scale that I give. So that, in this example, the modes of the major scale could be created by the script, and then automatically be given names that could also be accessed as green variables in pitch fields. I basically just want to save myself the trouble of manually writing out the intervals of all the modes of the original scale I defined (I intend to create a large compendium of scales to have easy access to in my sounds).

I have code that generates the modes like so:

| majorScale mode numberOfMode subtractForNewStartingNote intervalOfEndingNote|
majorScale := #(0 2 4 5 7 9 11 12 14 16 17 19 21 23 24 26 28 29 31 33 35 36 38 40 41 43 45 47 48 50 52 53 55 57 59 60 62 64 65 67 69 71 72).
mode := majorScale. "start with original scale"
numberOfMode := 3. "generate the phrygian mode"
subtractForNewStartingNote := mode at: numberOfMode. "to adjust the pitch of the entire scale to start at 0 on the new starting note, subtract the interval of that note above the orig. scale"
intervalOfEndingNote := mode at: mode size.

1 to: (mode size) do:
[:i | mode at: i put: ((mode at: i) - subtractForNewStartingNote)].

mode := mode asOrderedCollection.
mode removeLast. "remove ending note, since it functionally duplicates the first note"

1 to: numberOfMode - 1
do: [ :i |
mode addLast: ((mode at: 1) + intervalOfEndingNote).
mode removeFirst].

mode addLast: intervalOfEndingNote. "add ending note back in again."

mode := mode "define green variable"

This works well. However, you can see by the sounds in the attached sound file that I am able to get this working when I use two bits of code separately, but when I combine them into a single script, I inadvertantly redefine the major scale variable. Play the attached sounds and you'll see what I mean. I'm not sure why the original major scale array is being altered, since the changes I am making are all to the mode array.

[Actually, I do have a version that works, marked "DOES WORK" in the attached file. What I have done is just paste in the same array when defining "mode," instead of saying "mode := major." But now I'm curious why this one works and the other doesn't, since I don't think manipulations that I do to the "mode" array should effect the "major" array. And anyway, my question still stands because I would like help figuring out how I can make this code generate all possible modes, and then automatically assign them names like "majorMode1," "majorMode2," etc.]

I also would like to have script generate/construct a new green variable name. ie major conflated with "Mode1" = majorMode1. This would be set up to automatically generate modes.

My ultimate goal is to have a piece of code within a same script that:

1. defines a scale (in this case, a major scale)

2. automatically generates the various modes of that scale (i.e it goes through and defines as many modes as are possible until it comes to the octave repeat of the scale. Or just generates every possible mode of the original array).

3. names the modes automatically (ike "majorMode1," "majorMode2," etc.) so that they can be referenced in the sound as green variables.

Thanks for your help.

Phil

[This message has been edited by Phi Curtis (edited 05 December 2008).]

IP: Logged

Luddy
Member
posted 05 December 2008 19:03         Edit/Delete Message   Reply w/Quote
Hi,

This statement:
mode := majorScale.
causes mode to be majorScale itself, not a copy of majorScale. Your code goes on to do assignments ('put' operations) to mode, and since mode is majorScale, majorScale is altered by these assignments.

You could fix this by copying majorScale before assigning it to mode. I think a more straightforward fix however is to use a 'collect' form to create the mode. You could use something like
(lo to: hi) collect: [ :i | majorScale of: i ]
where lo starts at the scale offset you want to extract, and hi is any value you want, so long as it is within majorScale.

Concerning the overall structure, you might consider making a mode generator function, something like

ModeGenerator := [ :Scale :ModeOffset | ... ].

You could then call it repeatedly to generate the various modes of a scale. This way you the generator would not be sensitive to the names of the original scale and the modes.

hth,

-Luddy

[This message has been edited by Luddy (edited 05 December 2008).]

IP: Logged

Phi Curtis
Member
posted 05 December 2008 19:54         Edit/Delete Message   Reply w/Quote
Thanks Luddy.

I had a feeling that's what was happening (the assignment operation was making the two arrays into effectively the same array). There must be a way to do what I'm trying here without having the two arrays be exactly the same array...I need to study Smalltalk a bit more.

This variation of your suggestion does what I want, without having to paste the same array twice:

major := #(0 2 4 5 7 9 11 12 14 16 17 19 21 23 24 26 28 29 31 33 35 36 38 40 41 43 45 47 48 50 52 53 55 57 59 60 62 64 65 67 69 71 72).
mode := (1 to: major size) collect: [:i | major at: i].

Then, for the rest, I guess I'll try putting the whole mode-creating code into an iterative statement that also constructs unique names for each one...

IP: Logged

Phi Curtis
Member
posted 05 December 2008 20:09         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Luddy:
Concerning the overall structure, you might consider making a mode generator function, something like

ModeGenerator := [ :Scale :ModeOffset | ... ].


I think I understand what you mean. I'll play with it. I need to read up on Smalltalk...

IP: Logged

SSC
Administrator
posted 06 December 2008 12:48         Edit/Delete Message   Reply w/Quote

modalscales.kym

 
Since your Array contains intervals rather than absolute notenumbers, you might be able to get by with using just that one Array and getting different modes by adding an offset to the index in your Frequency fields. For example:

code:

(((!ScaleDegree - 1 + !Mode) of: ?major) + (!Tonic - (!Mode of: ?major))) nn

!Mode is a number from 0 to 6 that shifts where in the interval pattern you start the scale.

Once you have the interval above the tonic, you can add it to !Tonic.

The last step is to subtract the pitch offset (!Mode of: ?major).

This would give the interval pattern of a major scale starting on the (!Mode + 1) degree of the scale but it would start on whatever you supply as the !Tonic.

I've attached a funny little example that just plays the scales for testing. (If you add 7 extra intervals at the top of your original array, you can avoid the complication of taking the newly computed index modulo the size of the array).

IP: Logged

Phi Curtis
Member
posted 06 December 2008 18:24         Edit/Delete Message   Reply w/Quote

ChooseScalesAndArrays.kym

 
Thanks, SSC!

That code is useful. See my attached variation, which has one fader to choose the scale, and another fader to choose the mode derived from that scale (although technically I don't think the terms dorian, phrygian, etc. apply when they are derived from the melodic and harmonic minor scales...).

The one problem I have with this approach is figuring out what to do when the !ScaleChoice fader is choosing between scales that have other numbers of notes per octave.

Phil

IP: Logged

SSC
Administrator
posted 07 December 2008 16:50         Edit/Delete Message   Reply w/Quote
quote:
(although technically I don't think the terms dorian, phrygian, etc. apply when they are derived from the melodic and harmonic minor scales...).

You probably know this already but in case anyone reading this has not played around with this feature yet: To change the names of the tic marks on a fader:
Unlock the VCS
Double-click the Fader
Under Options choose Set tick marks and labels
Then click Edit to change the label names

quote:
The one problem I have with this approach is figuring out what to do when the !ScaleChoice fader is choosing between scales that have other numbers of notes per octave.

Well, you would lose the label names this way but you could make !Mode a (0,1) variable and then, when you select a scale, you could also use that as a way to select the appropriate multiplier on !Mode. The multiplier would be equal to the number of steps per octave - 1.

IP: Logged

Phi Curtis
Member
posted 08 December 2008 00:52         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by SSC:
Well, you would lose the label names this way but you could make !Mode a (0,1) variable and then, when you select a scale, you could also use that as a way to select the appropriate multiplier on !Mode. The multiplier would be equal to the number of steps per octave - 1.

That's true. But I like not just the labels, but also the fact that there are stops/notches in the fader, rather than having a continuous fader. It makes the interface somehow more hardware-like.

Thanks again for the help.

[This message has been edited by Phi Curtis (edited 08 December 2008).]

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c