Vous êtes sur la page 1sur 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 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

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 (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+

2llustration 10 Ar our -ein" controlle -y the &S'9footswitch &/22

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

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1

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

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1

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

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


% & 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 42 43 44 45 46 47 4% 4& 5' 51 52 53 54 55 56 57 5% 5& 6' 61 62 63 */ (include (include (include (include (include (include (include (include (include )stdio# * )stdli+# * )stdint# * )termios# * )unistd# * )string# * ),cntl# * )lo/lo# * )errno# *

(de,ine -./0 (de,ine 1.2OSCS3R43R (de,ine 1.2.R5S

-&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

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'6 1'7 1'% 1'& 11' 111 112 113 114 115 116 117 11% 11& switch7*MMargvFiG8 ; case AsA" serialport C argvFiM1G9 !rea"9 case AoA" oscsFHG C lo6address6ne!7>/LL: argvFiM1G89 HMM9 !rea"9 B B B serial6,d C serial6init7serialport89 i 7serial6,d ) 08 ; eIit732J?6K.JL/R389 B

/* 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

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


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 154 155 156 157 15% 15& 16' 161 162 163 164 165 166 167 16% 16& 17' 171 172 173 174 175 case AsA" lo6message6add6string7lo6osc6msg: argument89 !rea"9 /* Jnteger */ case AiA" case A,A" lo6message6add6int327lo6osc6msg: 7uint32_t8atoi7argument889 !rea"9 B B B

(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

usleep7100089 B close7serial6,d89 return 09 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

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 217 21% 21& 22' 221 222 223 io#c6c,lag DC TP.R3>-9 io#c6c,lag DC TCS?OP-9 io#c6c,lag DC TCSJU39 io#c6c,lag EC CS%9 io#c6c,lag DC TCR?SC?S9 io#c6c,lag EC CR3.0 E CLOC.L9 io#c6i,lag DC T7J2O> E J2OKK E J2.>S89 io#c6l,lag DC T7JC.>O> E 3CQO E 3CQO3 E JSJ589 io#c6o,lag DC TOPOS?9 io#c6ccF41J>G C 09 io#c6ccF4?J13G C 209 i 7tcsetattr7,d: ?CS.>OR: Dio8 ) 08 ; perror7<Cannot initialiNe serial port<89 return $19 B return ,d9 B /* Read ,rom serial port until carriage return */ int seria$_read7int ,d: char *+u,8 ; char +yteF1G C ;AO'AB9 int i C 0: r9 do ; r C read7,d: +yte: 189 i 7r ) 08 ; i 7errno CC 3.5.J>8 ; r C 09 B e$se ; perror7<Could not read ,rom serial port<89 return $19 B B /* Read not ing */ i 7r CC 08 ; usleep71000089 continue9 B +u,FiMMG C +yteF0G9 B whi$e7*+yte VC AOnA89 +u,F$$iG C AO'A9 return 09 B

5. Appendi2 1: Source code oscfootswitch.ino 12/22

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 42 43 44 45 46 47 4% 4& 5' 51 52 53 54 55 /* Simple ,oot ,or t e 0.R t em over t and relayed s!itc t at generates OSC 7Open Sound Control8 messages <.rdour2< and t e WacX$+ased metronome <XlicX<: and sends e serial port# 1essages are to +e received +y oscrelay#c to t e OSC server#

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

2 3 1'' 5 &6'' 5'

//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

o, t!o tracXs is selected ,or recording

' 1 2 3 4 5 6

1"/22

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 (de,ine (de,ine (de,ine (de,ine (de,ine (de,ine OSC60.R6R30O OSC60.R6P.R.16-.CY OSC60.R6P.R.16>32? OSC60.R6P.R.16R3COR0 OSC60.R6P.R.16S3?LOOP OSC60.R6P.R.16S3L3C?6.LL OSC60.R6P.R.16J>43R? 7 ' 1 2 3 4 5

+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

71))'8 71))18 71))28 71))38 71))48

1&/22

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


112 113 114 115 116 117 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 154 155 156 157 15% 15& 16' 161 162 163 164 165 166 167 /* OSC message +u,,er */ char msg6+u,F128G9 /* Prototypes */ void gen6osc6message7char *msg: +yte id: const char *name: const char *pat : const char *args: ###89 void send6osc7const char *msg89 void stop6recording789 void andle6+utton6press7+yte +utton6nr89 void andle6+utton6release7+yte +utton6nr89 /* 1ain ,unctions */ void setup78 ; Serial#+egin7S3RJ.L6-./089 or7+yte i C -/??O>6S?.R?6PJ>9 i ) -/??O>6S?.R?6PJ> M -/??O>6>ROK-/??O>S 9 iMM8 ; pin1ode7i: J>P/?6P/LL/P89 B pin1ode7L306R3COR0J>5: O/?P/?89 pin1ode7L306?R.CYS3L3C?: O/?P/?89 or7+yte i C 09 i ) -/??O>6>ROK-/??O>S9 iMM8 ; +utton6states EC 71))i89 +utton6press6timesFiG C 09 B real6+utton6states C +utton6states9 previous6real6+utton6states C +utton6states9 B void $oop78 ; // Read +uttons or7+yte i C 09 i ) -/??O>6>ROK-/??O>S9 iMM8 ; int +utton6state C digitalRead7iM-/??O>6S?.R?6PJ>89 uint16_t +utton6state6+itmasX C 71))i89 // -utton value c anged i 7+utton6state))i VC 7+utton6states D +utton6state6+itmasX88 ; i 7+utton6state8 ; +utton6states EC +utton6state6+itmasX9 B e$se ; +utton6states DC T+utton6state6+itmasX9 B +utton6press6timesFiG C millis789 B // -utton de+ounce i 77millis78 $ +utton6press6timesFiG8 * +utton6press6!ait6time8 ;

1)/22

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


16% 16& 17' 171 172 173 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 i 7real6+utton6states D +utton6state6+itmasX8 ; real6+utton6states DC T+utton6state6+itmasX9 B i 7+utton6state8 ; real6+utton6states EC +utton6state6+itmasX9 B B // Real de+ounced +utton state c anged i 77real6+utton6states D +utton6state6+itmasX8 VC 7previous6real6+utton6states D +utton6state6+itmasX88 ; // J, real +utton state C LOR 7+utton got pressed8 i 7V7real6+utton6states D +utton6state6+itmasX88 ; andle6+utton6press7i89 B // Real +utton state C QJ5Q 7+utton released8 i 7real6+utton6states D +utton6state6+itmasX8 ; andle6+utton6release7i89 B B // Set previous6real6+utton6state i 7previous6real6+utton6states D +utton6state6+itmasX8 ; previous6real6+utton6states DC T+utton6state6+itmasX9 B i 7real6+utton6states D +utton6state6+itmasX8 ; previous6real6+utton6states EC +utton6state6+itmasX9 B B B /* Kunctions */ void hand$e_!utton_re$ease7+yte +utton6nr8 ; switch7+utton6nr8 ; case -/??O>6R3R3COR06PJ>" // Stop recording on recording$+utton release in second recording mode i 7state6,lags D KL.56R3COR0J>58 ; i 7state6,lags D KL.56R3COR0J>561O038 ; stop6recording789 B B !rea"9 B B

void hand$e_!utton_press7+yte +utton6nr8 ;

1,/22

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 266 267 26% 26& 27' 271 272 273 274 275 276 277 27% 27& switch7+utton6nr8 ; /* 0.R */ case -/??O>6R3R3COR06PJ>" i 7state6,lags D KL.56R3COR0J>58 ; i 7V7state6,lags D KL.56R3COR0J>561O0388 ; stop6recording789 B B e$se ; // 3na+le selected tracX ,or recording gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6R3C3>-LG: <ii<: tracX6selected: 189 send6osc7msg6+u,89 // Record gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16R3COR0G89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6PL.SG: >/LL89 send6osc7msg6+u,89 digitalRrite7L306R3COR0J>5: QJ5Q89 state6,lags EC 7KL.56R3COR0J>589 B !rea"9 case -/??O>6PL.S6PJ>" i 7state6,lags D KL.56PL.SJ>58 ; gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6LOOPG: >/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 state6,lags DC T7KL.56PL.SJ>589 // s!itc metronome +acX on i, it !as on +e,ore play+acX i 7state6,lags D KL.5613?RO6R.S6O>8 ; gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6S?.R?G: >/LL89 send6osc7msg6+u,89 state6,lags DC T7KL.5613?RO6R.S6O>89 state6,lags EC KL.5613?RO6O>9 B B e$se ;

1M/22

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


2%' 2%1 2%2 2%3 2%4 2%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 322 323 324 325 326 327 32% 32& 33' 331 332 333 334 335 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16S3?LOOPG89 send6osc7msg6+u,89 gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6LOOPG: >/LL89 send6osc7msg6+u,89 state6,lags EC 7KL.56PL.SJ>589 // s!itc metronome o,, during play+lacX i 7state6,lags D KL.5613?RO6O>8 ; gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6S?OPG: >/LL89 send6osc7msg6+u,89 state6,lags EC KL.5613?RO6R.S6O>9 state6,lags DC T7KL.5613?RO6O>89 B B !rea"9 case -/??O>6RJKK-.CY6PJ>" gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16-.CYG89 send6osc7msg6+u,89 !rea"9 case -/??O>6RJKKKR06PJ>" gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R6.C?JO>G: <s<: da!6paramsFOSC60.R6P.R.16>32?G89 send6osc7msg6+u,89 !rea"9 case -/??O>6?R.CYS3L3C?6PJ>" digitalRrite7L306?R.CYS3L3C?: VdigitalRead7L306?R.CYS3L3C?889 i 7MMtracX6selected$KJRS?6?R.CY6J0 * >/16OK60.R6?R.CYS$18 ; tracX6selected C KJRS?6?R.CY6J09 B !rea"9 case -/??O>6.001.RY3R6PJ>" gen6osc6message7msg6+u,: da!6id: da!: da!6pat sFOSC60.R61.RY3RG: >/LL89 send6osc7msg6+u,89 !rea"9 /* 1etronome */ case -/??O>613?ROO>OKK6PJ>" i 7state6,lags D KL.5613?RO6O>8 ; gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6S?OPG: >/LL89 state6,lags DC T7KL.5613?RO6O>89 B e$se ; gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6S?.R?G: >/LL89 state6,lags EC 7KL.5613?RO6O>89 B send6osc7msg6+u,89 !rea"9

1@/22

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>613?ROSP33003C6PJ>" current6metro6speed $C 13?RO6J>C03CS?3PS9 gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6?31POG: <,<: current6metro6speed89 send6osc7msg6+u,89 !rea"9 case -/??O>613?ROSP330J>C6PJ>" current6metro6speed MC 13?RO6J>C03CS?3PS9 gen6osc6message7msg6+u,: metro6id: metro: metro6pat sFOSC613?RO6?31POG: <,<: current6metro6speed89 send6osc7msg6+u,89 !rea"9 case -/??O>6R3COR0J>561O03" i 7state6,lags D KL.56R3COR0J>561O038 ; state6,lags DC TKL.56R3COR0J>561O039 B e$se ; state6,lags EC KL.56R3COR0J>561O039 B !rea"9 B B

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<:

sFOSC60.R6/>0OG: >/LL89 sFOSC60.R6R30OG: >/LL89 sFOSC60.R6.C?JO>G: <s<:

1A/22

Sren Wellhfer Medienkunst/Mediengestaltung, Sem. 1


digitalRrite7L306R3COR0J>5: LOR89 state6,lags DC T7KL.56R3COR0J>589 B // 5enerate OSC messages run$time: in ,ormat reZuired +y oscrelay void gen_osc_message7char *msg: +yte id: const char *name: const char *pat : const char *args: ###8 ; va_$ist argp9 char id6+u,F10G9 itoa77int8id: id6+u,: 1089 *msg C AO'A9 strcat7msg: strcat7msg: strcat7msg: strcat7msg: id6+u,89 <"<89 name89 pat 89

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

Vous aimerez peut-être aussi