sugarlabs / musicblocks

Music Blocks -- A musical microworld
https://musicblocks.sugarlabs.org/
GNU Affero General Public License v3.0
554 stars 756 forks source link

timing drifts #49

Closed walterbender closed 7 years ago

walterbender commented 8 years ago

We need a master clock

pikurasa commented 8 years ago

This is a very important issue, I think.

Master Clock seems to be critical to two important features of Music Blocks (in order of importance): 1) counterpoint (Frere Jacques is "okay" right now, but more complex rhythms are unsuccessful) 2) Turtle-Mouse (turtle art and music) integrated visual-aural art/music integration -- I just call it "Turtle-Mouse Integration", which is a fun title.

Modest Search for JavaScript clocks on Git Hub (not necessarily "for music", but may be helpful):

(most promising at the top)

For Music

_ACTIVE DEVELOPMENT --_ Web Midi Clock Sequencer: https://github.com/starmandeluxe/WebMidiClockSequencer

_None of the below have explicit licenses!_

Midi Clock: https://github.com/livejs/midi-clock Midi repeater: https://github.com/mmckegg/midi-repeater "Ditty" -- Schedule playback for a loop sequence of Web Audio events: https://github.com/livejs/ditty MIDI Clock through WebSocket: https://github.com/noio/pulse

_MIT License, but probably not what we are looking for --_sync your gifs with a midi clock: https://github.com/jkap/tricktionary

Not Specifically for Music

_None of the below have explicit licenses!_

Timing Clock: https://github.com/neolitec/sergy Game Clock: https://github.com/RoryDuncan/ClockEventAggreggator Timer Helper for JS: https://github.com/raphaelrauwolf/clockWork TV Clock: https://github.com/bactisme/tv-clock Timer for exams: https://github.com/tjd/examclock

pikurasa commented 8 years ago

You can test the Midi Clock HERE: https://rawgit.com/starmandeluxe/WebMidiClockSequencer/master/index.html

Doesn't seem to work "out of the box" in FireFox: screenshot - 10222015 - 08-50-56 am

Works "out of the box" in chromium (however, please test sound -- my midi isn't working right now) screenshot - 10222015 - 08-51-46 am seems to work with chrome

pikurasa commented 8 years ago

Will any of the timing/clock code from https://github.com/starmandeluxe/WebMidiClockSequencer be helpful to us? Is any of it integratable?

I imagine that the midi part of it would be difficult to integrate, but can the clock/timing be "transplanted"? (Mr. Mouse heart transplant)

walterbender commented 8 years ago

Let's meet next week to map out a plan.

On Fri, Oct 23, 2015 at 9:09 AM, Devin Ulibarri notifications@github.com wrote:

Will any of the timing/clock code from https://github.com/starmandeluxe/WebMidiClockSequencer be helpful to us? Is any of it integratable?

I imagine that the midi part of it would be difficult to integrate, but can the clock/timing be "transplanted"? (Mr. Mouse heart transplant)

— Reply to this email directly or view it on GitHub https://github.com/walterbender/musicblocks/issues/49#issuecomment-150566642 .

Walter Bender Sugar Labs http://www.sugarlabs.org

pikurasa commented 8 years ago

Sure, I can meet. @khandelwalYash would you like to join us? If so, what time(s) would work for you.

I thought about this issue some more from another perspective.

If you told me, for example, that we were going to show Music Blocks at a conference in 10 days and that we had two choices. Choice one is to spend all our energy on a master clock, with an uncertain outcome. Choice two is that we could create a patch that would have the timeouts make adjustments so that the multiple simultaneous "voices" would, according to a certain algorithm**, compensate for imperfections in timing, and that the possibility for a successful patch seemed very good.

I would, by far, choose the second choice.

*The algorithm would need to: find points were the notes should play simultaneously and make sure that they do. *if a certain voice did not complete its durations before the points of simultaneity, time would be added as part of its readjustment (since we do not have a master clock, I cannot imagine how subtracting to make an adjustment would be feasible).

So, for something like this:

Voice 1 = 1/4 1/4 1/8 1/8 1/4 Voice 2 = 1/6 1/12 1/4 1/6 12/ 1/8 1/8

It would _maybe_ (big maybe here) first find the least common denominator (LCD=24). Then find points of alignment (each quarter note--or every sixth 24th note--in this instance) and make sure they start together. And if some of the notes take too long, add time to the other notes--essentially wait for the slower moving notes--to make an adjustment.

This would be acceptable in 95% of cases. Highly rhythmic, syncopated music and music where the user is purposely trying to create rhythmic counterpoint without many overlapping points would probably not benefit much from this particular patch, unless you had any ideas for how to readjust even at points without many simultaneity.

Just some thoughts! (Trying to think of priorities over here--I am a performer after all, so I understand the desire to just get to certain goal posts) Cheers!