SLOrk/Instruments/KoolKeys

From CCRMA Wiki
Revision as of 09:41, 20 May 2009 by Wsun (Talk | contribs) (ChucK Code)

Jump to: navigation, search

Description

The program senses mouse movement, and plays chords (each note of the chord on a different channel) at the volume which cooresponds to the speed of the mouse movement. It can be modified to play through a Hemi or through laptop speakers.

Usage

Installation

Executing

  • Using a terminal go to the folder where "koolkeys.ck" is located
  • On the terminal window type: (replace N with the number of output channels of the audio card)
    chuck -cN koolkeys.ck
  • Play!

Execution

This program works much like a keyboard on a piano, and is highly based off of the virtual keyboard in Garage Band.

  1. Select the root note by using 2nd and 3rd rows of the keyboard (from A & W to P & '). See root note selection for details
  2. Play chord by moving finger over trackpad
  3. Optional:

Key mapping

Root note selection
C C# D D# E F F# G G# A A# B C C# D D# D E F
A W S E D F T G Y H U J I K O L P ;
Chord selection
Major Minor Dominant 7 Minor 7 Power Sixth Major 7 Sustained 4 Diminished
Z X C V B N M ,
Register selection

[+] to Increase by 1 octave ([=] will suffice).
[-] to Decrease by 1 octave.

Ping tempo

[ [ ] to decrease ping tempo by 5 bpm.
[ ] ] to increase ping tempo by 5 bpm.

Chord isolation

[SHIFT] + [1] to select lowest note
[SHIFT] + [2] to select medium low note
[SHIFT] + [3] to select medium high note
[SHIFT] + [4] to select highest note
[SHIFT] + [5] to select all of chord.

Advanced users

ChucK Code

Here is the code:

//KoolKeys

2 => int speakers;
60 => int key;
0 => int chance_high;
0 => int player;
240 => float tempo;

SinOsc frst => JCRev r => dac.chan(0%speakers);
SinOsc thrd => r => dac.chan(1%speakers);
SinOsc fith => r => dac.chan(2%speakers);
SinOsc sevn => r => dac.chan(3%speakers);

SinOsc high => r => Echo a;

[0,4,7,12] @=> int maj[];
[0,3,7,12] @=> int min[];
[0,4,7,10] @=> int dom7[];
[0,3,7,10] @=> int min7[];
[0,7,12,0] @=> int pwr[];
[0,4,7,9] @=> int six[];
[0,4,7,11] @=> int maj7[];
[0,5,7,12] @=> int sus4[];
[0,4,7,14] @=> int nin[];
[0,2,7,12] @=> int sec[];
[0,3,6,9] @=> int dim7[];
[-1,3,6,11] @=> int flat7[];

KBHit kb; //keyboard
Hid hi;
HidMsg msg;
0=>float volume;
0=>float true_vol;

if( !hi.openMouse( 0 ) ) me.exit();

int k;
maj @=> int chord[];
0 => int deg;
0 => int octave;
float play_now[];


function float[] chnum(int start, int deg, int chord[]) {
    return [Std.mtof(start+deg+octave+chord[4%4]),Std.mtof(start+deg+octave+chord[5%4]),Std.mtof(start+deg+octave+chord[6%4]),Std.mtof(start+deg+octave+chord[7%4])];
}


function void get_mouse() {
    while (true) {
        hi => now;
        while (hi.recv( msg )) {
    
            if( msg.isMouseMotion() ) {
                Math.abs(msg.deltaX)+Math.abs(msg.deltaY)+volume=>volume;
            }
        }
    }
}

function void main_loop() {
    while (true) {
        volume*.85 => volume;
        volume => true_vol;
        true_vol/4500.0 => true_vol;
        if (true_vol>1.0) {1.0=>true_vol;}
        if (true_vol<.001) {0.0=>true_vol;}
        
        
        kb.getchar() => k;
        //<<<k>>>;
        if (k>=48&k<=57) {(k-48)*2 => chance_high;<<<(k-48)*2," pings">>>;}
        
        if (k==122) {maj@=>chord;<<<"Major","">>>;}
        if (k==120) {min@=>chord;<<<"Minor","">>>;}
        if (k==99) {dom7@=>chord;<<<"Dominant 7","">>>;}
        if (k==118) {min7@=>chord;<<<"Minor 7","">>>;}
        if (k==98) {pwr@=>chord;<<<"Power","">>>;}
        if (k==110) {six@=>chord;<<<"Sixth","">>>;}
        if (k==109) {maj7@=>chord;<<<"Major 7","">>>;}
        if (k==44) {sus4@=>chord;<<<"Sustained 4","">>>;}
        if (k==46) {nin@=>chord;<<<"Ninth","">>>;}
        if (k==47) {dim7@=>chord;<<<"Diminshed 7","">>>;}
        
        if (k==97) {0=>deg;<<<"C","">>>;}
        if (k==119) {1=>deg;<<<"C#","">>>;}
        if (k==115) {2=>deg;<<<"D","">>>;}
        if (k==101) {3=>deg;<<<"D#","">>>;}
        if (k==100) {4=>deg;<<<"E","">>>;}
        if (k==102) {5=>deg;<<<"F","">>>;}
        if (k==116) {6=>deg;<<<"F#","">>>;}
        if (k==103) {7=>deg;<<<"G","">>>;}
        if (k==121) {8=>deg;<<<"G#","">>>;}
        if (k==104) {9=>deg;<<<"A","">>>;}
        if (k==117) {10=>deg;<<<"A#","">>>;}
        if (k==106) {11=>deg;<<<"B","">>>;}
        if (k==107) {12=>deg;<<<"C","">>>;}
        if (k==111) {13=>deg;<<<"C#","">>>;}
        if (k==108) {14=>deg;<<<"D","">>>;}
        if (k==112) {15=>deg;<<<"D#","">>>;}
        if (k==59) {16=>deg;<<<"E","">>>;}
        if (k==39) {17=>deg;<<<"F","">>>;}

        if (k == 45) {12 -=> octave;<<<"Octave:",octave/12>>>;}
        if (k == 61) {12 +=> octave;<<<"Octave:",octave/12>>>;}

        if (k == 91) {5 -=> tempo;<<<tempo,"bpm">>>;}
        if (k == 93) {5 +=> tempo;<<<tempo,"bpm">>>;}

        if (k == 33) {1 => player;<<<"Base","">>>;}
        if (k == 64) {2 => player;<<<"Tenor","">>>;}
        if (k == 35) {3 => player;<<<"Alto","">>>;}
        if (k == 36) {4 => player;<<<"Soprano","">>>;}
        if (k == 37) {0 => player;<<<"All","">>>;}
        //<<<player>>>;

        chnum(key,deg,chord) @=> play_now;
        
        true_vol/5.0=>true_vol;
        //<<<true_vol>>>;
        if (player == 1) {true_vol => frst.gain;0 => thrd.gain;0 => fith.gain;0 => sevn.gain;}
        if (player == 2) {true_vol => thrd.gain;0 => frst.gain;0 => fith.gain;0 => sevn.gain;}
        if (player == 3) {true_vol => fith.gain;0 => frst.gain;0 => thrd.gain;0 => sevn.gain;}
        if (player == 4) {true_vol => sevn.gain;0 => frst.gain;0 => thrd.gain;0 => fith.gain;}
        if (player == 0) {true_vol => frst.gain;true_vol => thrd.gain;true_vol => fith.gain;true_vol => sevn.gain;}
        play_now[0] => frst.freq;
        play_now[1] => thrd.freq;
        play_now[2] => fith.freq;
        play_now[3] => sevn.freq;
        
        
        
        100::ms => now;
    }
}

function void pings(){
while(true){

for (0 => int i; i < chance_high; i++) {
            .05-true_vol/2 => high.gain;
            a => dac.chan(Std.rand2(0,speakers - 1));
            Std.mtof(chord[Std.rand2(0,3)]+key+deg+Std.rand2(0,1)*12) => high.freq;
            (60000/tempo)::ms => now;
        }
            0.0 => high.gain;
            a =< dac;
            0 => chance_high;

  
  100::ms => now;
}
}

spork ~ get_mouse();
spork ~ main_loop();
spork ~ pings();

while (true) {
    100::ms=>now;   
}



-w