tmhglnd / mercury

A minimal and human-readable language and environment for the live coding of algorithmic electronic music.
http://www.timohoogland.com/mercury-livecoding
GNU General Public License v3.0
291 stars 13 forks source link

Execute separate lines, blocks or sections #82

Open tmhglnd opened 1 year ago

tmhglnd commented 1 year ago

Many other live coding languages allow for per-block or per-line execution of code. Maybe this is something to look into to help create different sections in a performances/piece that can executed separately. For example use a part or section keyword:

part start
  new sample kick_909 time(1/4)
  new sample hat_909 time(1/8)
part end

Or maybe simplified with parenthesis or curly brackets

{
  new sample kick_909 time(1/4)
  new sample hat_909 time(1/8)
}
tmhglnd commented 1 year ago

In the browser version this is in an experimental working state with the shortkey shift-alt-enter and only executes grouped code that has no empty lines between it. e.g.:

// execute the block below by placing the cursor on the line of the kick or snare and hitting shift-alt-enter
new sample kick_909 time(1/4)
new sample hat_909 time(1/8)

// the synth is not audible because it is not connected with the top code because of the empty line
new synth saw note(0 1) shape(-1)
tmhglnd commented 8 months ago

An other idea to work with sections could be to include a new function called playbar() (or bar or something alike). This would allow instruments to mute/unmute for specific bars without having to create a new rhythm appended with 0's and without being restricted by the time() function. The bar length would be determined by the signature setting. Or maybe as an argument in the function. For example:

set signature 4/4

// these two instruments would alternate playing every bar
new synth sine note(0 2) time(1/16) play(euclid(11 5)) bar([1 0])
new sample hat_808 time(1/8) bar([0 1])

// this instrument would play 2 bars and 1 bar silent, but the bar length is set to 7/8 instead of 4/4
new sample snare_808 time(3/16) bar([1 1 0] 7/8)