fluhus / beatnik

A drum programming language.
MIT License
21 stars 3 forks source link

Loops #2

Closed servusdei2018 closed 4 years ago

servusdei2018 commented 4 years ago

The ability to program a loop would be great. So a loop would allow the same sequence to be played for a set amount of iterations (or infinitely) like:

#This would loop twice
LOOP 2
HC,K. HC.   HC,S. HC.
ENDLOOP

and

#This would loop infinitely
LOOP ~
HC,K. HC.   HC,S. HC.
ENDLOOP
truj commented 4 years ago

Just a few considerations...

An infinite loop is only possible if the sound is produced on the fly. But not if a MIDI file is exported. Or if an intermediate MIDI sequence must be available before playback time. (I don't know if MIDI file export or an intermediate sequence must be considered with beatnik)

I had similar considerations with Midica There I cannot allow infinite loops. My loops are implemented using nestable blocks A kind of multi-purpose blocks accepting parameters. A beatnik example could look something like this:

{ times=2
    HC,K. HC.   HC,S. HC.
}

The block is determined by { and }, and times=2 (in this case) could mean "execute this block twice". (In Midica I use q, meaning quantity for this purpose, instead of times)

If a loop is the only kind of block that's needed (now and in the future), than it's probably easier to use something like servusDei2018's example. Because it's a bit easier to read.

fluhus commented 4 years ago

Thanks for the suggestions!

Loops are a feature I was planning to add according to demand, so your feedback is important.

An infinite loop is indeed not possible in the context of a (finite) MIDI file. Perhaps in the future if streaming output is implemented it can be added.

My inclination is for the syntax to be something like

loop:4  # or `loop: 4` with a space
K S K S
loop:end

The initial thought was to make drums in capitals and control syntax in smalls using :. This way drums stand out more and the file is more readable.

fluhus commented 4 years ago

I have committed the initial implementation for loops.

@servusDei2018 are you able to build the latest version (instructions) and check if the syntax above works for you?

fluhus commented 4 years ago

Or you can get the binaries from here. I'll make a release once this is finalized.

servusdei2018 commented 4 years ago

Thanks @fluhus , it works great!

fluhus commented 4 years ago

Great, thanks for checking! Will create a release soon.