// // Programmer: Craig Stuart Sapp // Creation Date: 26 December 1997 // Last Modified: 26 December 1997 // Filename: box.cpp // Syntax: Visual C++ 5.0; Radio Baton Improv // // Description: Demonstrates how to create boxes on the radio drum. // Notice that the edged of the boxes are very narrow, // and the notes can oscillate at the edges. // #include "improv.h" /*----------------- beginning of improvization algorithms ---------------*/ int boxlevel; // the height of the four boxes on the surface of the drum /*--------------------- maintenance algorithms --------------------------*/ void description(void) { printtopline(); printstringline( " Description: Demonstrates how to create boxes +---------+---------+ "); printstringline( " on the radio drum. Notice that the edged of | note 1 | note 2 | "); printstringline( " the boxes are very narrow, and the notes can | | | "); printstringline( " oscillate at the edges. There are four boxes | (dial1) | (dial2) | "); printstringline( " on the drum surface, one for each quadrant. +---------+---------+ "); printstringline( " When a stick enters a box, it will generate a | note 3 | note 4 | "); printstringline( " note. | | | "); printstringline( " The volume of each box is controlled by | (dial3) | (dial4) | "); printstringline( " each of the four dials as indicated to the +---------+---------+ "); printstringline( " right. The b14+ raises the height of the boxes, and b15+ lowers "); printstringline( " the height of the box on the surface of the radio drum. "); printbottomline(); } void initialization(void) { boxlevel = 100; } void finishup(void) { } /*-------------------- main loop algorithms -----------------------------*/ int newbox(int batonNumber) { // this function returns true if a new box was entered switch (batonNumber) { case 1: // first check to see if the x-axis border was crossed: if (midiscale(baton.x1p[0], 0, 1) != midiscale(baton.x1p[-1], 0, 1)) { return 1; } // now check to see if the y-axis boarder was crossed: if (midiscale(baton.y1p[0], 0, 1) != midiscale(baton.y1p[-1], 0, 1)) { return 1; } // now check the z-axis if (baton.z1p[0] > boxlevel && baton.z1p[-1] <= boxlevel) { return 1; } break; case 2: // first check to see if the x-axis border was crossed: if (midiscale(baton.x2p[0], 0, 1) != midiscale(baton.x2p[-1], 0, 1)) { return 1; } // now check to see if the y-axis boarder was crossed: if (midiscale(baton.y2p[0], 0, 1) != midiscale(baton.y2p[-1], 0, 1)) { return 1; } // now check the z-axis if (baton.z2p[0] > boxlevel && baton.z2p[-1] <= boxlevel) { return 1; } break; } // end of switch // no new box return 0; } void playbox(int boxnumber) { switch (boxnumber) { case 11: // note: percussion sound on test soundcard are very bad so changed note_on(CH_9, GM_LOW_MID_TOM, baton.d1p[0]); break; case 12: note_on(CH_9, GM_HI_MID_TOM, baton.d2p[0]); break; case 21: note_on(CH_9, GM_LOW_TOM, baton.d3p[0]); break; case 22: note_on(CH_9, GM_HIGH_TOM, baton.d4p[0]); break; } // end switch } void playboxnote1(void) { int boxnumber = 10 * midiscale(baton.x1p[0], 1, 2) + midiscale(baton.y1p[0], 1, 2); playbox(boxnumber); } void playboxnote2(void) { int boxnumber = 10 * midiscale(baton.x2p[0], 1, 2) + midiscale(baton.y2p[0], 1, 2); playbox(boxnumber); } void mainloopalgorithms(void) { if (newbox(1)) { playboxnote1(); } if (newbox(2)) { playboxnote2(); } } /*-------------------- triggered algorithms -----------------------------*/ void stick1trig(void) { } void stick2trig(void) { } void b14plustrig(void) { boxlevel--; if (boxlevel < 0) boxlevel = 0; cout << "boxlevel = " << boxlevel << endl; } void b15plustrig(void) { boxlevel++; if (boxlevel > 127) boxlevel = 127; cout << "boxlevel = " << boxlevel << endl; } void b14minusuptrig(void) { cout << "b14 pedal released" << endl; } void b14minusdowntrig(void) { cout << "b14 pedal released" << endl; } void b15minusuptrig(void) { cout << "b15 pedal released" << endl; } void b15minusdowntrig(void) { cout << "b15 pedal depressed" << endl; } void keyboardchar(int key) { charsynth(key); } /*------------------ end improvization algorithms -----------------------*/ /* some functions and variables provided by the support program program_change(channel, instrument); -------- sets the timbre for a channel control_change(channel, controller, value); - sends a continuous controller note_on(channel, keynumber, keyvelocity); --- plays a MIDI note note_off(channel, keynumber); --------------- same as note_on with 0 vel. raw_send(channel, command, data1, data2); --- send some midi command long t_time; -------------------------------- current time in milliseconds short pt1, pt2, pt3, pt4; ------------------- current pot (dial) positions short xt1,yt1,zt1,xt2,yt2,zt2; -------------- current stick positions short wh1, wh2; ----------------------------- whack strength of a trigger short xw1, yw1, xw2, yw2; ------------------- x and y positions at trigger short hit1, set1, hit2, set2; --------------- hit and set levels of sticks short whack1,whack2; ------------------------ registers set by stick triggers long trigtime1, trigtime2; ----------------- times of stick triggers */