Jump to content

Triggering event - anonymous functions (like in Javascript)

Recommended Posts

Hello all, 


I'm coming from the javascript development world. Here are few musical ideas. Is there a way to implement them thanks to Opusmodus ? 


- play a sequence of notes in 30 seconds:

in javascript, it could be pseudo-coded like this: 

 setTimeout(function(){ play('c4 d4 e4 f4 g4'); }, 3000); 


- play a sequence of notes at a specific event.

in Javascript/jQuery, it is very easy to code anonymous functions that would wait for a specific event to be triggered. Some examples I have in mind:


play 'do ré mi' at bar 4

$('4th bar').on(function() { play('c5 d5 e6');});


play 'do ré mi' each time note f5 is played

$('f5').on(function() { play('c5 d5 e6');});

repeat the note + octave when f5 is played

$('f5').on(function(this) { play(this + this.octave(1));});


In other words: is it possible to trigger an anonymous function with opusmodus, so that a musical phrase will be played at specific event ? 



Thanks for clarification, best !

Link to comment
Share on other sites

SLEEP is the function you are looking for.

(sleep time) ; in seconds 


The 1st expression will play for 10 second. The 2nd for 4 seconds.

  (ps 'gm :cl (list (gen-repeat 100 '((s c4 d4 e4 f4 g4)))))
  (sleep 10)
  (ps 'gm :fl (list '(q c5 d5 e5 f5 g5 a5 b5)))
  (sleep 4)
  (ps 'gm :fl (list '(w cs6)))


Link to comment
Share on other sites

my colleagues from the computermusic laboratory advised me not to steer external things via internal SLEEP, but also to control the TIME / delay via OSC. perhaps also has to do with the fact that for me different things must be controlled in parallel and synchronized. i don't know...

Link to comment
Share on other sites

but SLEEP is not very precise


The Common Lisp standard actually says that the number of seconds specified as arguments for sleep is approximate:


> Causes execution to cease and become dormant for approximately the seconds of real time indicated by seconds, whereupon execution is resumed. 




Anyway, it seems that at least on a Mac the imprecision is rather regular, see the following discussion with empirical tests.



Anyway, for realtime scheduling in a musical context one needs likely a proper scheduler for that. 




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use Privacy Policy