Created
February 20, 2016 16:14
-
-
Save antoinevg/3d68e0c8535aff43e12b to your computer and use it in GitHub Desktop.
Simple MIDI Sync for Extempore and Ableton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; useful | |
(define *beats-per-bar* (lambda () 4)) | |
(define *next-bar* (lambda () (*metro* 'get-beat (*beats-per-bar*)))) | |
;; init MIDI & create a stream for my Ableton IAC device | |
(sys:load "libs/external/portmidi.xtm") | |
(pm_initialize) | |
(pm_print_devices) | |
(define *ableton* (pm_create_output_stream 7)) | |
;; TR wrapper around pm_send | |
(define (send-midi-message time stream type chan a b) | |
(callback time (lambda () | |
(pm_send stream type chan a b)))) | |
;; a touch of global state | |
(define *midi-clock-state* #f) | |
;; Midi sync | |
(define (*midi-clock* beat) | |
(println '*midi-clock* beat) | |
(dotimes (frame 24) | |
(send-midi-message (*metro* (+ beat (/ frame 24))) *ableton* *midi-timiing-clock* 0 0 0)) | |
(if *midi-clock-state* (callback (*metro* (+ beat 23/24)) '*midi-clock* (+ beat 1)))) | |
(define (*ableton-start* beat) | |
(set! *midi-clock-state* #t) | |
(send-midi-message (*metro* beat) *ableton* *midi-song-position* 0 0 0) | |
(send-midi-message (*metro* beat) *ableton* *midi-start* 0 0 0) | |
(*midi-clock* beat)) | |
(define (*ableton-stop* beat) | |
(send-midi-message (*metro* beat) *ableton* *midi-stop* 0 0 0) | |
(callback (*metro* beat) | |
(lambda () | |
(set! *midi-clock-state* #f)))) | |
;; Like this: | |
(*ableton-start* (*next-bar*)) | |
(*ableton-stop* (*next-bar*)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment