Hi
I took Grahams advise and started coding some of what I'll be needing
and came up with the following way to do legato the IMO prober way;
latest note on is sounding. I figured I needed a stack, so I made one.
Three questions arise:
1) Did I reinvent a wheel? Is there alreasy a stack implemented in chuck
(I looked in the docs but didn't find one)?
2) Is there a smarter/smaller/more elegant way of implementing a legato
instrument the way I want; latest note on is sounding?
3) Most importently (for my learning chuck): Is there a way of getting
rid of the static stack size (int stack_size)? In other words; can I
have a dynamically growing array in chuck?
Thanks in advance for any reply...
--
peace, love & harmony
Atte
http://www.atte.dk
1 => int device;
MidiIn midi_in;
MidiMsg msg;
if(!midi_in.open(device)) me.exit();
<<< "MIDI device:", midi_in.num(), " -> ", midi_in.name() >>>;
sinosc s => ADSR env => gain g => dac;
.01 => env.attackTime;
.1 => env.releaseTime;
.35 => g.gain;
1 => env.keyOff;
stack held_keys;
while(true)
{
// wait on the event 'midi_in'
midi_in => now;
// get the message(s)
while(midi_in.recv(msg))
{
// print out midi message
<<< msg.data1, msg.data2, msg.data3 >>>;
if(msg.data3 != 0)
{
held_keys.push(msg.data2);
}
else
{
held_keys.remove_by_value(msg.data2);
}
if(held_keys.count() > 0)
{
std.mtof(held_keys.pop()) => s.freq;
held_keys.unpop();
if(msg.data3 != 0){
1 => env.keyOn;
}
}
else
{
1=> env.keyOff;
}
}
}
public class stack
{
200 => int stack_size;
int latest_popped;
int the_stack[stack_size];
0 => int nb_elements;
fun void push(int element)
{
if(nb_elements < stack_size)
{
element => the_stack[nb_elements];
nb_elements++;
}
}
fun int pop()
{
if(nb_elements > 0)
{
the_stack[nb_elements--] => latest_popped;
return latest_popped;
}
else
{
return 0;
}
}
fun void unpop()
{
this.push(latest_popped);
}
fun void remove_by_value(int value_to_be_removed)
{
for(0 => int i; i
Hi Atte,
1) Did I reinvent a wheel? Is there alreasy a stack implemented in chuck (I looked in the docs but didn't find one)?
Currently, there is no stack implemented in chuck's class library, though one is planned. (I think reinventing the wheel is a general rule of thumb in chuck)
2) Is there a smarter/smaller/more elegant way of implementing a legato instrument the way I want; latest note on is sounding?
Your solution seems like a good way to go, especially since state needs to be pushed.
3) Most importently (for my learning chuck): Is there a way of getting rid of the static stack size (int stack_size)? In other words; can I have a dynamically growing array in chuck?
At the moment, arrays in chuck are not dynamically "grow-able", but this feature is on the priority list (array.push_back, array.pop_back, array.size()). For now, one may have to write a dynamic array wrapper class to use this feature. Best, Ge!
participants (2)
-
Atte André Jensen
-
Ge Wang