Difference between revisions of "JucK Doc"

From CSWiki
Jump to: navigation, search
m (Writing a JucK File)
m (Writing a ChucK File)
Line 61: Line 61:
  
 
* Example 1: test.ck
 
* Example 1: test.ck
 +
** for each GUIelement to listen for, a new function must be created and sporked
  
 
  // create sin oscillator; set gain and reverb
 
  // create sin oscillator; set gain and reverb
Line 112: Line 113:
 
     }
 
     }
 
  }
 
  }
 
** for each GUIelement to listen for, a new function must be created and sporked
 
  
 
=IV. GUI Elements=
 
=IV. GUI Elements=
  
 
==
 
==

Revision as of 20:53, 22 May 2006

JucK

I. Introduction

  • JucK is a swing-based GUI creator for ChucK.
  • Currently supported GUI elements:
    • Slider
    • Checkbox
    • Radiobutton
    • Dropdown menu
    • Textfield
    • Two-Dimensional Checkbox
    • Two-Dimensional Grid
  • Planned Features
    • ChucK libraries to parse JucK messages

II. System Requirements

  • ChucK System Requirements
  • Java 1.4 or higher
    • Compilation: javac Juck.java
    • Execution: java Juck <file.jk>

III. Tutorial

Writing a JucK File

  • A .jk file has several required entries. In order:
    • [Name of the GUI to be created]
    • [Target of OSC message] [Port to send OSC messages out of]
    • [Layout]
      • panels: [number of rows] [number of columns]
      • manual: [width] [height]
    • elements (see IV. GUI Elements for specific parameters)


  • Example 1: testpanel.jk
    • This is a very simple GUI with only one element, a slider. The overall window is labelled "MidiSlider", as indicated by the first line. It sends OSC messages to localhost through port 6449. The layout is panels, and the next line defines the number of rows and columns to be created (in this case there is only one element, so only one row and one column is necessary). The next line contains the only element of the GUI - a slider with labele "Frequency" that ranges from 0 - 127; initialized to 0, ticks marked every 5 units; does NOT have to snap to ticks (false) ; oriented vertically.
MidiSlider
localhost 6449
panels
1 1
slider Frequency 0 127 0 5 false vertical
  • Example 2: testmanual.jk
    • Everything here is identical, except for the layout. Because manual layout is specified, the following line does not contain the number of rows and columns; rather, it defines the width and height of the overall window (can be resized). In this case, the line for the slider (and any element) must contain an additional two parameters at the end for JucK to decide where to place the slider in the window. In this case, the parameters (5, 5) dictate that the LEFTmost border of the slider be placed 5 units away from the LEFT border of the overall window, and that the TOPmost border of the slider be placed 5 units away from the TOP border of the overall window. A few other parameters have been changed as well: the ticks are marked every 3 units; the slider DOES have to snap to ticks (true); and the orientation is horizontal. In addition, I have specified a preferred size for the slider (width: 290, height: 40). These two final parameters are optional, and also work in the panels layout.
MidiSlider
localhost 6449
manual
400 100
slider Frequency 0 127 0 3 true horizontal 5 5  290 40

Writing a ChucK File

  • Code that must appear in a .ck file in order to receive messages from a .jk file (this will become much clearer with an example):
    • create OSC receiver
    • set port for receiver to receive from
    • have the receiver start listening
    • create an address for the receiver; store in a new variable
    • loop: pass time until an event occurs; process the event
  • Example 1: test.ck
    • for each GUIelement to listen for, a new function must be created and sporked
// create sin oscillator; set gain and reverb
sinosc s => JCRev r => dac;
.5 => s.gain;
.1 => r.mix;

// declare global variables (in this case, only int i to take midi values)
int i;

// spork functions (must be done in order to receive multiple events)
spork~ listenSlider();
 
// infinite event loop to pass time
while( true )
{
    0.05::second => now;
    i => std.mtof => s.freq;
}

// function to listen to test.jk
fun void listenSlider()
{
    // create our OSC receiver
    OscRecv recv;
    // use port 6449 to listen
    6449 => recv.port;
    // start listening (launch thread)
    recv.listen();
    // create an address in the receiver; store in new variable
    // the input is "/GUIname/element type/ element name, expected type"
    // expected types: i(int), s(string), f(float), b(boolean)
    recv.event( "/MidiSlider/Slider/Frequency, i" ) @=> OscEvent e;
	
    // listener loop
    while( true )
    {
    // wait for event to arrive
        e => now;

        // grab the next message from the queue. 
        while( e.nextMsg() )
        {         

            // getInt fetches the expected int (as indicated by "i")
            e.getInt() => i;
	
            // print
            <<< "got (via OSC):", i >>>;
        }
    }
}

IV. GUI Elements

==