2.4. Incudine

Start von Incudine:

;;; SLIME 2.19
CL-USER> (ql:quickload "incudine")
To load "incudine":
Load 1 ASDF system:
incudine
;;; Loading "incudine"
....
("incudine")
CL-USER> (in-package :scratch)
#<PACKAGE "INCUDINE.SCRATCH">
SCRATCH> (rt-start)
:STARTED
SCRATCH>

Definition eines Phasors:

(define-vug phasor (freq init)
  (with-samples ((phase init)
                 (inc (* freq *sample-duration*)))
    (prog1 phase
      (incf phase inc)
      (cond ((>= phase 1.0) (decf phase))
            ((minusp phase) (incf phase))))))

Definition eines Sinusoszillators und eines Oszillators mit 10 Obertönen:

(define-vug sine (freq amp phase)
  (* amp (sin (+ (* +twopi+ (phasor freq 0)) phase))))

(define-vug 10-harm (freq)
  (macrolet ((sine-sum (n)
               `(+ ,@(mapcar (lambda (x)
                               `(sine (* freq ,x) ,(/ .3 n) 0))
                             (loop for i from 1 to n collect i)))))
    (sine-sum 10)))

Definition eines DSPs (das Äquivalent zu einer 'synthdef' in SuperCollider):

(dsp! simple (freq amp)
  (out (sine freq amp 0)))

(dsp! simple-stereo (freq amp)
  (out (sine freq amp 0) (sine (+ freq 3) amp 0)))

Aufruf eines DSPs nach dessen Definition (entsprechend der 'play' Methode eines synths in SuperCollider):

(simple-stereo 440 0.1 :id 1)
SCRATCH> (control-value 1 'freq)
440.0d0
SCRATCH> (setf (control-value 1 'freq) 330)
330
SCRATCH> (free 1)

Definition eines fm-VUGs:

(define-vug fm-osc (freq amp ratio idx phase)
  (* amp (sin (+ (* +twopi+ (phasor freq 0))
                 (sine (* freq ratio) idx 0) phase))))

(define-vug fm-osc-2 (freq amp ratio idx phase)
  (* amp (sin (+ (* +twopi+ (phasor freq 0))
                 (* idx (sin (* +twopi+ (phasor (* freq ratio)))))
                 phase))))

Definition des DSPs und Aufruf:

; No value
SCRATCH> (dsp! simple-fm (freq amp ratio idx)
  (out (fm-osc freq amp (+ 1 (* (mouse-x) (- ratio 1))) (* (mouse-y) idx) 0)))
#<FUNCTION SIMPLE-FM>
SCRATCH> (simple-fm 50 0.2 50 10 :id 1)
; No value
SCRATCH> (free 1)
; No value
SCRATCH> (dotimes (x 40) (simple-fm (+ 50 (random 50.0)) 0.01 (+ 20 (random 30.0) 0) 10))
NIL
SCRATCH> (nodes-free-all)

MIDI Ein-/Ausgabe in incudine

;;; *MIDI Ein-/Ausgabe in incudine*

(defparameter *midi-out-1* (jackmidi:open :direction :output :port-name "midi_out-1"))
;;; (defparameter *midi-in-1* (jackmidi:open :direction :input :port-name "midi_in-1"))

(jackmidi:write-short *midi-out-1* (jackmidi:message 144 60 96) 3)
(jackmidi:write-short *midi-out-1* (jackmidi:message 144 60 0) 3)

(defun midi-note (&key (keynum 60) (velo 64) (dur 1))
  (jackmidi:write-short *midi-out-1* (jackmidi:message 144 keynum velo) 3)
  (at (+ (now) (* dur *sample-rate*))
    #'jackmidi:write-short *midi-out-1* (jackmidi:message 144 keynum 0) 3))

(midi-note :keynum 60)

;;; Scheduling mit "at":

(dotimes (x 20)
  (at (+ (now) (* (random 2.0) *sample-rate*))
    #'midi-note :keynum (+ 60 (random 24)) :velo 64 :dur (random 3.0)))

Schließen des Midi Ports

(jackmidi:close *midi-out-1* )

;; auch möglich:
(jackmidi:close "midi_out-1")

Beenden des rt-threads:

(rt-stop)

results matching ""

    No results matching ""