Mercurial > hg > amuse
comparison base/charm/constructors.lisp @ 253:b5ffec94ae6d
some very sketchy Charm constituent code
author | Jamie Forth <j.forth@gold.ac.uk> |
---|---|
date | Thu, 24 Feb 2011 11:23:18 +0000 |
parents | |
children | f1e6d10fdb11 |
comparison
equal
deleted
inserted
replaced
252:b518b9f904e3 | 253:b5ffec94ae6d |
---|---|
1 (cl:in-package #:amuse-charm) | |
2 | |
3 (defun make-charm-property-list (&rest properties) | |
4 (make-instance 'charm-property-list | |
5 :%data properties)) | |
6 | |
7 (defun make-charm-constituent-identifier (id) | |
8 (make-instance 'charm-constituent-identifier | |
9 :constituent-id id)) | |
10 | |
11 (defun make-standard-charm-constituent (particles parent | |
12 extrinsic-properties | |
13 intrinsic-properties &key | |
14 start duration | |
15 constituent-identifier owner | |
16 version creation-timestamp | |
17 deletion-timestamp) | |
18 "Properties should be charm-property-lists. FIXME: enforce this? | |
19 What about time? Should we be using implementation time data-types? | |
20 Particles by definition are identifiers - BUT this seemed to cause | |
21 unnecessary pain, so particales are now either events or | |
22 constituents. This could be made to call a backend specific | |
23 constructor specialised on the parent-identifier." | |
24 (make-instance 'standard-charm-constituent | |
25 :identifier constituent-identifier | |
26 :parent parent | |
27 :time start ; FIXME: naming conventions? | |
28 :interval duration | |
29 :extrinsic-properties extrinsic-properties | |
30 :intrinsic-properties intrinsic-properties | |
31 :%data particles | |
32 :owner owner | |
33 :version version | |
34 :creation-timestamp creation-timestamp | |
35 :deletion-timestamp deletion-timestamp)) | |
36 | |
37 (defun make-standard-charm-event-constituent (particles parent | |
38 extrinsic-properties | |
39 intrinsic-properties | |
40 &key start duration | |
41 constituent-identifier | |
42 owner version | |
43 creation-timestamp | |
44 deletion-timestamp) | |
45 (make-instance 'standard-charm-event-constituent | |
46 :identifier constituent-identifier | |
47 :parent parent | |
48 :time start ; FIXME: naming conventions? | |
49 :interval duration | |
50 :extrinsic-properties extrinsic-properties | |
51 :intrinsic-properties intrinsic-properties | |
52 :%data particles | |
53 :owner owner | |
54 :version version | |
55 :creation-timestamp creation-timestamp | |
56 :deletion-timestamp deletion-timestamp)) | |
57 | |
58 (defun composition->charm-constituent (composition | |
59 extrinsic-properties | |
60 intrinsic-properties) | |
61 "This is currently the bridge that takes us from AMuSE compositions | |
62 to Charm constituents." | |
63 (make-standard-charm-event-constituent (%list-slot-sequence-data | |
64 composition) composition | |
65 extrinsic-properties | |
66 intrinsic-properties | |
67 :start (timepoint | |
68 composition) | |
69 :duration (duration | |
70 composition))) | |
71 | |
72 (defun make-onset-segment-constituent (composition) | |
73 "So this makes a constituent for each set of events with the same | |
74 onset, and adds all of those as particles to a parent constituent. To | |
75 two levels are created, maybe it's better to only return a list of | |
76 onset-constituents, and the user can group them together within | |
77 another constituent if necessary?" | |
78 (let ((grouped-events (group-by-onset composition)) | |
79 (parent-constituent | |
80 (make-standard-charm-constituent nil composition | |
81 (make-charm-property-list | |
82 'sequence-class) | |
83 (make-charm-property-list | |
84 'sequence-class) | |
85 :start (timepoint | |
86 composition) | |
87 :duration (duration | |
88 composition)))) | |
89 (loop for beat-events in grouped-events | |
90 collect (make-standard-charm-event-constituent | |
91 beat-events | |
92 parent-constituent | |
93 (make-charm-property-list 'segment) | |
94 (make-charm-property-list 'onset-segment)) | |
95 into constituents | |
96 finally (progn | |
97 (setf (%list-slot-sequence-data parent-constituent) | |
98 constituents) | |
99 (return parent-constituent))))) | |
100 | |
101 (defun group-by-onset (composition) | |
102 (loop for event in (reverse (%list-slot-sequence-data composition)) | |
103 with grouped-events | |
104 do (if (and grouped-events | |
105 (time= (onset event) (onset (car (car grouped-events))))) | |
106 (push event (car grouped-events)) | |
107 (push (list event) grouped-events)) | |
108 finally (return grouped-events))) | |
109 | |
110 (defun segment-at-bar (composition) | |
111 "Returns a list of bar-constituents." | |
112 (loop with current-bar = (current-bar (elt composition 0) composition) and current-events | |
113 for event in (%list-slot-sequence-data composition) | |
114 if (time= current-bar (current-bar event composition)) | |
115 do (push event current-events) | |
116 else | |
117 collect (make-standard-charm-event-constituent | |
118 (reverse current-events) | |
119 composition | |
120 (make-charm-property-list) | |
121 (make-charm-property-list 'segment 'bar)) | |
122 into constituents | |
123 and do (setf current-bar (current-bar event composition)) | |
124 and do (setf current-events nil) | |
125 finally (return constituents))) |