mirror of
https://github.com/thestk/stk
synced 2026-01-14 21:41:53 +00:00
Version 3.2
This commit is contained in:
committed by
Stephen Sinclair
parent
4b6500d3de
commit
3f126af4e5
264
projects/ragamatic/ragamat.cpp
Normal file
264
projects/ragamatic/ragamat.cpp
Normal file
@@ -0,0 +1,264 @@
|
||||
/************** Test Main Program Individual Voice *********************/
|
||||
|
||||
#include "RtWvOut.h"
|
||||
#include "SKINI11.msg"
|
||||
#include "Instrmnt.h"
|
||||
#include "Reverb.h"
|
||||
#include "JCRev.h"
|
||||
#include "StrDrone.h"
|
||||
#include "Sitar1.h"
|
||||
#include "Tabla.h"
|
||||
#include "VoicDrum.h"
|
||||
#include "miditabl.h"
|
||||
|
||||
#define RATE_NORM (MY_FLOAT) (22050.0/SRATE)
|
||||
|
||||
// The input control handler.
|
||||
#include "Controller.h"
|
||||
|
||||
// Return random float between 0.0 and max
|
||||
MY_FLOAT float_random(MY_FLOAT max) {
|
||||
MY_FLOAT temp;
|
||||
#if defined(__OS_Win_) /* For Windoze */
|
||||
temp = (MY_FLOAT) (rand() * max);
|
||||
temp *= ONE_OVER_RANDLIMIT;
|
||||
#else /* This is for unix */
|
||||
temp = (MY_FLOAT) (random() * max);
|
||||
temp *= ONE_OVER_RANDLIMIT;
|
||||
#endif
|
||||
return temp;
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
/* Error function in case of incorrect command-line argument specifications */
|
||||
printf("\nuseage: ragamat flag \n");
|
||||
printf(" where flag = -ip for realtime SKINI input by pipe\n");
|
||||
printf(" (won't work under Win95/98),\n");
|
||||
printf(" and flag = -is for realtime SKINI input by socket.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
long i, nTicks;
|
||||
int type;
|
||||
MY_FLOAT byte2, byte3, temp;
|
||||
MY_FLOAT outSamples[2];
|
||||
int controlMask = 0;
|
||||
bool done;
|
||||
MY_FLOAT reverbTime = 4.0; /* in seconds */
|
||||
MY_FLOAT drone_prob = 0.01, note_prob = 0.0;
|
||||
MY_FLOAT drum_prob = 0.0, voic_prob = 0.0;
|
||||
MY_FLOAT droneFreqs[3] = {55.0,82.5,220.0};
|
||||
int tempo = 3000;
|
||||
int counter = 3000;
|
||||
int key = 0;
|
||||
int ragaStep, ragaPoint = 6, voicNote;
|
||||
int ragaUp[2][13] = {{57, 60, 62, 64, 65, 68, 69, 71, 72, 76, 77, 81},
|
||||
{52, 54, 55, 57, 59, 60, 63, 64, 66, 67, 71, 72}};
|
||||
int ragaDown[2][13] = {{57, 60, 62, 64, 65, 67, 69, 71, 72, 76, 79, 81},
|
||||
{48, 52, 53, 55, 57, 59, 60, 64, 66, 68, 70, 72}};
|
||||
RtWvOut *output;
|
||||
Instrmnt *drones[3];
|
||||
Instrmnt *sitar;
|
||||
Instrmnt *voicDrums;
|
||||
Instrmnt *drums;
|
||||
Reverb *reverbs[2];
|
||||
SKINI11 *score;
|
||||
Controller *controller;
|
||||
|
||||
if (argc != 2) usage();
|
||||
|
||||
if (!strcmp(argv[1],"-is") )
|
||||
controlMask |= STK_SOCKET;
|
||||
else if (!strcmp(argv[1],"-ip") )
|
||||
controlMask |= STK_PIPE;
|
||||
else
|
||||
usage();
|
||||
|
||||
try {
|
||||
output = new RtWvOut(2);
|
||||
|
||||
// Instantiate the input message controller.
|
||||
controller = new Controller( controlMask );
|
||||
}
|
||||
catch (StkError& m) {
|
||||
m.printMessage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
drones[0] = new StrDrone(50.0);
|
||||
drones[1] = new StrDrone(50.0);
|
||||
drones[2] = new StrDrone(50.0);
|
||||
sitar = new Sitar1(50.0);
|
||||
voicDrums = new VoicDrum();
|
||||
drums = new Tabla();
|
||||
|
||||
score = new SKINI11();
|
||||
reverbs[0] = new JCRev(reverbTime);
|
||||
reverbs[0]->setEffectMix(0.5);
|
||||
reverbs[1] = new JCRev(2.0);
|
||||
reverbs[1]->setEffectMix(0.2);
|
||||
|
||||
drones[0]->noteOn(droneFreqs[0],0.1);
|
||||
drones[1]->noteOn(droneFreqs[1],0.1);
|
||||
drones[2]->noteOn(droneFreqs[2],0.1);
|
||||
|
||||
for (i=0;i<SRATE;i++) { /* warm everybody up a little */
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
|
||||
// The runtime loop begins here:
|
||||
done = FALSE;
|
||||
while (!done) {
|
||||
|
||||
nTicks = controller->getNextMessage();
|
||||
|
||||
if (nTicks == -1)
|
||||
done = TRUE;
|
||||
|
||||
for (i=0; i<nTicks; i++) {
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick()
|
||||
+ sitar->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick() + 0.5 * voicDrums->tick()
|
||||
+ 0.5 * drums->tick());
|
||||
// mix a little left to right and back
|
||||
temp = outSamples[0];
|
||||
outSamples[0] += 0.3 * outSamples[1];
|
||||
outSamples[1] += 0.3 * temp;
|
||||
output->mtick(outSamples);
|
||||
|
||||
counter -= 1;
|
||||
if (counter == 0) {
|
||||
counter = (int) (tempo / RATE_NORM);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[0]->noteOn(droneFreqs[0],0.1);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[1]->noteOn(droneFreqs[1],0.1);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[2]->noteOn(droneFreqs[2],0.1);
|
||||
if (float_random(1.0) < note_prob) {
|
||||
if ((temp = float_random(1.0)) < 0.1)
|
||||
ragaStep = 0;
|
||||
else if (temp < 0.5)
|
||||
ragaStep = 1;
|
||||
else
|
||||
ragaStep = -1;
|
||||
ragaPoint += ragaStep;
|
||||
if (ragaPoint < 0)
|
||||
ragaPoint -= (2*ragaStep);
|
||||
if (ragaPoint > 11)
|
||||
ragaPoint = 11;
|
||||
if (ragaStep > 0)
|
||||
sitar->noteOn(__MIDI_To_Pitch[ragaUp[key][ragaPoint]],
|
||||
0.05 + float_random(0.3));
|
||||
else
|
||||
sitar->noteOn(__MIDI_To_Pitch[ragaDown[key][ragaPoint]],
|
||||
0.05 + float_random(0.3));
|
||||
}
|
||||
if (float_random(1.0) < voic_prob) {
|
||||
voicNote = (int) float_random(11);
|
||||
voicDrums->noteOn(voicNote, 0.3 + (0.4 * drum_prob) +
|
||||
float_random(0.9 * voic_prob));
|
||||
}
|
||||
if (float_random(1.0) < drum_prob) {
|
||||
voicNote = (int) float_random(TABLA_NUMWAVES);
|
||||
drums->noteOn(voicNote, 0.2 + (0.2 * drum_prob) +
|
||||
float_random(0.7 * drum_prob));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type = controller->getType();
|
||||
if (type > 0) {
|
||||
// parse the input control message
|
||||
|
||||
byte2 = controller->getByte2();
|
||||
byte3 = controller->getByte3();
|
||||
|
||||
switch(type) {
|
||||
|
||||
case __SK_ControlChange_:
|
||||
if (byte2 == 1) {
|
||||
drone_prob = byte3 * NORM_7;
|
||||
}
|
||||
else if (byte2 == 2) {
|
||||
note_prob = byte3 * NORM_7;
|
||||
}
|
||||
else if (byte2 == 4) {
|
||||
voic_prob = byte3 * NORM_7;
|
||||
}
|
||||
else if (byte2 == 11) {
|
||||
drum_prob = byte3 * NORM_7;
|
||||
}
|
||||
else if (byte2 == 7) {
|
||||
tempo = (int) (11025 - (byte3 * 70));
|
||||
}
|
||||
else if (byte2 == 64) {
|
||||
if (byte3 == 0) {
|
||||
key = 1;
|
||||
droneFreqs[0] = 55.0;
|
||||
droneFreqs[1] = 82.5;
|
||||
droneFreqs[2] = 220.0;
|
||||
}
|
||||
else {
|
||||
key = 0;
|
||||
droneFreqs[0] = 82.5;
|
||||
droneFreqs[1] = 123.5;
|
||||
droneFreqs[2] = 330.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("What Need Have I for This?\n");
|
||||
drones[1]->noteOn(droneFreqs[1],0.1);
|
||||
for (i=0; i<reverbTime*SRATE; i++) { // Calm down a little
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
printf("What Need Have I for This?\n");
|
||||
drones[2]->noteOn(droneFreqs[2],0.1);
|
||||
for (i=0; i<reverbTime*SRATE; i++) { // and a little more
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
printf("RagaMatic finished ... \n");
|
||||
drones[0]->noteOn(droneFreqs[0],0.1);
|
||||
for (i=0; i<reverbTime*SRATE; i++) { // almost ready to think about ending
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
printf("All is Bliss ...\n");
|
||||
for (i=0; i<reverbTime*SRATE; i++) { // nearly finished now
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
printf("All is Bliss ...\n");
|
||||
for (i=0; i<reverbTime*SRATE; i++) { // all is bliss....
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->mtick(outSamples);
|
||||
}
|
||||
|
||||
delete output;
|
||||
delete score;
|
||||
delete drones[0];
|
||||
delete drones[1];
|
||||
delete drones[2];
|
||||
delete sitar;
|
||||
delete drums;
|
||||
delete voicDrums;
|
||||
delete reverbs[0];
|
||||
delete reverbs[1];
|
||||
delete controller;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user