Evaluate a command input with a variable

Hello Snap! Team,

Thank you for the smooth migration to Snap! 9. My project, heavily dependent on Metaprogramming, works just fine.

However I need an advice there. Here is a brief from a previous topic:

I'm modelling the Crab Canon (J.S Bach). I need to play the main melody straight, reversed and sometimes both straight and reversed in parallel:

The tune is long enough so let's store it in a variable:

The tune get's reversed on every time image invocation. There could be a problem with the performance (which results in pause between repeats) so I would like to reverse the tune once, assign it to a variable and use that variable every time I need to play the reversed tune:

However image doesn't get evaluated to image so I can't parse and reverse it.

Both image and

work but that's not ideal.

I can do image but I prefer to introduce only one reported for manipulating tunes (image) instead of multiple (for each implemented transformation) - image, image, etc.

Here is the code - Snap! Build Your Own Blocks
. The green flag does some initialization.

I'm sure you'll have some magic to solve the puzzle.
Best.

I don't understand why you think you need metaprogramming to solve this problem. I get that you do if you store the melodies as lambdas, but the simple thing everyone else does is to store them as lists of notes,
(LIST (DO) (MI) (SOL))
and then transformations are just list processing. When you're done with transformations, then you turn the list into a sound.

Every time I get stuck with the implementation I ask my self the same ... But I believe notes as blocks/tunes as scripts are more aestetic, intuitive and easier to play with than notes as lists/tunes as lists of lists.
image vs

I imagine learning music more like grab the instrument, hit the key/, then hit another key rather than this is how C quater looks like on the notebook, this is how it sounds .... For introduction I find this approach better.

P.S one more + for DO RE MI vs C D E is that there is this nice song: "Do-Re-Mi" - THE SOUND OF MUSIC (1965) - YouTube

Wait, there's no reason the list has to have CEG instead of DoMiSol!

Also, you're mixing up input and output notations. The user would still enter a script made of DO etc blocks, but the resulting song would look like a table-format list.

True.

How can I have a block that plays a note when it is clicked and at the same time can be processed?

Even if I do image then the blocks won't stack and I need to introduce image to hear DO. It is not that bad, but still I prefer the other approach.

Anyway I found what I was looking for. When I call

inside the evaluate procedure
I get all the variables evaluated against the context of the caller and I'm able to handle both scenarios:
image and image.

All I need is to handle both cases of split's output:
image and

Thank you.

Yes, precisely, that's the essence of macros! It's great how people have taken to macrology so strongly. :~)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.