sourcecode:
octomodulate_09.ck

TouchOSC template:
octomodulate_09.touchosc

most of these features have made their way into the latest version of meeq.


// =========================================================================================
// Name:        octomodulate; eight low frequency oscillators for Greg Surges' USB-Octomod
// Version:     v0.9
// Date:        January 16th 2011
// Author:      Graham Morrison
// Email:       graham@paldandy.com
// Web:         http://www.paldandy.com
// Licence:     GPLv3; http://www.gnu.org/licenses
//
// Description: 8 independent LFOs with TouchOSC control
// Features:    2x Sine, Square, Saw and Triangle waveforms. Individual control of each LFO
//              and visual feedback to TouchOSC. A latency slider is used to adjust the 
//				update frequency of values back to USB-Octomod. 
// =========================================================================================

// Default values for oscillators - starting value and freq (Hz)
0 => int glfo1;		
0.5 => float glfo1_f;

0 => int glfo2;
0.5 => float glfo2_f;

512 => int glfo3;
0.5 => float glfo3_f;

512 => int glfo4;
0.5 => float glfo4_f;

512 => int glfo5;
0.5 => float glfo5_f;

512 => int glfo6;
0.5 => float glfo6_f;

0 => int glfo7;
0.5 => float glfo7_f;

0 => int glfo8;
0.5 => float glfo8_f;

/// Global latency/update period
10 => int glat;

// Octomod - Send
"localhost" => string host;
9999 => int hostport;				/// CHANGE FOR YOUR SETUP: Octomod OSC Port
"/dac" => string prefix;
OscSend oemit; 
oemit.setHost(host, hostport);

// TouchOSC - Receive
8001 => int tosc_rp;				/// CHANGE FOR YOUR SETUP: TouchOSC OSC receive
OscRecv tosc_r; 
tosc_rp => tosc_r.port; 
tosc_r.listen();
tosc_r.event("/1/rotary1", ",f") @=> OscEvent rotary1;
tosc_r.event("/1/rotary2", ",f") @=> OscEvent rotary2;
tosc_r.event("/1/rotary3", ",f") @=> OscEvent rotary3;
tosc_r.event("/1/rotary4", ",f") @=> OscEvent rotary4;
tosc_r.event("/1/rotary5", ",f") @=> OscEvent rotary5;
tosc_r.event("/1/rotary6", ",f") @=> OscEvent rotary6;
tosc_r.event("/1/rotary7", ",f") @=> OscEvent rotary7;
tosc_r.event("/1/rotary8", ",f") @=> OscEvent rotary8;
tosc_r.event("/1/latency", ",f") @=> OscEvent latency;

// TouchOSC - Send
8002 => int toport;					/// CHANGE FOR YOUR SETUP: TouchOSC OSC send
"192.168.1.94" => string tohost;	/// CHANGE FOR YOUR SETUP: TouchOSC IP address
OscSend toemit;
toemit.setHost(tohost, toport);

/// free-running oscillators
spork ~lfo1();
spork ~lfo2();
spork ~lfo3();
spork ~lfo4();
spork ~lfo5();
spork ~lfo6();
spork ~lfo7();
spork ~lfo8();

/// functions that use input from TouchOSC 
spork ~toInput1();
spork ~toInput2();
spork ~toInput3();
spork ~toInput4();
spork ~toInput5();
spork ~toInput6();
spork ~toInput7();
spork ~toInput8();

spork ~toUpdate();
spork ~toLatency();

while (true){

		octSend(glfo8,glfo7,glfo6,glfo5,glfo4,glfo3,glfo2,glfo1);
		glat::ms => now; // Octomod update frequency	
}

///Sine 1
fun int lfo1(){
	
	while (true){

		for (0=> int i; i<900; i++){
		
			((Math.sin ((i/10)*3.14159265/180)) * 512 + 512-1) $ int => glfo1;
			1/glfo1_f => float div_click;
			div_click*0.27777777::ms => now;
		}
	
		for (900=> int i; i>0; i--){
		
			((Math.sin ((i/10)*3.14159265/180)) * 512 + 512-1) $ int => glfo1;
			1/glfo1_f => float div_click;
			div_click*0.27777777::ms => now;
		}
		
		for (0=> int i; i<900; i++){
		
			((Math.sin ((i/10)* -3.14159265/180)) * 512 + 512) $ int => glfo1;
			1/glfo1_f => float div_click;
			div_click*0.27777777::ms => now;
		}
		
		for (900=> int i; i>0; i--){
		
			((Math.sin ((i/10)* -3.14159265/180)) * 512 + 512) $ int => glfo1;
			1/glfo1_f => float div_click;
			div_click*0.27777777::ms => now;
			//((1/glfo1_f)/4)::second => now;
		}

	}
	
	
}

/// Sine 2
fun int lfo2(){
	
	while (true){
	
		for (0=> int i; i<900; i++){
		
			((Math.sin ((i/10)*3.14159265/180)) * 512 + 512-1) $ int => glfo2;
			1/glfo2_f => float div_click;
			div_click*0.27777777::ms => now;
		}
	
		for (900=> int i; i>0; i--){
		
			((Math.sin ((i/10)*3.14159265/180)) * 512 + 512-1) $ int => glfo2;
			1/glfo2_f => float div_click;
			div_click*0.27777777::ms => now;
		}
		
		for (0=> int i; i<900; i++){
		
			((Math.sin ((i/10)* -3.14159265/180)) * 512 + 512) $ int => glfo2;
			1/glfo2_f => float div_click;
			div_click*0.27777777::ms => now;
		}
		
		for (900=> int i; i>0; i--){
		
			((Math.sin ((i/10)* -3.14159265/180)) * 512 + 512) $ int => glfo2;
			1/glfo2_f => float div_click;
			div_click*0.27777777::ms => now;
			//((1/glfo1_f)/4)::second => now;
		}


	}	
}

/// Triangle 1
fun int lfo3(){
	
	1 => int direction;
	
	while (true){
	
		if (direction){
			
			if (glfo3 < 1023){
				glfo3 + 1 => glfo3;
			} else {
				0 => direction;			
			}
		} else {
			if (glfo3 > 0){
				glfo3 - 1 => glfo3;
			} else {
				1 => direction;
				
			}			
		}
	
	1/glfo3_f => float div_click;
	div_click * 0.48828125::ms => now;
	}
}

/// Triangle 2
fun int lfo4(){
	
	1 => int direction;
	
	while (true){
	
		if (direction){
			
			if (glfo4 < 1023){
				glfo4 + 1 => glfo4;
			} else {
				0 => direction;			
			}
		} else {
			if (glfo4 > 0){
				glfo4 - 1 => glfo4;
			} else {
				1 => direction;
				
			}			
		}
	
	1/glfo4_f => float div_click;
	div_click * 0.48828125::ms => now;
	}
}

/// Sawtooth 1
fun int lfo5(){
		
	while (true){
	
		if (glfo5 < 1023){
			glfo5 + 1 => glfo5;
		} else {
			0 => glfo5;			
		}
		
	1/glfo5_f => float div_click;
	div_click * 0.9765625::ms => now;
	}
}

/// Sawtooth 2
fun int lfo6(){
		
	while (true){
	
		if (glfo6 < 1023){
			glfo6 + 1 => glfo6;
		} else {
			0 => glfo6;			
		}
		
	1/glfo6_f => float div_click;
	div_click * 0.9765625::ms => now;
	}
}

/// Square 1
fun int lfo7(){
	
	1 => int direction;
		
	while (true){
	
		if (direction > 2000){
			1 => direction;
		}
	
		if (direction < 1000){
			1023 => glfo7;
			
		} else {
			0 => glfo7;			
		}
		
		direction + 1 => direction;
		
		1/glfo7_f => float div_click;
		div_click * 0.5::ms => now;
	}
}

/// Square 2
fun int lfo8(){
		
	1 => int direction;
		
	while (true){
	
		if (direction > 2000){
			1 => direction;
		}
	
		if (direction < 1000){
			1023 => glfo8;
			
		} else {
			0 => glfo8;			
		}
		
		direction + 1 => direction;
		
		1/glfo8_f => float div_click;
		div_click * 0.5::ms => now;
	}
}

fun void toLatency() {
    
  while (true){

    latency => now;

    	while ( latency.nextMsg() != 0 ){
			(Math.pow (latency.getFloat(), 1.2) + 8) $ int => glat;
			//<<< "Latency ", glat >>>;
       	}

  }

}

fun void toInput1() {
    
  while (true){

    rotary1 => now;

    	while ( rotary1.nextMsg() != 0 ){ 

		//<<< "TouchOSC Input 1", rotary1.getFloat() >>>;
		Math.pow (rotary1.getFloat() /25, 2)+0.001 => glfo1_f;
       	}

  		}
}

fun void toInput2() {
    
  while (true){

    rotary2 => now;

    	while ( rotary2.nextMsg() != 0 ){ 

		Math.pow (rotary2.getFloat() /25, 2)+0.001 => glfo2_f;
       	}

  		}
}

fun void toInput3() {
    
  while (true){

    rotary3 => now;

    	while ( rotary3.nextMsg() != 0 ){ 

		Math.pow (rotary3.getFloat() /25, 2)+0.001  => glfo3_f;
       	}

  		}
}

fun void toInput4() {
    
  while (true){

    rotary4 => now;

    	while ( rotary4.nextMsg() != 0 ){ 
			Math.pow (rotary4.getFloat() /25, 2)+0.001  => glfo4_f;
       	}

  }
}

fun void toInput5() {
    
  while (true){

    rotary5 => now;

    	while ( rotary5.nextMsg() != 0 ){ 
			Math.pow (rotary5.getFloat() /25, 2)+0.001  => glfo5_f;
       	}

  }
}

fun void toInput6() {
    
  while (true){

    rotary6 => now;

    	while ( rotary6.nextMsg() != 0 ){ 
			Math.pow (rotary6.getFloat() /25, 2)+0.001  => glfo6_f;
       	}

  }
}

fun void toInput7() {
    
  while (true){

    rotary7 => now;

    	while ( rotary7.nextMsg() != 0 ){ 
			Math.pow (rotary7.getFloat() /25, 2)+0.001  => glfo7_f;
       	}

  }
}

fun void toInput8() {
    
  while (true){

    rotary8 => now;

    	while ( rotary8.nextMsg() != 0 ){ 
			Math.pow (rotary8.getFloat() /25, 2)+0.001  => glfo8_f;
       	}

  }
}

fun void octSend(int oa, int ob, int oc, int od, int oe, int of, int og, int oh){
	
	oemit.startMsg(prefix, "iiiiiiii");
	
	oa => oemit.addInt;
    ob => oemit.addInt;
    oc => oemit.addInt;
	od => oemit.addInt;
    oe => oemit.addInt;
    of => oemit.addInt;
	og => oemit.addInt;
	oh => oemit.addInt;

}

fun void toUpdate(){
	
	while (true){
	
		toemit.startMsg("/1/fader1", "f");
		glfo1/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader2", "f");
		glfo2/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader3", "f");
		glfo3/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader4", "f");
		glfo4/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader5", "f");
		glfo5/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader6", "f");
		glfo6/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader7", "f");
		glfo7/10 => toemit.addFloat;
		
		toemit.startMsg("/1/fader8", "f");
		glfo8/10 => toemit.addFloat;
		
		50::ms => now; // TouchOSC update frequency
	}
}

Leave a Reply

*

*