groove blox - started already. Need help with arrays and snap to
bobs at twft.com
Thu Aug 11 12:37:29 EDT 2011
Arrays are easy. To create one, simply put something into the first element: put "~/Music/GrooveBox/groovyarp.wav" into arps["track1"]. If instead, you want a multidimensional array containing all your categories: put "~/Music/GrooveBox/groovyarp.wav" into aTracks[arps]["track1"].
If you need multiple elements for each track:
put "Groovy Arp" into aTracks[arps]["track1"]["name"]
put "~/Music/GrooveBox/groovyarp.wav" into aTracks[arps]["track1"]["path"]
put "Groovy Rythm" into aTracks[drums]["track1"]["name"]
put "~/Music/GrooveBox/groovyrythm.wav" into aTracks[drums]["track1"]["path"]
If the tracks are the top level key:
put "Groovy Rythm" into aTracks["track1"]["name"]
put "Drums" into aTracks["track1"]["type"]
put "~/Music/GrooveBox/groovyrythm.wav" into aTracks["track1"]["path"]
put "Groovy Arp" into aTracks["track2"]["name"]
put "Arps" into aTracks["track2"]["type"]
put "~/Music/GrooveBox/groovyarp.wav" into aTracks["track2"]["path"]
A few caveats: It does not follow that the order of the keys will be the order you created them. I do not know why this is. For this reason, you could not put the keys of aTracks and expect them to be in the order "track1,track2,track3, ...". Refer to them by name. Secondly, you cannot test to see if atracks is empty, because an array will return true. I do not know why this is. To see if an array variable is empty, use: atracks is an array.
If you have Trevor Devore's excellent and highly recommended sqlYoga, you can use his printkeys() function to turn an array into text that can be searched or filtered. Using the above example it would look like this:
name: Groovy Rythm
name: Groovy Arp
Now you can use the filter command to get all the paths:
filter thetracks with "*path:*"
Now delete the headers using:
replace " path: " with empty in thetracks
Which magically and without fuss produces a list of file paths to your tracks:
Very handy with large arrays! Don't have to create repeat loops! (Trevor did that for you). :-)
On Aug 10, 2011, at 3:44 PM, Admin wrote:
> Dear All,
> I already got drag and drop sort of working - can drag
> a wave file to a rectangle and it retains the name of the file - so now
> I can play that file once it is dragged to the track view.
> I am not
> sure how to make an array - and I assume an array is what I need to keep
> track of multiple blocks (there are 4 categories of blocks - drum, arp,
> bass and fxfill)
> Also, how would I implement a 'snap to' interface?
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the Use-livecode