Showing posts with label KIns. Show all posts
Showing posts with label KIns. Show all posts

Thursday, June 14, 2012

KIns progress: 6/14/12

New features:
-Sustained notes! When you release the key the note doesn't cut off immediately. Instead it fades out.
-Finer control over what keys do what. This is hopefully paving the way for the user to change the key mappings from a GUI.

Next step is to combine Lucy's GUI with this code below.

Tuesday, June 12, 2012

Kins Project Update

I have been working on the Kins project, and it is going on very well so far. I am making use of te MAUI elements in mini-Audicle and they are very helpful. I prefer to post my code when I am done with everything--probably tomorrow, but you may view my GUI. The idea is to have individuals choose instruments they would like to play and allow them to control the volume of the instruments as well. Keyboard keys are mapped to make them easier to play. I am done with my organ--built on from my last one, but tried to make the code look like it was written by someone who has been programming for a while (used arrays instead of a bunch of if statements). Please feel free to critique the whole thing so we come up with the best project.


KIns progress: 06/12/12

Some significant progress on the KIns has been made! Here's a summary of my process so far:

I started using keyinmulti2.ck (http://smelt.cs.princeton.edu/code/keyboard/keyinmulti2.ck) from the S.M.E.L.T. website as my base. It already supported polyphony (playing more than one note at once) and variable note length, so those things can be crossed off the KIns project summary (I've updated that post too to reflect the work done so far). The way the program implements polyphony is very elegant--the making of actual noise is handled by one function, and when the program receives a message that a key has been pressed on the keyboard, it sporks a new shred of the keysound function, and when a key release message is received, it unsporks the proper shred to stop the sound. Therefore, pressing three keys at once will cause three shreds to get sporked, which will sit there playing their respective notes until they are unsporked. The number of notes you can have playing at one time seems to be limited only by the number of simultaneous key presses the computer is capable of registering.

I've made two specific modifications to keyinmulti2.ck.
1. I rearranged the key mappings to make a more linear progression. They were originally arranged in "frets" like on a guitar, so that there were a lot of overlapping notes between the key rows. This arrangement actually makes somewhat more sense for real music making, but for the beginner level user that the KIns is aimed at, I think it just makes it a lot more confusing. I feel like there's probably a somewhat optimal arrangement for the key mapping that makes more sense the way I've got it arranged now, but I think that will be figured out through experimentation much later on.
2. I added the capability to switch between different instrument sounds by pressing the number keys. In this version, 1 switches to a basic sine wave, 2 is a saw wave, and 3 is a "Rhodey" instrument (from the STK instrument kit that's built into ChucK). It's extremely easy to edit the instruments/add new instruments in the code, but I'm hoping eventually to be able to do this via a GUI and to also have slider controls on the GUI for the individual properties of the instruments. For example, a sine wave has very few built-in controls, but the STK instruments have lots of different controls that vary with the instrument. Having a dynamically changing GUI would be great for giving more control over these instruments.

One thing that I think would be good to work on next would be capability to sustain notes after the key is released, so that they fade out rather than being cut off abruptly by the shred being unsporked right as the key is released. Another thing is of course the GUI, which could be executed in MAUI (miniAudicle's built in, but very simple GUI). Processing also seems a promising choice for the GUI though. Julia found some demos that show two-way interaction between Processing and ChucK, I think via OSC, so I might look into those to see if that would be possible.

Here is the code for the current iteration of the KIns. It's very heavily commented, probably more so than is actually necessary.


/*----------------------------------------------------------------------------
S.M.E.L.T. : Small Musically Expressive Laptop Toolkit

Copyright (c) 2008 Dan Trueman.  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: keyinmulti2.ck
// desc: this program creates an array filled with the keyboard code for
// each key on the keyboard, indexed by the keyboard row and column. Then,
// it treats each row as a string, which is "tuned" in the code. Pressing 
// a key will play the note.
//
// This version supports polyphony, and the note ends when you release the key!
// Warning: Due to hardware (not our fault), you may not be able to play all chords.
//
// to run (in command line chuck):
//     %> chuck keyinmulti2.ck
//
// to run (in miniAudicle):
//     (make sure VM is started, add the thing)

//
//-----------------------------------------------------------------------------

//Hid = human input device. It's a variable to hold whatever HID the program
//needs to use
Hid hi;
//Hidmsg contains data about what the HID is doing at any given moment
HidMsg msg;
//sound determines what sound the keyboard is making at any given time
0 => int sound;

//initializes the HID as the keyboard, and exits if there's no keyboard available
0 => int deviceNum;
hi.openKeyboard( deviceNum ) => int deviceAvailable;
if ( deviceAvailable == 0 ) me.exit();
<<< "keyboard '", hi.name(), "' ready" >>>;


//array with key codes, for MacBook anyhow
[ 

[30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 45, 46, 42], //1234... row
[20, 26, 8, 21, 23, 28, 24, 12, 18, 19, 47, 48, 49], //qwer... row
[4, 22, 7, 9, 10, 11, 13, 14, 15, 51, 52], //asdf... row
[29, 27, 6, 25, 5, 17, 16, 54, 55, 56]   //zxcv... row

]   @=> int row[][];

//our big array of pitch values, indexed by ASCII value
int keyToPitch_table[256];

//this function takes each row and tunes it in half steps, based
//on whatever fundamental pitch note specified
fun void tuneString(int whichString, int basepitch) {
    
    for (0 => int i; i < row[whichString].cap(); i++) {
        
        basepitch + i => keyToPitch_table[row[whichString][i]];
        
        <<<row[whichString][i], keyToPitch_table[row[whichString][i]]>>>;
        
    }
    
}

//tune the strings!! This starts at (I think) A1, and then continues up by halftones
//each key. To hear the progression, go from left to right z->?, then up to a->",
//then q->]

tuneString(3, 55);
tuneString(2, 65);
tuneString(1, 76);
//tuneString(0, 185);


//makes the key sounds!
//currently configured to let the top row (number keys) control the type of sound
//the KIns makes. The code below should be pretty self-explanatory.
fun void keysound(float freq, Event noteOff) {
    
    if(sound==0){
    
    SinOsc sine => ADSR envelope => dac;
    envelope.set(80::ms, 25::ms, 0.1, 150::ms);
    
    freq => sine.freq;
    
    envelope.keyOn();
    noteOff => now;
    envelope.keyOff();
    150::ms => now;
    
    envelope =< dac;
}
else if(sound==1){
    
    SawOsc saw => ADSR envelope => dac;
    envelope.set(10::ms, 25::ms, 0.1, 150::ms);
    
    freq => saw.freq;
    
    envelope.keyOn();
    noteOff => now;
    envelope.keyOff();
    150::ms => now;
    
    envelope =< dac;
}
else if(sound ==2){
    Rhodey voc=> JCRev r =>dac;
    freq => voc.freq;
0.8 => voc.gain;
.8 => r.gain;
.2 => r.mix;

voc.noteOn(1);
    noteOff => now;
    voc.noteOff(1);
    150::ms => now;
}
}

Event noteOffs[256];

//infinite time loop
while( true )
{
    
    hi => now;
    
    //only does things when there's a message coming in from the HID
    while( hi.recv( msg ) )
    {
        //only if the message from the HID is that a button was pressed...
        if( msg.isButtonDown() )
        {
            //the following if/elseif statements check to see if the button press
            //should cause the type of sound to change. Only the value
            //of sound needs to change, as the keysound function
            //handles actually producing the appropriate sound.
            if(msg.which==30){
                0 => sound;
            }
            else if(msg.which==31){
                1=>sound;
            }
            else if(msg.which==32){
                2=>sound;
            }
            else{
            keyToPitch_table[ msg.which ] => Std.mtof => float freq;
            spork ~ keysound(freq, noteOffs[ msg.which] );
        }
            
        }
        //if the message was not that a button was pressed...
        else
        {   
            noteOffs[ msg.which ].signal();
        }
    }
}


Friday, June 8, 2012

The DOHboard

The original file can be found in the keyboard folder within the SMELT download.

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;
              }
    }
}

Thursday, June 7, 2012

KIns research: Existing digital audio programs

// everyone please add to this list! We want to compile a comprehensive list of existing digital audio programs so that we can decide exactly what features we want KIns to have.


Audacity:
Main features:
-record audio
-manipulate recorded audio through filters
-arrange multiple clips of audio together into one track
-free

Garageband:
Main features:
-record audio
-arrange multiple clips of audio together into one track
-manipulate recorded audio through filters
-basic midi recording, composing, and editing, but not available unless you have a midi controller
-remastering of audio tracks
-comes with Mac computers, so not free but still pretty widely available

Circle:
Main features:
-create complex sounds through a visual interface
-has piles of premade sounds
-intended to extend the capabilities of a midi controller
-$69.00

Ableton Live:
Main features:
-Extremely sophisticated program for composing, recording, and live performances
-intended to extend the capabilities of a midi controller, as well as many other types of audio equipment
-one of the industry standards
-$99-$850

Garage Band for iPad:
Main features:
-port of Garageband to make the most of the touchscreen interface
-automates a lot of the music making process, at the expense of control (for example, set the virtual piano to autoplay and you can just press a chord and it will play that chord in a predetermined pattern)
-has a lot of virtual instruments (piano, drum, bass, guitar) that you can play using the touch screen
-not very sophisticated arranging tools
-no ability to directly edit the midi notes once they're created, like you can do in the normal Garageband
-$4.99 + the cost of an iPad if you don't already have one

Conclusion:
This is not a final conclusion, so if you reach a different one, please add it/edit this one.

It seems that there is a place for a simple, free, open source digital music creation program. The possible networking capabilities of the KIns would make it extremely powerful and possibly fairly unique among digital music creation software. There is also very little software geared towards beginners (people with little to no musical background), or at least very little that doesn't try to automate the process for the user (such as Garageband on the iPad).

Keyboard Instrument (KIns) Project Proposal

// everyone please feel free to add/remove/change things in here! This should be a continually developed document that states our goal, steps, features, etc. As we complete features we should come back to this document and strike through what we've done already so we can see how much we've accomplished :)

//Last update: 6/12/12

Goal: To create a digital instrument that is somewhat analogous to a real, physical instrument that is open source, free, very easy to learn and use, and can be a gateway to a deeper understand of both musical theory and digital audio.

Features:
Initial goals:
-sounds controlled by the computer keyboard completed
-able to play multiple sounds at once completed
-simple gui
-be able to switch between a few different instruments completed
-website that explains the goal and provides instructions on downloading and using
-a few tutorials on the website explaining the basics of how the instrument works
Stretch goals:
-ability to loop audio (press a button, play a melody, press the button again, and the melody will loop over and over)
-ability to record to both a common filetype (like a .wav file) and to a series of keystrokes
-ability to paste in a series of keystrokes into the gui and have the program play them back to you as a melody
-ability to distribute the program as an installable package, to eliminate the need for the user to compile it themselves
- ability to create own laptop orchestra by having some musical scores that allow multiple users to select different instruments and play an arrangement together (to improve timing, some networking functions might be useful)

Proposed steps to complete the project:
1. Do research on existing digital audio programs and refine our proposed list of features. We want to create something that is relatively unique, or at least is unique in its appeal to the beginner user base.
2. Make the KIns.
3. ???
4. Profit! (not really)