-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chipfork
committed
Mar 8, 2010
1 parent
3fa2337
commit 940bee1
Showing
4 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
17 changes: 17 additions & 0 deletions
17
ofxSuperCollider/examples/ofSuperColliderExample/src/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "ofMain.h" | ||
#include "testApp.h" | ||
#include "ofAppGlutWindow.h" | ||
|
||
//======================================================================== | ||
|
||
int main() | ||
{ | ||
|
||
ofAppGlutWindow window; | ||
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); | ||
|
||
// this kicks off the running of my app | ||
// can be OF_WINDOW or OF_FULLSCREEN | ||
// pass in width and height too: | ||
ofRunApp( new testApp()); | ||
} |
147 changes: 147 additions & 0 deletions
147
ofxSuperCollider/examples/ofSuperColliderExample/src/testApp.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#include "testApp.h" | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::setup() | ||
{ | ||
//-------------------------------------------------------------- | ||
// Create a SuperCollider synth with default parameters | ||
// and spawn it on the server. | ||
//-------------------------------------------------------------- | ||
synth = new ofxSCSynth("sine_harmonic"); | ||
synth->create(); | ||
|
||
//-------------------------------------------------------------- | ||
// Load up a buffer with a sound file, and route its playback | ||
// to an fx unit via a 2-channel audio bus. | ||
//-------------------------------------------------------------- | ||
buffer = new ofxSCBuffer(); | ||
buffer->read(ofToDataPath("bell.aif", true)); | ||
|
||
bus = new ofxSCBus(2); | ||
|
||
playbuf = new ofxSCSynth("playbuf_1"); | ||
playbuf->set("bufnum", buffer->index); | ||
playbuf->set("outbus", bus->index); | ||
|
||
delay = new ofxSCSynth("fx_delay"); | ||
delay->set("wet", 0.4); | ||
delay->set("delaytime", 0.4); | ||
delay->set("decaytime", 4); | ||
delay->set("inbus", bus->index); | ||
delay->set("outbus", 0); | ||
delay->addToTail(); | ||
|
||
//-------------------------------------------------------------- | ||
// Drawing setup | ||
//-------------------------------------------------------------- | ||
ofBackground(0, 20, 50); | ||
ofSetBackgroundAuto(false); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::update() | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
testApp::~testApp() | ||
{ | ||
//-------------------------------------------------------------- | ||
// Free synths and buffers when we're done - otherwise | ||
// they'll hang about on SC server, occupying CPU and memory. | ||
//-------------------------------------------------------------- | ||
synth->free(); | ||
delay->free(); | ||
buffer->free(); | ||
bus->free(); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::draw() | ||
{ | ||
ofEnableAlphaBlending(); | ||
ofSetColor(0, 20, 50, 2); | ||
ofFill(); | ||
ofRect(0, 0, ofGetWidth(), ofGetHeight()); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::keyPressed(int key) | ||
{ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::keyReleased(int key) | ||
{ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::mouseMoved(int x, int y ) | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::mouseDragged(int x, int y, int button) | ||
{ | ||
//-------------------------------------------------------------- | ||
// Modulate synth params based on mouse position. | ||
//-------------------------------------------------------------- | ||
|
||
if (button == 0) | ||
{ | ||
synth->set("freq", x + 40); | ||
synth->set("amp", 1.0f - (float) y / ofGetHeight()); | ||
synth->set("pan", (float) x / ofGetHeight() - 0.5f); | ||
|
||
ofSetColor(255, 255, 255, 100); | ||
ofCircle(x, y, 10 * (1.0 - (float) y / ofGetHeight())); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::mousePressed(int x, int y, int button) | ||
{ | ||
//-------------------------------------------------------------- | ||
// Trigger stuff. Press right mouse button for bells. | ||
//-------------------------------------------------------------- | ||
|
||
if (button == 0) | ||
{ | ||
this->mouseDragged(x, y, button); | ||
synth->set("amp", 0.8f); | ||
} | ||
else if (button == 2) | ||
{ | ||
playbuf->set("rate", 2.0f * x / ofGetWidth()); | ||
playbuf->grain(); | ||
|
||
ofSetColor(255, 255, 0, 200); | ||
ofTriangle(x, y - 10, x + 10, y + 10, x - 10, y + 10); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::mouseReleased(int x, int y, int button) | ||
{ | ||
synth->set("amp", 0.1f); | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
|
||
void testApp::windowResized(int w, int h) | ||
{ | ||
|
||
} | ||
|
81 changes: 81 additions & 0 deletions
81
ofxSuperCollider/examples/ofSuperColliderExample/src/testApp.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#ifndef _TEST_APP | ||
#define _TEST_APP | ||
|
||
|
||
#include "ofMain.h" | ||
#include "ofxSuperCollider.h" | ||
|
||
/*------------------------------------------------------------------------------ | ||
* The below SynthDefs must be loaded into SuperCollider before execution. | ||
* copy+paste the lot and hit enter... | ||
*------------------------------------------------------------------------------ | ||
SynthDef(\fx_comb, { |inbus = 0, outbus = 0, wet = 0.5, delaytime = 0.1, decaytime = 1.0, fade = 0.5| | ||
var in, out; | ||
in = In.ar(inbus, 2); | ||
out = CombN.ar(in, 2.0, delaytime, decaytime); | ||
out = (wet * out) + ((1 - wet) * in); | ||
Out.ar(outbus, out); | ||
}).store; | ||
SynthDef(\sine_harmonic, { |outbus = 0, freq = 200, amp = 0.1, gate = 1, pan = 0| | ||
var data, env; | ||
amp = Lag.kr(amp, 0.4); | ||
// generate, degrade, filter, echo | ||
data = SinOsc.ar(freq, 0, amp); | ||
data = Latch.ar(data, Impulse.ar(Rand(1000, 35000))); | ||
data = LPF.ar(data, 1000); | ||
data = Pan2.ar(data, pan); | ||
data = data + CombN.ar(data, 0.5, 0.3, 15.0, 0.3); | ||
// envelope | ||
env = EnvGen.kr(Env.asr(0.5, 1.0, 1.0), gate: gate, doneAction: 2); | ||
data = data * env; | ||
data = [ data[0], data[1] * Select.kr(IRand(0, 3), [ 1, 1, -1 ]) ]; | ||
Out.ar(outbus, data); | ||
}).store; | ||
SynthDef(\playbuf_1, { |bufnum = 0, outbus = 0, amp = 0.5, loop = 0, pan = 0, rate = 1.0| | ||
var data; | ||
data = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * rate, 0, 0, loop); | ||
FreeSelfWhenDone.kr(data); | ||
Out.ar(outbus, Pan2.ar(data, pan, amp)); | ||
}).store; | ||
*--------------------------------------------------------------------------------*/ | ||
|
||
class testApp : public ofBaseApp | ||
{ | ||
|
||
public: | ||
~testApp(); | ||
void setup(); | ||
void update(); | ||
void draw(); | ||
void stop(); | ||
|
||
void keyPressed (int key); | ||
void keyReleased(int key); | ||
void mouseMoved(int x, int y ); | ||
void mouseDragged(int x, int y, int button); | ||
void mousePressed(int x, int y, int button); | ||
void mouseReleased(int x, int y, int button); | ||
void windowResized(int w, int h); | ||
|
||
ofxSCSynth *synth; | ||
|
||
ofxSCSynth *playbuf; | ||
ofxSCBus *bus; | ||
ofxSCSynth *delay; | ||
ofxSCBuffer *buffer; | ||
|
||
}; | ||
|
||
#endif |