Documentation Electric WS 12.13 Soeren Wellhoefer
Transcript of Documentation Electric WS 12.13 Soeren Wellhoefer
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
1/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
Eclectic Electric! Final Project WS 12/13
Documentation
An OSC-enabled (Open-Sound-Control) foot-switch
with the Arduino Uno
Table of Contents:
1. Introduction
2. Software
2.1 OSC and OSC alications
2.2 OSC message rela!
2." #oot$switch oerational logic
". %ardware
&. Conclusion and e'tenda(ilit!
). *endi' *+ Source code oscrelay.c
. *endi' -+ Source code oscfootswitch.ino
1. Introduction
I am an electric guitar la!er and as a guitar la!er one would like to control a num(er of things
while la!ing or in (etween la!ing guitar. ust consider the huge amount of settings and no(s on a
guitar amlifier that !ou could choose from, for e'amle.
#or controlling some things, !ou do not like to mo0e !our fingers awa! from the guitar and sta! in
the flow of whate0er !ou are la!ing right now. *nd this is wh! eole came u with foot$switches
in general.
*s a musician, who also writes eseciall! iff$(ased music, I also ha0e other things I would like to
1/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
2/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
easil! control in order to suort m! creati0e rocess. I usuall! ractice and write with a
metronome in the (ackground and I do not like changing metronome seed during a song as it
re3uires utting the guitar aside.
While writing iff$(ased , I usuall! come u with a rudimentar! melod! line first, record it, loo ito0er and o0er again and tr! to harmoni4e it then I do this again and again until I5m satisfied with
the result. I do this recording with m! 6inu'$(ased 7*W 87igital$*udio$Workstation9 called
Arour 2which is 0er! oular and somewhat semi$rofessional. *s a 0irtual metronome I use
"t#lic# which is the grahical front$end to #lic#. :lick itself is an ad0anced 6inu' and console$
(ased metronome.
*s the dri0ing audio engine in the (ackground I use *C:$*udio with a real$time ena(led 6inu'
kernel. Sometimes I will use"uitari$ a 0irtual 6inu' tu(e guitar amlifier,when I5m on the road
and don5t ha0e m! real guitar amlifier around.
M! goal with this ro;ect was to make the entire tedious rocess of recording, looing, changing
metronome seed, recording new riffs, etc. smoother and easier, eseciall! without ha0ing to lift m!
fingers awa! from the guitar. ut in lain terms, OSC 8Oen$Sound$Control9 is the more ad0anced successor of MI7I when it
comes to the controlling and intercommunication of modern *udio$alications. It has a rotocol
stack (ased on and the ?7> rotocol, and uses it to send and recei0e messages. It remo0es
man! of the restrictions of MI7I, is cleaner and eseciall! much more t!e$safe for arameters
assings and sometimes e0en faster.
#rom Wikiedia+
Open Sound Control%&S'( is a content format for messa"in" amon" com)uters soun
synthesi*ers an other multimeia e+ices that are o)timi*e for moern networ#in" technolo"y.
,rin"in" the -enefits of moern networ#in" technolo"y to the worl of electronic musical
instruments &S's a+anta"es inclue intero)era-ility accuracy fle$i-ility an enhance
or"ani*ation an ocumentation.
Most of *rdour5s functionalit! is accessi(le through OSC, so are those of klick. #or e'amle !oucan send *rdour the following OSC messages on ort "1@A
Same as hitting la! (utton+ /ardour/transport_play
Changing the la!(ack seed+ /ardour/set_transport_speed [transport_speed]
* list of ossi(le OSC aths 8commands9 for *rdour and klick can (e found here, resecti0el!+
htts+//communit!.ardour.org/oscBcontrol
/usr/share/doc/klick/manual.htmlosc 8Deeds klick installed, no online documentation9
I wanted to get m! *rduino to send the right OSC$messages to *rdour and klick when I ress
certain (uttons which will (e arranged as foot$switches. M! software$related tasks now where the
2/2
https://community.ardour.org/osc_controlhttps://community.ardour.org/osc_control -
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
3/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
following+
1. #inding out which OSC$aths and/or OSC$ath com(inations would result in the
actions I needed for what I wanted
2. Eetting somehow OSC messages out of the *rduino using its serial connection". Writing the logic of the *rduino and the OSC message generation itself
. OSC !essa"e rela#
In order to get the *rduino talking to OSC$ena(led alications o0er the serial ort I first had to
write a con0erter or rela!.
#or this I wrote a C$rogram called oscrelay.c that listens on the serial ort for messages in a format
that I defined, generates roer OSC$messages and sends them o0er ?7> to the right alication
and ort. In its (ackend this alication uses li-lo an oen$source imlementation of the OSC$
rotocol stack.
In0oking ./oscrelay0
Usage: ./oscrelay -s -o .. -o The ordering of `-o' is important
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
4/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
.$ %oot-switch operational lo"ic
#or the *rduino ?no, I wrote a rogram called oscfootswitch.ino whose source code !ou will find
attached also.
What it (asicall! does is generate the right OSC messages or OSC message chains on certain (utton
resses in order to achie0e the desired state changes in the software it ultimatel! controls.
It contains (uttonBressed and a (uttonBreleased handler functions resecti0el!, as well as (utton
de(ouncing routines.
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
5/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
Fou can see that the tracks *udio 1 and *udio 2 contain guitar recordings as regions resecti0el!.
#or me a guitar track is ;ust a collection of riffs and thus musical ideas, ossi(l! all (elonging to a
song that this *rdour session has (een created for.
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
6/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
#rom right to left in the icture a(o0e the (uttons are la(eled as follows 8the la(eling is under the
(uttons and alas onl! (adl! 0isi(le in the icture9+
S' * S' - +T,O +A, ,C OO' T,AC ,I%%/ ,I%%0
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
7/20
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
8/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
llustration =0 5ere is a )icture of solerin" the )ush9-utton connections on the -ac# while
-uilin" the foot9switch
3. Conclusion and e2tendabilit#
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
9/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
%
&
1'
11
1213
14
15
16
17
1%
1&
2'
21
22
23
24
25
26
27
2%
2&
3'
31
32
33
34
35
36
37
3%
3&
4'
41
42
43
44
45
46
47
4%
4&
5'51
52
53
54
55
56
57
5%
5&
6'
61
62
63
*/
(include )stdio#
(include )stdli+#
(include )stdint#(include )termios#
(include )unistd#
(include )string#
(include ),cntl#
(include )lo/lo#
(include )errno#
(de,ine -.0 -&6''
(de,ine .OSCSRR 1'
(de,ine ..RS 5
intserialinitconstchar*port89
intserialreadint,d: char*+u,89
voidusagechar*progname8 ;
print,
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
10/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
64
65
66
67
6%6&
7'
71
72
73
74
75
76
77
7%
7&
%'
%1
%2
%3
%4
%5
%6
%7
%%
%&
&'
&1
&2
&3
&4
&5
&6
&7
&%
&&
1''
1'1
1'2
1'3
1'4
1'5
1'61'7
1'%
1'&
11'
111
112
113
114
115
116
117
11%
11&
switch*MMargvFiG8 ;
caseAsA"
serialport argvFiM1G9
!rea"9 caseAoA"
oscsFHG loaddressne!>LL: argvFiM1G89
HMM9
!rea"9
B
B
B
serial,d serialinitserialport89
iserial,d )08 ;
eIitJ?K.JLR89
B
/* ain loop */
or998 ;
+Neroread+u,: si#eoread+u,889
iserialreadserial,d: read+u,8 )08 ;
eIitJ?K.JLR89
B
i+u,ptr strcrread+u,: A"A888 ;
looscmsg lomessagene!89
*+u,ptrMMA'A9
oscrecid atoiread+u,89
oscpat +u,ptr9
/* Parse osc message arguments i, any */
char*argstart9
iargstart strcr+u,ptr: A A888 ;
char*arglistF..RSG9 inti 09
whi$e+u,ptr strrcr+u,ptr: A A888 ;
*+u,ptr A'A9
arglistFiMMG MM+u,ptr9
+u,ptr argstart9
B
or i$$9 i 09 i$$8 ;
chartype *arglistFiG: *argument arglistFiGM29
switchtype8 ;
/* String */
1/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
11/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
12'
121
122
123
124125
126
127
12%
12&
13'
131
132
133
134
135
136
137
13%
13&
14'
141
142
143
144
145
146
147
14%
14&
15'
151
152
153
154
155
156
157
15%
15&
16'
161
162163
164
165
166
167
16%
16&
17'
171
172
173
174
175
caseAsA"
lomessageaddstringlooscmsg: argument89
!rea"9
/* Jnteger */
caseAiA" caseA,A"
lomessageaddint32looscmsg:
uint32_t8atoiargument889
!rea"9
B
B
B
(i,de, 0-
print,
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
12/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
176
177
17%
17&1%'
1%1
1%2
1%3
1%4
1%5
1%6
1%7
1%%
1%&
1&'
1&1
1&2
1&3
1&4
1&5
1&6
1&7
1&%
1&&
2''
2'1
2'2
2'3
2'4
2'5
2'6
2'7
2'%
2'&
21'
211
212
213
214
215
216
21721%
21&
22'
221
222
223
io#cc,lag DTP.R>-9
io#cc,lag DTCS?OP-9
io#cc,lag DTCSJU9
io#cc,lag ECS%9
io#cc,lag DTCR?SC?S9 io#cc,lag ECR.0 ECLOC.L9
io#ci,lag DTJO> EJOKK EJ.>89
io#cl,lag DTJC.>O> ECQO ECQO EJSJ89
io#co,lag DTOPOS?9
io#cccFJ>G 09
io#cccF?JG 209
itcsetattr,d: ?CS.>O: Dio8 )08 ;
perror
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
13/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
1
2
3
4
5
6
7
%
&
1'
11
12
13
14
15
16
17
1%
1&
2'
21
22
23
24
25
26
27
2%
2&3'
31
32
33
34
35
36
37
3%
3&
4'
41
4243
44
45
46
47
4%
4&
5'
51
52
53
54
55
/*
Simple ,oot s!itc tat generates OSC Open Sound Control8 messages
,or te 0.
Iamples"
'"/ardour/routes/recena+le ,"2 ,"'
'"/ardour/accessaction s"ditor/playead$to$previous$region$+oundary$noselection
1"/XlicX/metro/start
*/
/* Jmportant value de,initions */
(de,ine >OK0.?R.CYS 2
(de,ine KJRS??R.CYJ0 3
(de,ine 0K.L??ROSP0 1''
(de,ine ?ROJ>C0CS?PS 5
(de,ine SRJ.L-.0 &6''
(de,ine -??O>0-O>C.J??J 5' //ms
/* Pin declarations */
(de,ine -??O>>ROK-??O>S 11
(de,ine -??O>S?.R?PJ> 1
// 0.(de,ine -??O>RRCOR0PJ> -??O>S?.R?PJ>
(de,ine -??O>PL.PJ> -??O>S?.R?PJ>M18
(de,ine -??O>RJKK-.CYPJ> -??O>S?.R?PJ>M28
(de,ine -??O>RJKKK0PJ> -??O>S?.R?PJ>M38
(de,ine -??O>?R.CYSLC?PJ> -??O>S?.R?PJ>M48
(de,ine -??O>.00.RYRPJ> -??O>S?.R?PJ>M58
//etro
(de,ine -??O>?ROO>OKKPJ> -??O>S?.R?PJ>M68
(de,ine -??O>?ROSP00CPJ> -??O>S?.R?PJ>M78
(de,ine -??O>?ROSP0J>CPJ> -??O>S?.R?PJ>M%8
(de,ine PO?J?ROOL .'
//eneral
(de,ine -??O>RCOR0J>O0 -??O>S?.R?PJ>M&8//L0s
(de,ine L0RCOR0J> 12
(de,ine L0?R.CYSLC? 13 // so!s !ic o, t!o tracXs is selected ,or recording
/* OSC server pats */
// 0igitial .udio orXstation
(de,ine OSC0.PL. '
(de,ine OSC0.S?OP 1
(de,ine OSC0..C?JO> 2
(de,ine OSC0.RC>-L 3
(de,ine OSC0..RYR 4
(de,ine OSC0.LOOP 5
(de,ine OSC0.>0O 6
1"/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
14/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
56
57
5%
5&
6'61
62
63
64
65
66
67
6%
6&
7'
71
72
73
74
75
76
77
7%
7&
%'
%1
%2
%3
%4
%5
%6
%7
%%
%&
&'
&1
&2
&3
&4
&5
&6
&7
&%&&
1''
1'1
1'2
1'3
1'4
1'5
1'6
1'7
1'%
1'&
11'
111
(de,ine OSC0.R0O 7
(de,ine OSC0.P.R.-.CY '
(de,ine OSC0.P.R.>? 1
(de,ine OSC0.P.R.RCOR0 2
(de,ine OSC0.P.R.S?LOOP 3(de,ine OSC0.P.R.SLC?.LL 4
(de,ine OSC0.P.R.J>R? 5
+yte da!id 09
constchar*da!
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
15/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
112
113
114
115
116117
11%
11&
12'
121
122
123
124
125
126
127
12%
12&
13'
131
132
133
134
135
136
137
13%
13&
14'
141
142
143
144
145
146
147
14%
14&
15'
151
152
153
154155
156
157
15%
15&
16'
161
162
163
164
165
166
167
/* OSC message +u,,er */
charmsg+u,F128G9
/* Prototypes */voidgenoscmessagechar*msg: +yte id: constchar*name: constchar*pat: constchar*args: ###89
voidsendoscconstchar*msg89
voidstoprecording89
voidandle+uttonpress+yte +uttonnr89
voidandle+uttonrelease+yte +uttonnr89
/* ain ,unctions */
voidsetup8 ;
Serial#+eginSRJ.L-.089
or+yte i -??O>S?.R?PJ>9 i )-??O>S?.R?PJ> M-??O>>ROK-??O>S 9 iMM8 ;
pinodei: J>P?PLLP89
B
pinodeL0RCOR0J>: O?P?89
pinodeL0?R.CYSLC?: O?P?89
or+yte i 09 i )-??O>>ROK-??O>S9 iMM8 ;
+uttonstates E1))i89
+uttonpresstimesFiG 09
B
real+uttonstates +uttonstates9
previousreal+uttonstates +uttonstates9
B
void$oop8 ;
// Read +uttons
or+yte i 09 i )-??O>>ROK-??O>S9 iMM8 ;
int+uttonstate digitalReadiM-??O>S?.R?PJ>89
uint16_t+uttonstate+itmasX 1))i89
// -utton value canged i+uttonstate))i V+uttonstates D+uttonstate+itmasX88 ;
i+uttonstate8 ;
+uttonstates E+uttonstate+itmasX9
B e$se;
+uttonstates DT+uttonstate+itmasX9
B
+uttonpresstimesFiG millis89
B
// -utton de+ounce
imillis8 $+uttonpresstimesFiG8 +uttonpress!aittime8 ;
1)/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
16/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
16%
16&
17'
171
172173
174
175
176
177
17%
17&
1%'
1%1
1%2
1%3
1%4
1%5
1%6
1%7
1%%
1%&
1&'
1&1
1&2
1&3
1&4
1&5
1&6
1&7
1&%
1&&
2''
2'1
2'2
2'3
2'4
2'5
2'6
2'7
2'%
2'&
21'211
212
213
214
215
216
217
21%
21&
22'
221
222
223
ireal+uttonstates D+uttonstate+itmasX8 ;
real+uttonstates DT+uttonstate+itmasX9
B
i+uttonstate8 ;
real+uttonstates E+uttonstate+itmasX9 B
B
// Real de+ounced +utton state canged
ireal+uttonstates D+uttonstate+itmasX8 V
previousreal+uttonstates D+uttonstate+itmasX88 ;
// J, real +utton state LO +utton got pressed8
iVreal+uttonstates D+uttonstate+itmasX88 ;
andle+uttonpressi89
B
// Real +utton state QJQ +utton released8
ireal+uttonstates D+uttonstate+itmasX8 ;
andle+uttonreleasei89
B
B
// Set previousreal+uttonstate
ipreviousreal+uttonstates D+uttonstate+itmasX8 ;
previousreal+uttonstates DT+uttonstate+itmasX9
B
ireal+uttonstates D+uttonstate+itmasX8 ;
previousreal+uttonstates E+uttonstate+itmasX9
B
B
B
/* Kunctions */
voidhand$e_!utton_re$ease+yte +uttonnr8 ;
switch+uttonnr8 ;
case-??O>RRCOR0PJ>"
// Stop recording on recording$+utton release in second recording mode istate,lags DKL.RCOR0J>8 ;
istate,lags DKL.RCOR0J>O08 ;
stoprecording89
B
B
!rea"9
B
B
voidhand$e_!utton_press+yte +uttonnr8 ;
1/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
17/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
224
225
226
227
22%22&
23'
231
232
233
234
235
236
237
23%
23&
24'
241
242
243
244
245
246
247
24%
24&
25'
251
252
253
254
255
256
257
25%
25&
26'
261
262
263
264
265
266267
26%
26&
27'
271
272
273
274
275
276
277
27%
27&
switch+uttonnr8 ;
/* 0. */
case-??O>RRCOR0PJ>"
istate,lags DKL.RCOR0J>8 ;
iVstate,lags DKL.RCOR0J>O088 ;
stoprecording89
B
B e$se;
// na+le selected tracX ,or recording
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0.RC>-LG: 89
B
!rea"9
case-??O>PL.PJ>"
istate,lags DKL.PL.J>8 ;
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0.LOOPG: >LL89
sendoscmsg+u,89
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0..C?JO>G: 8 ;
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?ROS?.R?G: >LL89
sendoscmsg+u,89
state,lags DTKL.?RO.SO>89
state,lags EKL.?ROO>9
B
B e$se;
1/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
18/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
2%'
2%1
2%2
2%3
2%42%5
2%6
2%7
2%%
2%&
2&'
2&1
2&2
2&3
2&4
2&5
2&6
2&7
2&%
2&&
3''
3'1
3'2
3'3
3'4
3'5
3'6
3'7
3'%
3'&
31'
311
312
313
314
315
316
317
31%
31&
32'
321
322323
324
325
326
327
32%
32&
33'
331
332
333
334
335
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0..C?JO>G: 89
// s!itc metronome o,, during play+lacX
istate,lags DKL.?ROO>8 ;
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?ROS?OPG: >LL89
sendoscmsg+u,89
state,lags EKL.?RO.SO>9
state,lags DTKL.?ROO>89
B
B
!rea"9
case-??O>RJKK-.CYPJ>"
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0..C?JO>G: G: OK0.?R.CYS$18 ;
tracXselected KJRS??R.CYJ09
B
!rea"9
case-??O>.00.RYRPJ>"
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0..RYRG: >LL89
sendoscmsg+u,89
!rea"9
/* etronome */
case-??O>?ROO>OKKPJ>"
istate,lags DKL.?ROO>8 ;
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?ROS?OPG: >LL89
state,lags DTKL.?ROO>89
B e$se;
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?ROS?.R?G: >LL89
state,lags EKL.?ROO>89
B
sendoscmsg+u,89
!rea"9
1@/2
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
19/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
336
337
33%
33&
34'341
342
343
344
345
346
347
34%
34&
35'
351
352
353
354
355
356
357
35%
35&
36'
361
362
363
364
365
366
367
36%
36&
37'
371
372
373
374
375
376
377
37%37&
3%'
3%1
3%2
3%3
3%4
3%5
3%6
3%7
3%%
3%&
3&'
3&1
case-??O>?ROSP00CPJ>"
currentmetrospeed $?ROJ>C0CS?PS9
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?RO?POG: C0CS?PS9
genoscmessagemsg+u,: metroid: metro: metropatsFOSC?RO?POG: O08 ;
state,lags DTKL.RCOR0J>O09
B e$se;
state,lags EKL.RCOR0J>O09
B
!rea"9
B
B
voidstop_recording8 ;
// stop recording
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0.S?OPG: >LL89
sendoscmsg+u,89
genoscmessagemsg+u,: da!id: da!: da!patsFOSC0..C?JO>G:
-
8/13/2019 Documentation Electric WS 12.13 Soeren Wellhoefer
20/20
Sren Wellhfer
Medienkunst/Mediengestaltung, Sem. 1
3&2
3&3
3&4
3&5
3&6
3&7
3&%
3&&
4''
4'1
4'24'3
4'4
4'5
4'6
4'7
4'%
4'&
41'
411
412
413
414
415416
417
41%
41&
42'
421
422
423
424
425
426
427
42%
42&
43'
431
digitalriteL0RCOR0J>: LO89
state,lags DTKL.RCOR0J>89
B
// enerate OSC messages run$time: in ,ormat reZuired +y oscrelayvoidgen_osc_messagechar*msg: +yte id: constchar*name: constchar*pat: constchar*args: ###8
;
va_$istargp9
charid+u,F10G9
itoaint8id: id+u,: 1089
*msg A'A9
strcatmsg: id+u,89
strcatmsg: