Académique Documents
Professionnel Documents
Culture Documents
Table of Contents: 1. Introduction 2. Software 2.1 OSC and OSC a lications 2.2 OSC message rela! 2." #oot$switch o erational 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 am lifier that !ou could choose from, for e'am le. #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! eo le came u with foot$switches in general. *s a musician, who also writes es eciall! 1iff$(ased music, I also ha0e other things I would like to 1/22
Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1 easil! control in order to su ort m! creati0e rocess. I usuall! ractice and write with a metronome in the (ackground and I do not like changing metronome s eed during a song as it re3uires utting the guitar aside. While writing 1iff$(ased , I usuall! come u with a rudimentar! melod! line first, record it, loo it o0er 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 Ar our 2! which is 0er! o ular and somewhat semi$ rofessional. *s a 0irtual metronome I use "t#lic#! which is the gra hical 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 am lifier, when I5m on the road and don5t ha0e m! real guitar am lifier around. M! goal with this ro;ect was to make the entire tedious rocess of recording, loo ing, changing metronome s eed, recording new riffs, etc. smoother and easier, es eciall! without ha0ing to lift m! fingers awa! from the guitar. <he solution is a foot$switches to control all these things, and I (uilt one using the *rduino in order to control m! *udio software. . Software .1 OSC and OSC applications #irst let me answer that one sim le 3uestion. What is OSC= >ut in lain terms, OSC 8O en$Sound$Control9 is the more ad0anced successor of MI7I when it comes to the controlling and intercommunication of modern *udio$a lications. It has a rotocol stack (ased on <C> and the ?7> rotocol, and uses it to send and recei0e messages. It remo0es man! of the restrictions of MI7I, is cleaner and es eciall! much more t! e$safe for arameters assings and sometimes e0en faster. #rom Wiki edia+ Open Sound Control %&S'( is a content format for messa"in" amon" com)uters! soun synthesi*ers! an other multime ia e+ices that are o)timi*e for mo ern networ#in" technolo"y. ,rin"in" the -enefits of mo ern networ#in" technolo"y to the worl of electronic musical instruments! &S'.s a +anta"es inclu e 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'am le !ou can send *rdour the following OSC messages on ort "1@A Same as hitting la! (utton+ /ardour/transport_play Changing the la!(ack s eed+ /ardour/set_transport_speed [transport_speed]
* list of ossi(le OSC aths 8commands9 for *rdour and klick can (e found here, res ecti0el!+ htt s+//communit!.ardour.org/oscBcontrol /usr/share/doc/klick/manual.htmlCosc 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/22
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 a lications 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 ro er OSC$messages and sends them o0er ?7> to the right a lication and ort. In its (ackend this a lication uses li-lo! an o en$source im lementation of the OSC$ rotocol stack. In0oking ./oscrelay0
Usage: ./oscrelay -s <ttyport> -o <osc_port_app_1>.. -o <osc_port_app_N> The ordering of `-o' is important
<he first arameters $s is the serial ort to listen on. *fter this !ou use $o for the ort num(er on localhost that a s ecific OSC$a lication listens on. <he a lication first gi0en gets I7 2, 1, .. <his I7 is im ortant. In real li0e I would in0oke OSC$rela! like this+ Fou can find the source code of oscrela!.c attached.
./oscrelay -s /dev/ttyACM0 -o 3819 -o 5555
Where "@1A is the OSC$ ort of *rdour and )))), that of klick 8the metronome9. It is im ortant to note that for this to work, in *rdour5s config file OSC must (e ena(led and that gtklick must (e in0oked with the arameter $o )))) in order for it to start its klick instance with the incoming OSC ort of )))). <he format oscrela! e' ects messages to arri0e o0er the serial ort from the *rduino are as follows+ 12D301PA453 1PA6A7E4E648PE301PA6A7E4E63 #or instance the *rduino could send o0er /de0/tt!*SM2+
0:/ardour/access_action s:Editor/select-all-after-playhead
oscrela! generates a ro er OSC message from this te't string and sends it to ort "1@A. *rdour then selects all after the la!head5s current osition. #ollowing schematic illustrates the OSC messages flow+ /de0/tt!*CM2 >roto$OSC message oscrela!.c ?7> 8<C> orts9 :lick "/22 *rdour 2
*rduino ?no
.$ %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 (uttonB ressed and a (uttonBreleased handler functions res ecti0el!, as well as (utton de(ouncing routines. <he rogram has (een written with s eed and s ace considerations in mind, that is to (e as fast as ossi(le in order to foster a more real$time feeling when (eing used, and also to conser0e flash memor! s ace on the limited storage the *rduino ?no ro0ides. <his is also wh! OSC messages are not hard$coded (ut rather generated on the fl!, as string mani ulations in C is reall! fast as well. It should (e fairl! o(0ious how the foot$switch can control the metronome, when I sa! that the arameters of s eed and whether the metronome is OD/O## are (eing made controlla(le. M! idea for *rdour in regards to the foot$switch is, that riffs are sim l! (eing recorded on after the other. *rdour stores each recording in a so$called re"ion which is laced on a trac#. * track is ;ust like a recording ta e that multi le recordings 8or regions9 can (e ut onto on after the other. When I write music, I usuall! write melod! and harmon!, so I ha0e two tracks for each. *s each region re resents a signal recording and thus a riff in m! conce t! I can loo that region using the foot$switch and la! stuff o0er it and see if I can come u with an!thing that fits to that which I had re0iousl! recorded. If I found something, than I can switch to the ne't track using the foot$switch and record what I ha0e come u with on the track e'actl! (elow m! re0ious recording. ?sing the foot$switch, I can also ski (ack to m! re0ious riffs, or record something entirel! new without losing m! re0ious ideas. *ll in all aiding the songwriting rocess greatl!. <he following screenshot from *rdour illustrates what I50e ;ust descri(ed a(o0e+
Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1 Fou can see that the tracks *udio 1 and *udio 2 contain guitar recordings as regions res ecti0el!. #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. <he Metro track at the (ottom is ;ust the metronome (eing recorded as well (ut se aratel!, for (eat tracking ur oses. <he red (ar is the currentl! la!head marker which is alwa!s set to the (eginning of a riff. <he last riff in the screenshot is (eing marked for loo ing, (ut not currentl! la!ed. * riff, once written, can (e la(eled for later reference, this is 0er! useful to 0er(all! remem(er what musical idea has actuall! (een recorded.
2llustration 20 :t#lic#! the "ra)hical interface to the ;A'<9-ase metronome #lic#! that is controlla-le -y the foot9switch $. &ardware #or the actual foot$switch hardware, I had to (uild something that would (e sta(le since it would (e stom ed onto a lot, (ut which would also (e a(le to hold u to 12 (uttons that are well accessi(le (! foot. -asicall!, the hardware consists of two wooden slates screwed together in a &) degree angle, with 12 ush (uttons attached to it. <he (uttons are laced according to their functionalit! and also with the remise in mind, to allow eas! accessi(ilit! for those (uttons most commonl! used. #ollowing is a icture of the foot$switch (eing used while la!ing guitar. <he red 6G7 that is lit u is indicating that the guitar is currentl! (eing recorded (! the 7*W, meaning that the recording (utton on the foot$switch was ressed and sent a HrecordI OSC message to the 7*W through the serial ort and the rela! rogram causing it to o erate.
)/22
2llustration 30 Picture of &S' foot9switch -ein" use #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
<heir high$le0el functionalit! of the (uttons and what the! generate as OSC messages is shown in the ne't ta(le. 1utton (.abel) S>GG7J %unctionalit# OSC !essa"es (oscrelay.c-e2pected for!at)
Increases metronome s eed 1:/klick/simple/set_tempo f:<SPEED+5> (! ) ( m 8(eats er minute9. 7efault s eed is 122 ( m 7ecreases metronome s eed 1:/klick/simple/set_tempo f:<SPEED-5> (! ) ( m Switches the metronome OD or O## *dds a mark to the (eginning of the current riff
If O##, sends If OD, sends 1:/klick/metro/start 1:/klick/metro/stop
S>GG7$ MG<1O
M*1:
0:/ardour/add_marker
,/22
Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1 for la(eling ur oses. 1GC <ells the 7*W 8*rdour9 to If not recording+ Gna(le selected track for recordings record. 0:/ardour/routes/recena le <!"#$%> 1 *(o0e the recoding (utton 0:/ardour/access_action s:!ransport/"ecord there is also a smaller (utton 0:/ardour/transport_pla& that can set the the recording mode. In mode 1, one If recording+ resses the recording (utton, 0:/ardour/transport_stop and the 7*W kee s 0:/ardour/access_action recording until ressed s:Editor/pla&'ead-to-pre(iousagain. In mode 2 recording re)ion- oundar&-noselection onl! last as long as the 0:/ardour/routes/recena le <!"#$%> 0 (utton is (eing ressed. <he first mode is useful if one records longer riffs or e0en entire songs. 6oo s the region 8riff9 the la!head is currentl! at. It will also switch of the metronome O## when la!ing, and switch it (ack OD when the loo la! (utton is hit again, thus sto ing the loo la!(ack.
If not !et loo ing+ 0:/ardour/access_action s:Editor/set-loop-from-re)ion 0:/ardour/loop_to))le If loo ing+ 0:/ardour/loop_to))le 0:/ardour/access_action s:Editor/pla&'ead-to-pre(iousre)ion- oundar&-noselection
6OO>
<1*C:
Selects the current track 81 Done or 29 for recording. If track 2 is selected, the !ellow Htrack$selectI 6G7 is lit. Mo0es the actual la!head to the re0ious riff in *rdour.
0:/ardour/access_action s:Editor/pla&'ead-to-pre(ious-re)ionoundar&-noselection
1I##K
1I##L
Mo0es the actual la!head 0:/ardour/access_action s:Editor/pla&'ead-to-ne*t-re)ionto the ne't riff in *rdour. If oundar&-noselection there is no ne't riff, goes to the end of last riff. * new riff can then (e recorded. Switches (etween the two recording modes 8see 1GC (utton9. Done
MO7G
M/22
2llustration =0 5ere is a )icture of sol erin" the )ush9-utton connections on the -ac# while -uil in" the foot9switch 3. Conclusion and e2tendabilit# <he OSC foot$switch I50e (uild has greatl! enhanced m! fle'i(ilit! in riff writing and e0en in regular guitar ractice. It com lements the creati0e rocess 0er! well and allows me to e' ress m!self more freel! musicall!, remo0ing almost all the re0ious hindrances. I might ha0e liked to use e0en more (uttons, (ut alas I used u all m! *rduino ?no ins. I could ha0e installed a Hswitch$to$second$le0elI (utton, in order to gi0e each ush (utton a dou(le functionalit!, much like the Shift$ke! on a ke!(oard. On the other hand, (! kee ing things at what is actuall! im ortant when racticing and/or writing riffs, I kee things sim le straight and clean. #or an!thing more com licated I sit down an!wa!s and use m! Com uter mouse and ke!(oard for ro er editing. 4. Appendi2 A: Source code oscrelay.c
1 2 3 4 5 6 7 /* Relays OSC messages arduino sends over serial port to certain ports on local ost Compile !it " cc oscrelay#c $o oscrelay $llo
@/22
-&6'' 1' 5
int serial6init7const char *port89 int serial6read7int ,d: char *+u,89 void usage7char *progname8 ; print,7</sage" =s $s )ttyport* $o )osc6port6app61*## $o )osc6port6app6>*\n ? e ordering o, @$oA is important#\n<: progname89 B
int32_t swap_int327int32_t val8 ; val C 77val )) 88 D 0xFF00FF008 E 77val ** 88 D 0xFF00FF 89 return 7val )) 168 E 77val ** 168 D 0xFFFF89 B int main7int argc: char **argv8 ; char *serialport9 char read+u,F256G: *+u,ptr9 char *osc6pat 9 int oscrec6id9 int i: H9 int serial6,d9 lo6address oscsF1.2OSCS3R43RG9 lo6message lo6osc6msg9
/* Command line arguments */ i 7argc ) 58 ; usage7argvF0G89 eIit732J?6K.JL/R389 B or7i C 0: H C 09 i ) argc9 iMM8 ; i 7*argvFiG CC A$A8 ;
A/22
/* 1ain loop */ or7998 ; +Nero7read+u,: si#eo 7read+u,889 i 7serial6read7serial6,d: read+u,8 ) 08 ; eIit732J?6K.JL/R389 B i 77+u,ptr C strc r7read+u,: A"A888 ; lo6osc6msg C lo6message6ne!789 *+u,ptrMM C AO'A9 oscrec6id C atoi7read+u,89 osc6pat C +u,ptr9 /* Parse osc message arguments i, any */ char *argstart9 i 77argstart C strc r7+u,ptr: A A888 ; char *arglistF1.2.R5SG9 int i C 09 whi$e77+u,ptr C strrc r7+u,ptr: A A888 ; *+u,ptr C AO'A9 arglistFiMMG C MM+u,ptr9 +u,ptr C argstart9 B or7 i$$9 i *C09 i$$8 ; char type C *arglistFiG: *argument C arglistFiGM29 switch7type8 ; /* String */
12/22
(i,de, 03-/5 print,7<\nOSC" J0$* E=dE: P.?Q$*" E=sE\n<: oscrec6id: osc6pat 89 lo6message6pp7lo6osc6msg89 (endi, i 7lo6send6message7oscsFoscrec6idG: osc6pat : lo6osc6msg8 ) 08 ; ,print,7stderr: <3rror sending osc message\n<89 B lo6message6,ree7lo6osc6msg89 B
int seria$_init7const char *port8 ; struct termios io9 int ,d9 ,d C open7port: O6R0RR E O6>OC??S E O6>03L.S89 i 7,d ) 08 ; perror7<Cannot open serial port<89 return $19 B i 7tcgetattr7,d: Dio8 ) 08 ; perror7<Cannot read term attri+utes<89 return $19 B c,setispeed7Dio: -./089 c,setospeed7Dio: -./089 /* %$>$1 con,iguration */
11/22
Kormat it sends" )oscid*")pat * )arg16type*")arg1* ### )arg>6type*")arg>* 3Iamples" '"/ardour/routes/recena+le ,"2 ,"' '"/ardour/access6action s"3ditor/play ead$to$previous$region$+oundary$noselection 1"/XlicX/metro/start */ /* Jmportant value de,initions */ (de,ine >/16OK60.R6?R.CYS (de,ine KJRS?6?R.CY6J0 (de,ine 03K./L?613?RO6SP330 (de,ine 13?RO6J>C03CS?3PS (de,ine S3RJ.L6-./0 (de,ine -/??O>603-O/>C36R.J??J13 /* Pin declarations */ (de,ine -/??O>6>ROK-/??O>S (de,ine -/??O>6S?.R?6PJ> // 0.R (de,ine -/??O>6R3R3COR06PJ> (de,ine -/??O>6PL.S6PJ> (de,ine -/??O>6RJKK-.CY6PJ> (de,ine -/??O>6RJKKKR06PJ> (de,ine -/??O>6?R.CYS3L3C?6PJ> (de,ine -/??O>6.001.RY3R6PJ> //1etro (de,ine -/??O>613?ROO>OKK6PJ> (de,ine -/??O>613?ROSP33003C6PJ> (de,ine -/??O>613?ROSP330J>C6PJ> (de,ine PO?J613?RO64OL/13 //5eneral (de,ine -/??O>6R3COR0J>561O03 //L30s (de,ine L306R3COR0J>5 (de,ine L306?R.CYS3L3C? /* OSC server pat s */ // 0igitial .udio RorXstation (de,ine OSC60.R6PL.S (de,ine OSC60.R6S?OP (de,ine OSC60.R6.C?JO> (de,ine OSC60.R6R3C3>-L (de,ine OSC60.R61.RY3R (de,ine OSC60.R6LOOP (de,ine OSC60.R6/>0O
//ms
11 1 -/??O>6S?.R?6PJ> 7-/??O>6S?.R?6PJ>M18 7-/??O>6S?.R?6PJ>M28 7-/??O>6S?.R?6PJ>M38 7-/??O>6S?.R?6PJ>M48 7-/??O>6S?.R?6PJ>M58 7-/??O>6S?.R?6PJ>M68 7-/??O>6S?.R?6PJ>M78 7-/??O>6S?.R?6PJ>M%8 .' 7-/??O>6S?.R?6PJ>M&8 12 13
// s o!s ! ic
' 1 2 3 4 5 6
1"/22
+yte da!6id C 09 const char *da! C </ardour<9 const char *da!6pat sFG C ;</transport6play<: </transport6stop<: </access6action<: </routes/recena+le<: </add6marXer<: </loop6toggle<: </undo<: </redo<B9 const char *da!6paramsFG C ;<3ditor/play ead$to$previous$region$+oundary$noselection<: <3ditor/play ead$to$neIt$region$+oundary$noselection<: <?ransport/Record<: <3ditor/set$loop$,rom$region<: <3ditor/select$all<: <3ditor/invert$selection< B9
// 1etronome (de,ine OSC613?RO6S?.R? ' (de,ine OSC613?RO6S?OP 1 (de,ine OSC613?RO6?31PO 2 +yte metro6id C 19 const char *metro C </XlicX<9 const char *metro6pat sFG C ;</metro/start<: </metro/stop<: </simple/set6tempo<B9 /* Klags */ (de,ine KL.56R3COR0J>5 (de,ine KL.56PL.SJ>5 (de,ine KL.5613?RO6O> (de,ine KL.56R3COR0J>561O03 (de,ine KL.5613?RO6R.S6O> int16_t state6,lags C 09 /* State varia+les */ +yte tracX6selected C 0 M KJRS?6?R.CY6J09 +yte current6metro6speed C 03K./L?613?RO6SP3309 /* -utton de+ounce varia+les */ +yte +utton6press6!ait6time C -/??O>603-O/>C36R.J??J139 $ong +utton6press6timesF-/??O>6>ROK-/??O>SG9 uint16_t +utton6states C 09 uint16_t real6+utton6states9 uint16_t previous6real6+utton6states9
1&/22
1)/22
1,/22
1M/22
1@/22
void stop_recording78 ; // stop recording gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6S?OPG: >/LL89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16-.CYG89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16-.CYG89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6R3C3>-LG: <ii<: tracX6selected: 089 send6osc7msg6+u,89
// 0irty acX gen6osc6message7msg6+u,: da!6id: da!: da!6pat da!6paramsFOSC60.R6P.R.16S3L3C?6.LLG89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat da!6paramsFOSC60.R6P.R.16J>43R?G89 send6osc7msg6+u,89
sFOSC60.R6.C?JO>G: <s<:
1A/22
3&2 3&3 3&4 3&5 3&6 3&7 3&% 3&& 4'' 4'1 4'2 4'3 4'4 4'5 4'6 4'7 4'% 4'& 41' 411 412 413 414 415 416 417 41% 41& 42' 421 422 423 424 425 426 427 42% 42& 43' 431
// Parse arguments i 7args8 ; char +F16G9 va6start7argp: args89 do ; strcat7msg: < <89 switch7*args8 ; // String case AsA" strcat7msg: <s"<89 strcat7msg: va6arg7argp: char*889 !rea"9 // Jnteger case AiA" case A,A" char cF2G C ;*args: AO'AB9 strcat7msg: c89 strcat7msg: <"<89 itoa7va6arg7argp: int8: +: 1089 strcat7msg: +89 !rea"9 B B whi$e7*MMargs VC AO'A89 B strcat7msg: <\n\0<89 va6end7argp89 B void send_osc7const char *msg8 ; Serial#println7msg89 B
22/22