[chuck-users] how to mickey-mouse a 'switch' statement into chuck?

Forrest Curo treegestalt at gmail.com
Tue Oct 13 13:49:08 EDT 2015


Hmmm! Then this would also work?
 [a tinkered-with example] --

(It doesn't appear that a chuck file absolutely _needs_ to end in '.ck',
except for our convenience. So if I put in a file for each keyboard letter
I would use....):
"

KBHit kb;

// time-loop
while( true )
{
    // wait on kbhit event
    kb => now;

    // potentially more than 1 key at a time
    while( kb.more() )
    {
        // print key value
        machineadd(kb.getchar());
    }
}

"

On Tue, Oct 13, 2015 at 8:04 AM, Michael Heuer <heuermh at gmail.com> wrote:

> Hello Forrest,
>
> The import.ck script is a workaround for this issue
>
> Add namespaces and import statements #34
> https://github.com/spencersalazar/chuck/issues/34
>
> I believe many other ChucK projects use something similar.  If you don't
> want to see plugin related warnings, you can just comment out from around
> line 387 down, and of course anything else you don't need.
>
>    michael
>
>
> On Mon, Oct 12, 2015 at 10:34 PM, Forrest Curo <treegestalt at gmail.com>
> wrote:
>
>> Okay, I finally found the documentation re usage...
>> https://github.com/heuermh/lick/wiki
>>
>> Shreds that just declare classes so that other shreds can instantiate &
>> use them... It makes my mind blur, but so it goes!
>>
>> On Mon, Oct 12, 2015 at 3:54 PM, Forrest Curo <treegestalt at gmail.com>
>> wrote:
>>
>>> I'm gathering that I can just put 'machine.add(<any of these classes in
>>> the directory that I want to use>)' and
>>> that should work(?)
>>>
>>> On Mon, Oct 12, 2015 at 2:54 PM, Forrest Curo <treegestalt at gmail.com>
>>> wrote:
>>>
>>>> Okay, I did find the github zip for tap-plugins -- but the later
>>>> plugins are struggling; and I wasn't thinking of using them... so I'll
>>>> assume that I'm okay if I don't, for now.
>>>>
>>>> On Mon, Oct 12, 2015 at 1:32 PM, Michael Heuer <heuermh at gmail.com>
>>>> wrote:
>>>>
>>>>> Forrest Curo <treegestalt at gmail.com> wrote:
>>>>>
>>>>>> "Something more elaborate than branching on the value of a specific
>>>>>> variable?"
>>>>>>
>>>>>> To use a text keyboard to trigger real-time changes in key, mode
>>>>>> ('major', 'minor', etc), record-&-repeat-&-vary (by scale degrees in
>>>>>> whichever the current  key & mode are), accelerate or slow playback, change
>>>>>> target instrument for playback-and/or-midi-keyboard, dump or keep current
>>>>>> loop, etc:
>>>>>> with some 36+ keys available for whatever organization of this works
>>>>>> --
>>>>>> and I want to be able to modify the arrangement meanwhile so I don't
>>>>>> trap myself into a bad design...
>>>>>>
>>>>>> so running the text input through a maze of logic by ascii values
>>>>>> seems too cumbersome.
>>>>>> I know, I could search-&-replace, but finding a key value in a list
>>>>>> and changing the associated function
>>>>>> just seems a whole lot less ugly!
>>>>>> -------------------------
>>>>>>
>>>>>> Um, I'm now trying to install 'tap-plugins' as a prerequisite for
>>>>>> installing 'lick' -- and the instructions for that are telling me, ~'just
>>>>>> cd into folder and run 'make' -- but make can't find anything _to_ make! Do
>>>>>> I really need those plugins to install & use lick?
>>>>>>
>>>>>
>>>>> No.  Without them chuck will complain when loading the import.ck file
>>>>>
>>>>> $ chuck + import.ck
>>>>> ...
>>>>> [TapeDelay.ck]:line(26): cannot extend incomplete type 'Swh'
>>>>> [TapeDelay.ck]:line(26): ...(note: the parent's declaration must
>>>>> preceed child's)
>>>>> [RubberBand.ck]:line(26): cannot extend incomplete type 'Ladspa'
>>>>> [RubberBand.ck]:line(26): ...(note: the parent's declaration must
>>>>> preceed child's)
>>>>> "LiCK imported." : (string)
>>>>>
>>>>> but everything else will work fine.  And installing all of those
>>>>> plugins is a real mess, especially on OSX.  I should probably cut a docker
>>>>> image at some point.
>>>>>
>>>>>    michael
>>>>>
>>>>>
>>>>>
>>>>>> On Mon, Oct 12, 2015 at 11:41 AM, Spencer Salazar <
>>>>>> spencer at ccrma.stanford.edu> wrote:
>>>>>>
>>>>>>> Doing functional stuff in ChucK can be pretty fun (and verbose), but
>>>>>>> for specifically switch-case structures, mostly these can be implemented
>>>>>>> e.g. as
>>>>>>>
>>>>>>> if(var == 0) // case 0:
>>>>>>> { }
>>>>>>> else if(var == 1) // case 1:
>>>>>>> { }
>>>>>>> else // default:
>>>>>>> { }
>>>>>>>
>>>>>>> You can't do fall-throughs or nutty things like Duff's device, but
>>>>>>> (making up a number) maybe 90% of switch-case uses I see are basically a
>>>>>>> slightly better-looking if-else. Are you doing something more elaborate
>>>>>>> than branching on the value of a specific variable?
>>>>>>>
>>>>>>> spencer
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Oct 12, 2015 at 2:22 PM, Forrest Curo <treegestalt at gmail.com
>>>>>>> > wrote:
>>>>>>>
>>>>>>>> It looks far prettier than a mess of logical spaghetti!
>>>>>>>>
>>>>>>>> But is this documented with examples for the help & understanding
>>>>>>>> of object-challenged geezers from the days of punch-card boxes converted
>>>>>>>> twice/day to error-message listings?
>>>>>>>>
>>>>>>>> On Mon, Oct 12, 2015 at 10:37 AM, Michael Heuer <heuermh at gmail.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Forrest Curo <treegestalt at gmail.com> wrote
>>>>>>>>>
>>>>>>>>>> Since switches have so far not been included, is there a way
>>>>>>>>>> around this?
>>>>>>>>>>
>>>>>>>>>> An array of Events?
>>>>>>>>>>
>>>>>>>>>> An array of functions, either numbered or associative? How to
>>>>>>>>>> declare and call such an array?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ChucK doesn't have function pointers or similar, so I've resorted
>>>>>>>>> to functors
>>>>>>>>>
>>>>>>>>> https://github.com/heuermh/lick/blob/master/lick/fn
>>>>>>>>>
>>>>>>>>> E.g.
>>>>>>>>>
>>>>>>>>> class DoSomething extends Procedure {
>>>>>>>>>   fun void run() { ... }
>>>>>>>>> }
>>>>>>>>> class DoSomethingElse extends Procedure {
>>>>>>>>>   fun void run() { ... }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> DoSomething doSomething;
>>>>>>>>> DoSomethingElse doSomethingElse;
>>>>>>>>>
>>>>>>>>> ArrayList procedures;
>>>>>>>>> procedures.add(doSomething);
>>>>>>>>> procedures.add(doSomethingElse);
>>>>>>>>>
>>>>>>>>> while (true) {
>>>>>>>>>   procedures.sample() $ Procedure @=> Procedure procedure;
>>>>>>>>>   procedure.run();
>>>>>>>>>   1::second => now;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Yeah, it ain't pretty.
>>>>>>>>>
>>>>>>>>>    michael
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> chuck-users mailing list
>>>>>>>>> chuck-users at lists.cs.princeton.edu
>>>>>>>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> chuck-users mailing list
>>>>>>>> chuck-users at lists.cs.princeton.edu
>>>>>>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Spencer Salazar
>>>>>>> Doctoral Candidate
>>>>>>> Center for Computer Research in Music and Acoustics
>>>>>>> Stanford University
>>>>>>>
>>>>>>> spencer at ccrma.stanford.edu
>>>>>>> +1 831.277.4654
>>>>>>> https://ccrma.stanford.edu/~spencer/
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> chuck-users mailing list
>>>>>>> chuck-users at lists.cs.princeton.edu
>>>>>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> chuck-users mailing list
>>>>>> chuck-users at lists.cs.princeton.edu
>>>>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> chuck-users mailing list
>>>>> chuck-users at lists.cs.princeton.edu
>>>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>>>>
>>>>>
>>>>
>>>
>>
>> _______________________________________________
>> chuck-users mailing list
>> chuck-users at lists.cs.princeton.edu
>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>
>>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151013/9c7f3e72/attachment.html>


More information about the chuck-users mailing list