CSL
5.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Test_OSC_Client.cpp
Go to the documentation of this file.
1
//
2
// Test_OSC_CLIENT.cpp -- main() function for stand-alone OSC client that sends messages
3
// to the CSL OSC server in TEST_Control.cpp
4
// The server's OSC "play note" cmd is:
5
// /iX/pn, "ffff", dur ampl freq pos for X = 1...16
6
//
7
// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
8
//
9
// compile this like: g++ -w -I../Includes TEST_OSC_Client.cpp ../Kernel/CGestalt.cpp -o osc_client -llo
10
// (See the Makefile)
11
//
12
13
#include "
CSL_Core.h
"
// the core of CSL 5
14
#include "
lo/lo.h
"
// liblo for OSC
15
16
#define NUM_NOTES 100 // # notes to play
17
18
using namespace
csl;
19
20
void
noteLoop
(
lo_address
& ad);
// fcn protptype
21
22
// Main fcn sends out NUM_NOTES OSC messages to localhost port CGestalt::outPort()
23
24
int
main
(
int
argc,
char
** Argv) {
25
char
pNam[
CSL_WORD_LEN
];
// string for port number
26
27
sprintf(pNam,
"%d"
,
CGestalt::outPort
());
28
lo_address
ad =
lo_address_new
(NULL, pNam);
// set up a port to write to the server thread
29
30
logMsg
(
"Sending OSC note cmds"
);
31
noteLoop
(ad);
// call note loop fcn
32
33
sleepSec
(3);
// let the reverb dieout
34
35
logMsg
(
"Sending OSC quit"
);
36
37
if
(
lo_send
(ad,
"/q"
, NULL) == -1) {
38
logMsg
(
kLogError
,
"OSC error3 %d: %s\n"
,
lo_address_errno
(ad),
lo_address_errstr
(ad));
39
}
40
}
41
42
// note player fcn - play pentatonic pitches
43
44
void
noteLoop
(
lo_address
& ad) {
45
int
steps[5] = { 0, 2, 5, 7, 9 };
// scale steps for pentatonic scale
46
char
pNam[
CSL_WORD_LEN
];
// string for port number
47
for
(
unsigned
i = 0; i <
NUM_NOTES
; i++) {
// note loop
48
sprintf(pNam,
"/i%d/pn"
, (i % 16) + 1);
// OSC cmd: /iX/pn, "ffff", dur ampl freq pos
49
float
dur =
fRandM
(0.15f, 1.5f);
// duration range
50
float
ampl =
fRandM
(0.1, 0.6);
// amplitude range
51
int
octave =
iRandM
(2, 9);
// rand octave
52
int
step = steps[
iRandV
(5)];
// rand scale step
53
int
key = (octave * 12) + step;
// pick a pentatonic note to play
54
float
freq =
keyToFreq
(key);
// frequency range
55
float
pos =
fRand1
();
// random stereo position
56
// now send OSC
57
if
(
lo_send
(ad, pNam,
"ffff"
, dur, ampl, freq, pos) == -1)
58
logMsg
(
kLogError
,
"OSC error2 %d: %s\n"
,
lo_address_errno
(ad),
lo_address_errstr
(ad));
59
60
sleepSec
(
fRandM
(0.05, 0.25));
// sleep a bit
61
}
// end note loop
62
}
63
64
// note player fcn - play stuttered drum samples
65
66
//void noteLoop() {
67
// char pNam[CSL_WORD_LEN]; // string for port number
68
// for (unsigned i = 0; i < NUM_NOTES; i++) { // note loop
69
// int numN = iRandM(3, 10); // pick # notes to play
70
// int pit1 = iRandM(30, 84); // pick start pitch (in MIDI)
71
// int pitX = iRandM(1, 4); // pick pitch step
72
// if (coin()) // pick step up or down
73
// pitX = 0 - pitX;
74
// float pos1 = fRandZ(); // pick starting pos (0 - 1)
75
// if (pos1 == 0)
76
// pos1 = 0.1;
77
// pos1 = sqrtf(pos1); // sqrt of starting pos (moves it away from 0)
78
// if (coin()) // pick pos L or R
79
// pos1 = 0.0f - pos1;
80
// float posX = (pos1 > 0) // calc pan step
81
// ? ((0.0f - ((pos1 + 1.0f) / (float)numN)))
82
// : ((1.0f - pos1) / (float)numN);
83
// float dela = fRandM(0.08, 0.25); // calc delay
84
// logMsg("n: %d p: %d/%d \tx: %5.2f/%5.2f \td:%5.2f", numN, pit1, pitX, pos1, posX, dela);
85
// // note loop
86
// for (int i = 0; i < numN; i++) { // loop to create string gliss
87
//// logMsg("\t\ts: %d p: %d x: %5.2f", cnt, pit1, pos1);
88
// // set freq to MIDI pitch
89
// ((KarplusString *)strings[cnt])->setFrequency(keyToFreq(pit1));
90
// pit1 += pitX;
91
// // set pan
92
// ((Panner *)pans[cnt])->setPosition(pos1);
93
// pos1 += posX;
94
// // trigger
95
// ((KarplusString *)strings[cnt])->trigger();
96
// if (sleepSec(dela)) // sleep
97
// return; // exit if sleep was interrupted
98
// cnt++; // pick next string
99
// if (cnt == numStrings) // should I check ifthe string is still active?
100
// cnt = 0; // reset string counter
101
// }
102
// sleepSec(fRandM(0.02, 0.2)); // sleep a bit between sets
103
// }
104
//}
105
CSL
Tests
OSC
Test_OSC_Client.cpp
Generated on Thu Nov 15 2012 22:01:10 for CSL by
1.8.1.1