Here's the altered file:
/*----------------------------------------------------------------------------
S.M.E.L.T. : Small Musically Expressive Laptop Toolkit
Copyright (c) 2007 Rebecca Fiebrink and Ge Wang. All rights reserved.
http://smelt.cs.princeton.edu/
http://soundlab.cs.princeton.edu/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
U.S.A.
-----------------------------------------------------------------------------*/
//-----------------------------------------------------------------------------
// name: kb-fret.ck
// desc: this program attempts to open a keyboard; maps key-down events to
// pitches via a fretboard-like mapping.
//
// authors: Rebecca Fiebrink and Ge Wang
// adapted from Crystalis and Joy of Chant
//
// to run (in command line chuck):
// %> chuck kb-fret.ck
//
// to run (in miniAudicle):
// (make sure VM is started, add the thing)
//-----------------------------------------------------------------------------
// base and register
12 => int base;
3 => int register;
0 => int reg_change;
// keyboard
HidIn kb;
// hid message
HidMsg msg;
// If the keyboard is not available, just exit the program right away
if( !kb.openKeyboard( 0 ) ) me.exit();
//Otherwise, assuming the program didn't exit on the last line, keep going
<<< "Ready?", "" >>>;
// sound synthesis
SndBuf bar => JCRev r => dac;
"special:dope" => bar.read;
0 => bar.gain;
// set mix
.1 => r.mix;
// bar settings
//4 => bar.preset;
// key map
int key[256];
// key and pitch
0 => key[23];
1 => key[27];
2 => key[6];
3 => key[25];
4 => key[5];
5 => key[4] => key[17];
6 => key[22] => key[16];
7 => key[7] => key[54];
8 => key[9] => key[55];
9 => key[10] => key[56];
10 => key[20] => key[11];
11 => key[26] => key[13];
12 => key[8] => key[14];
13 => key[21] => key[15];
14 => key[23] => key[51];
15 => key[28] => key[52];
16 => key[24];
17 => key[12];
18 => key[18];
19 => key[19];
20 => key[47];
21 => key[48];
22 => key[49];
// which key is current
0 => int current;
// yes
fun void registerUp()
{
if( register < 6 ) { register++; 1 => reg_change; }
<<< "register:", register >>>;
}
// yes
fun void registerDown()
{
if( register > 0 ) { register--; 1 => reg_change; }
<<< "register:", register >>>;
}
float freq;
// infinite event loop
while( true )
{
// wait for event
kb => now;
// get message
while( kb.recv( msg ) )
{
// which
if( msg.which > 256 ) continue;
if( key[msg.which] == 0 && msg.which != 29 )
{
// register
if( msg.which == 80 && msg.isButtonDown() )
registerDown();
else if( msg.which == 79 && msg.isButtonDown() )
registerUp();
}
// set
else if( msg.isButtonDown() )
{
// freq
//base + register * 12 + key[msg.which] => Std.mtof => bar.freq;
base + register * 12 + key[msg.which] - 80 => Std.mtof => bar.freq;
// fire!
Std.rand2f(.4,.6) => bar.gain;
0 => bar.pos;
// go
10::ms => now;
}
}
}
No comments:
Post a Comment