Tag Archives: velocities

The first functionality update that arose out of…

The first functionality update that arose out of the Goldsmiths symposium last weekend was a fix to the way MIDI velocities are handled. As of the latest svn-latest check-in (2 mins ago) when you call midi-play, event velocities will reflect the last dynamic seen in any given part (rather than retaining their default velocity). Also, if you have hairpins (crescendo/diminuendo marks), then the notes that are under these will have correspondingly increasing/decreasing amplitudes.

Dan’s advice is to keep Disklavier velocities to…

Dan’s advice is to keep Disklavier velocities to within the 30 to 90 range. I’ve just implemented the rescale function to help with this (see below) so if you have events with amplitudes between 0.0 and 1.0 then the following would map those to velocities of 30 to 90:

(midi-play +jitterbug+ :force-velocity
	   #'(lambda (event) 
	       (round (rescale (amplitude event) 0 1 30 90))))

;;; ****f* utilities/rescale
;;; DATE
;;; June 8th 2016, Edinburgh
;;; Given a value within an original range, return its value withing a new range
;;; - the value we want to rescale
;;; - the original minimum
;;; - the original maximum
;;; - the new minimum
;;; - the new maximum
;;; The value within the new range (a number)
(rescale .5 0 1 0 100)
==> 50.0
(defun rescale (val min max new-min new-max)
;;; ****
  (when (or (>= min max)
            (>= new-min new-max))
    (error "utilities::rescale: argument 2 (~a) must be < argument 3 (~a) ~
            ~%and sim. for argument 4 (~a) and 5 (~a)" min max new-min new-max))
  (unless (and (>= val min)
               (<= val max))
    (error "utilities::rescale: first argument (~a) must be within original ~
            range (~a to ~a)" val min max))
  (let* ((range1 (float (- max min)))
         (range2 (float (- new-max new-min)))
         (prop (float (/ (- val min) range1))))
    (+ new-min (* prop range2))))