[CM] Simple example

Matti Koskinen squarewave at elisanet.fi
Sat Mar 12 22:05:19 PST 2022


Found a solution, surely not the most elegant one, but seems to work:

;
;; Receiving MIDI Input
;


; Here is the definition of a MIDI receiver that routes midi on and
; off messages to the output port and as alist to *m* global variable
(define *m* (list (now)))

(define (myplayer data)
  (let* ((opcode (first data))
         (channel (second data))
         (keyn (third data))
         (velocity (fourth data)))
    (set! *m* (append *m* (list (list data  (now)))))
    (if (= opcode mm:on)
        (mp:on :time (now) :key keyn :vel velocity :chan channel)
    (if (= opcode mm:off)
        (mp:off :key keyn :chan channel)))))

; Set receiver, then play your midi keyboard

(mp:receive myplayer)


; When you are done clear it...

(mp:receive #f)

;save the *m* to a file
(define (play-it-again-sam file)
    
  (sprout (let* ((notes (rest *m*))
              (wasnow (first *m*)))
             
  (process for d in notes do
           (print  d)
           (let* ((data (first d))
                  (op (first data))
                  (ch (second data))
                  (keyn (third data))
                  (veloc(fourth data)))
             (if (= op mm:on)
               (mp:on :time (- wasnow (last d)) :chan ch
                      :key keyn :vel veloc))
             (if (= op mm:off)
               (mp:off :time (- wasnow (last d)) 
                       :chan ch :key keyn))))) file))
;test it
(play-it-again-sam "ts3.mid")


> On 11. Mar 2022, at 18.41, Matti Koskinen <squarewave at elisanet.fi> wrote:
> 
> Hi all,
> 
> I got Grace compiled and it works, but since I’ve used it many years ago, can’t remember anything at all. 
> If someone could post a simple example how to read midi from keyboard and save it to a midi file, I’d be more than happy.
> 
> Thanks 
> 
> -m
> 
> 
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> https://cm-mail.stanford.edu/mailman/listinfo/cmdist




More information about the Cmdist mailing list