event-test.lsp

Return the nth non-rest event, useful for adding antescofo messages.
Turns out there is already a similar (i.e. better) method that comes with sc written by Mike called next-event.

sc-web-bar

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; File:   event-test.lsp
;;;
;;; Author: Daniel James Ross (mr.danielross@gmail.com)
;;;
;;; Date:   Sat Jan 17 14:03:51 GMT 2015
;;;
;;; Purpose:
;;;
;;; A short piece of code that ensures that the event to which
;;; we are adding an antescofo messages is also a note event,
;;; i.e. making sure we are not adding antescofo messages to 
;;; rests. Useful for algorithmically adding messages and 
;;; labels, see example below.
;;;
;;; Antescofo messages and labels can be added to event objects
;;; using (get-event ...), but not (get-note ...) as it returns
;;; different data. (event-test ...) tests to see if the result
;;; of (get-event ...) is a rest. If it is, it moves onto the 
;;; next event and tests that, and so on until it reaches a 
;;; non-rest event. It returns an event object.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DJR - Wed Sep 23 09:11:48 BST 2015
;; Have made this a method rather than a function on the 
;; advice of Mike, though I don't quite understand all the 
;; nuanced differences.
;; In his own words:
;; "the method will only be called if the first arg is an sc
;; object and you'll get a useful error msg if not (as it 
;; won't find another method that works with the argument 
;; types)"

(defmethod event-test ((sc slippery-chicken) bar event ins)
 ; arguments: sc object; bar number; the first event to start
 ; testing from (usually 1); instrument
  (let ((e (get-event sc bar event ins)))
   (if (is-whole-bar-rest e)
    (progn (setq bar (1+ bar-num))
     (event-test sc bar event ins))
    (if (is-rest e)
     (progn (setq event (1+ event))
      (event-test sc bar event ins))
     e))))

;; Example using an adapted and simplified version of Michael
;; Edwards' template.lsp to show (event-test ...) at work.

#|
(in-package :sc)
(in-scale :chromatic)

(make-slippery-chicken  
 '+your-title-here+ 
 :title "Your Title Here" 
 :composer "Your Name Here"
 :ensemble '(((flt (flute :midi-channel 1))))
 :staff-groupings '(1)
 :tempo-map '((1 (q 60)))
 :set-palette '((set1 ((fs2 b2 d4 a4 d5 e5 a5 d6))) 
                (set2 ((b2 fs3 d4 e4 a4 d5 e5 a5 d6))))
 :set-map '((1 (set1 set1 set2 set1 set1 set2)))
 :rthm-seq-palette
 '((seq1 ((((4 4) (q) (q) q q))   
          :pitch-seq-palette (1 2)))  
   (seq2 ((((4 4) (e) e q h)) 
          :pitch-seq-palette (1 2 3))))
 :rthm-seq-map
 '((1 ((flt (seq1 seq1 seq2 seq1 seq1 seq2))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Ading Antescofo messages using (event-test ...) in a loop

(loop for i from 1 to (num-seqs +your-title-here+ 1)
   for bn = (get-bar-num-from-ref +your-title-here+ 1 i 1)
   for event = (event-test +your-title-here+ bn 1 'flt)
   do
   (setf (asco-label event)
         "This is an antescofo LABEL")
   (push "This is an antescofo MESSAGE"
         (asco-msgs event)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Media content generation:

(write-antescofo +your-title-here+ 'flt
   :file "/tmp/your-title-here.txt")

(midi-play +your-title-here+ 
   :midi-file "/tmp/your-title-here.mid")

;;; cmn score
;;; #+ notation means only run the next Lisp form if e.g. 
;;; the CMN package is available  
#+cmn (cmn-display +your-title-here+ 
         :file "/tmp/your-title-here.eps")
|#

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; EOF event-test.lsp
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s