Basic Electroacoustics II: Music-Making Systems

Music G6602Y
TueThu 3:10-5:00pm
Spring 2008
Professor: Douglas Repetto [douglas at music columbia edu]
TA: Victor Adan [vga2102 at columbia edu]
Our Motto: "Why and how."
syllabus | lectures




January 29

* What is an Algorithm presentations

* Processing basics

* does everyone have Processing installed and running?
* how about the Ess library?
* IDE basics
* play & stop
* load & save
* export: http://music.columbia.edu/cmc/courses/g6602/spring2008/jan.29/taco_truck_applet
* console printing:
    
    Anything printed with the print() or println() methods comes out in the console area under your code.
    Printing is very useful for debugging, testing out ideas, sanity checks, easter eggs, dumb jokes, etc.
    
    //print() keeps printing on the same line:
    
    for (int taco = 0; taco < 10; taco++)
    {
        print("taco number: " + taco + " ");
    }
    
    result:
    
    taco number: 0 taco number: 1 taco number: 2 taco number: 3 taco number: 4 taco number: 5 taco number: 6 taco number: 7 taco number: 8 taco number: 9 
    
    
    //println() prints a new line after each statement:
    
    for (int truck = 0; truck < 10; truck++)
    {
        println("truck number: " + truck);
    }   
    
    result:
    
    truck number: 0
    truck number: 1
    truck number: 2
    truck number: 3
    truck number: 4
    truck number: 5
    truck number: 6
    truck number: 7
    truck number: 8
    truck number: 9
    
* programming super fundamentals
* comments help you document your code and keep track of what you're trying to do. They come in one line // and multiline /* */ flavors:

    // this is where we compute number of tacos per truck
    int tacosPerTruck = numTacos/numTrucks;
    
    /*
        The Bad Brains encode secret Java programs in their album titles. 
        Examples include:
            I against I
            I & I Survive
    */    
    

    int i = 1;

    if (i != i)
        println("that's not possible!");
    else
        println("i is never against i.");
  
    int survive = i + i;
    println("survive: " + survive);
    
* All statements end with a semicolon. Whitespace is ignored, so this is valid code:
    int i = 
        1000;
    print(i);
    
* variables are declared by type
    boolean is 1 bit, value range: true or false
    byte is 8 bits, value range: -128 to 127
    char is 16 bits, value range: 0 to 65535
    int is 32 bits, value range: -2,147,483,648 to 2,147,483,647
    float is 32 bits, value range: -3.40282347E+38 to 3.40282347E+38
    color 32 bits, value range: 16,777,216 colors
    
    examples:
    
    boolean useMetronome = false;
    int numInstruments = 4;
    // pan setting is 0.0 = left, 1.0 = right, 0.5 = middle
    float pan = 0.5;
    // i can assign an int to a float, Processing will assume 1.0
    float volume = 1;
    print(volume);
    // i can NOT assign a float to an int
    int numPlayers = 4.5; ERROR!!!
    // i can assign variables to other variables. pan2 will equal 0.5
    float pan2 = pan;
    
    
* arithmetic is fun!
    int numMeasures = 100;
    int currMeasure = 0;
    
    currMeasure = currMeasure + 1;
    println("we're on measure number: " + currMeasure);
    
    currMeasure -= 1;
    println("we're on measure number: " + currMeasure);
    
    currMeasure = numMeasures/2;
    println("we're on measure number: " + currMeasure);
    
    currMeasure *= 5;
    println("we're on measure number: " + currMeasure);
    
    if (currMeasure > numMeasures)
        println("uh oh, too many measures!");
    
    int numFourBarPhrases = numMeasures / 4;
    println("number of four bar phrases: " + numFourBarPhrases);
    
    currMeasure = 7;
    //we add one since computers start counting at 0 but humans usually start at 1
    int curBarOfPhrase = (currMeasure % 4) + 1;
    println("we're on bar number " + curBarOfPhrase + " in this 4 bar phrase.");
    
    currMeasure = 0;
    println("we're on measure number: " + currMeasure);
    currMeasure++;
    println("we're on measure number: " + currMeasure);
    currMeasure++;
    println("we're on measure number: " + currMeasure);
    currMeasure--;
    println("we're on measure number: " + currMeasure); 
    
* relationships are simple
    
    float highestFreq = 15000.0;
    float currFreq = 1000.0;
    
    println("currFreq < highestFreq");
    println("currFreq > highestFreq");
    
    currFreq = 15000.0;
    println("currFreq <= highestFreq");
    println("currFreq >= highestFreq");
    //NOTE use of == for comparison instead of = for assignment!
    println("currFreq == highestFreq");
    println("currFreq != highestFreq");
    
    
* conditionals control flow
    float highestFreq = 15000.0;
    float currFreq = 2000.0;
    
    if (currFreq > highestFreq)
        println(currFreq + "Hz ?!? Now that's a high frequency!");
    else
        println(currFreq + "Hz? Eh, not so high.");
        
    currFreq = 1000.0;
    
    if (currFreq < highestFreq)
    {
        println("currFreq is too low! Let's jack it up!");
        //square it!
        currFreq *= currFreq;
    }
    
    //try again
    if (currFreq < highestFreq)
        println("I give up, frequency is still too low.");
    else
    {
        println(currFreq + "Hz is beyond the range of human hearing. Congratulations!");
        // make it even higher, just to be mean
        currFreq *= currFreq * currFreq;
        println("now we're up to: " + currFreq);
    }
    
    
* the mighty "for loop"
    
    //dumb 4/4 rock beat
    
    for (int beatNum = 0; beatNum < 4; beatNum++)
    {
        //bass on even beats
        if (beatNum % 2 == 0)
            println("bass");
        else
            println("snare");
    }
    

    
    
    //dumb rock beat that goes on for much too long
    
    int numMeasures = 100;
    
    for (int measureNum = 0; measureNum < numMeasures; measureNum++)
    {
      //we add one so that we start counting at one instead of zero
      println("measure: " + (measureNum + 1));
      
        //every eight bars we'll shake a shaker!
        if (measureNum % 8 == 0)
          print("shaker! ");
          
        for (int beatNum = 0; beatNum < 4; beatNum++)
        {
            //bass on even beats
            if (beatNum % 2 == 0)
                print("bass");
            else
                print("snare");
                
            println();
        }
    }


    
    
* wow, that was easy!

Assignment
write a small program that generates a text-based score. We will perform the scores in class on Tuesday.
Here's mine: bleep_bloop_score.pde
Due Thursday night. Send a link to me and Victor and we'll forward it to the class.

Reading
for Feb 5th: "What is generative art?" by Philip Galanter