Mercurial > hg > amuse
comparison implementations/tabcode/tabcode-import.lisp @ 43:2fd7ebed5b87
basic tabcode amuse implementation
darcs-hash:20070614145209-dc3a5-98b89c451db974b34878aae216e024e2ae38b734.gz
author | c.rhodes <c.rhodes@gold.ac.uk> |
---|---|
date | Thu, 14 Jun 2007 15:52:09 +0100 |
parents | |
children | ba65f66a713e |
comparison
equal
deleted
inserted
replaced
42:9fcb0163faba | 43:2fd7ebed5b87 |
---|---|
1 (in-package :amuse-tabcode) | |
2 | |
3 (defun word-duration (word default) | |
4 (if (typep word 'tabcode::rhythmic-word) | |
5 (let ((flag (tabcode::flag word)) | |
6 (dots (tabcode::dots word))) | |
7 (if flag | |
8 (* (car (rassoc flag tabcode::*rhythms*)) | |
9 (if dots 3/2 1)) | |
10 default)) | |
11 0)) | |
12 | |
13 (defun word-causes-stop-p (word course) | |
14 (or (typep word 'tabcode::rest) | |
15 (typep word 'tabcode::barline) | |
16 (and (typep word 'tabcode::chord) | |
17 (member course (tabcode::playing word) :key #'tabcode::course)))) | |
18 | |
19 (defun duration-for-course (course buffer start initial-duration) | |
20 (let ((duration initial-duration) | |
21 (default-duration initial-duration)) | |
22 (do ((i start (+ i 1))) | |
23 ((>= i (drei-buffer:size buffer)) duration) | |
24 (let* ((object (drei-buffer:buffer-object buffer i)) | |
25 (word (tabcode-syntax::tabword-word object))) | |
26 (when (word-causes-stop-p word course) | |
27 (return-from duration-for-course duration)) | |
28 (let ((word-duration (word-duration word default-duration))) | |
29 (incf duration word-duration) | |
30 (when (> word-duration 0) | |
31 (setf default-duration word-duration))))))) | |
32 | |
33 ;;; FIXME: like GET-COURSE-TUNING/GET-TUNING only more hardcoded | |
34 (defun fret-to-number (char) | |
35 (let ((fret-num (- (char-code char) 97))) | |
36 (cond | |
37 ((> fret-num 20) (- fret-num 2)) | |
38 ((> fret-num 8) (- fret-num 1)) | |
39 (t fret-num)))) | |
40 (defun midi-pitch-for-playing (course fret) | |
41 (let ((tuning #(67 62 57 53 48 43))) | |
42 (+ (aref tuning (1- course)) | |
43 (fret-to-number fret)))) | |
44 | |
45 (defun make-tabcode-composition (tabword-buffer) | |
46 (let ((time 0) | |
47 (notes) | |
48 (result) | |
49 (current-duration 1)) | |
50 (dotimes (i (drei-buffer:size tabword-buffer) (setq notes (nreverse result))) | |
51 (let* ((object (drei-buffer:buffer-object tabword-buffer i)) | |
52 (tabword (tabcode-syntax::tabword-word object)) | |
53 (duration (word-duration tabword current-duration))) | |
54 (when (typep tabword 'tabcode::rhythmic-word) | |
55 (setf current-duration duration)) | |
56 (when (typep tabword 'tabcode::chord) | |
57 (dolist (playing (tabcode::playing tabword)) | |
58 (let* ((course (tabcode::course playing)) | |
59 (fret (tabcode::fret playing)) | |
60 (note-duration (duration-for-course course tabword-buffer (1+ i) current-duration))) | |
61 (push (make-instance 'tabcode-pitched-event | |
62 :course course | |
63 :fret fret | |
64 :word tabword ; object? | |
65 :number (midi-pitch-for-playing course fret) | |
66 :time time | |
67 :interval note-duration) | |
68 result)))) | |
69 (incf time duration))) | |
70 (let ((composition (make-instance 'tabcode-composition | |
71 :time 0 | |
72 :interval time))) | |
73 (sequence:adjust-sequence composition (length notes) | |
74 :initial-contents notes)))) | |
75 | |
76 #| | |
77 (in-package :clim-user) | |
78 | |
79 (defvar *composition*) | |
80 | |
81 (define-command (com-set-amuse-composition | |
82 :name t :command-table tabcode-syntax::tabcode-table) | |
83 () | |
84 (let* ((window (esa:current-window)) | |
85 (buffer (drei-buffer:buffer window)) | |
86 (syntax (climacs::syntax buffer)) | |
87 (tabwords (slot-value syntax 'tabcode-syntax::tabwords))) | |
88 (setq *composition* (amuse-tabcode::make-tabcode-composition tabwords)))) | |
89 |# |