Newer
Older
Marco Stroppa
committed
; SPATIAL LIBRARY FOR STROPPA ANTESCOFO/MAX LIBRARIES
; Last update: 24/02/2016
Arshia Cont
committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* NOTES:
This library uses an Antescofo map called $initlevels that contains destinations (as key strings)
and their coordinates (as value tables).
It should be defined by user.
Definition example:
$initlevels := map {
("FadeOut", [0., 0., 0., 0., 0.]),
("Left", [0., 1., 0., 0., 0.])
}
*/
; Initialize and (re)construct $source structure
@proc_def ::InitSources($NumberOfSources, $NumberOfSpeakers, $Namespace)
{
abort (obj::source)
;; Stores addresses of each object...
$source := [0.0 | ($NumberOfSources)]
;; (re)instantiate source objects and store them somewhere!
$t := tab [$x | $x in $NumberOfSources]
forall $x in $t
{
$source[$x] := obj::source($x, $NumberOfSpeakers, $Namespace)
}
print Created @size($source) Spatial Sources with @size($source[1].$coordinates) points
}
; define $initlevels here in case it is undefined. User definition SHOULD come next (after @include)
if (@is_undef($initlevels))
{
print SPAT LIB: initlevels was set to empty
$initlevels := map { }
}
; define $source here in case it is undefined. User definition SHOULD come next (after @include)
if (@is_undef($source))
{
; defines vector of source addresses
$source := [0.0 | (10)]
}
; SOURCE Object Definition
@obj_def source($idn, $npoints, $namespace)
{
; Create local variables that are specific to each instance of the object
@local $coordinates, $idnum, $last_action, $prefix_namespace
;@local $coordinates ; This is where we store local coordinates of this source. This is always a variable table whose length is equal to # of speakers
;@local $idnum ; ID Number of the receiver in patch
;@local $last_action ; store the address of last action for aborts etc.
;@local $prefix_namespace ; string used to build send-symbol for Max/pd as $prefix_namespace+$idnum+"-spat"
;; Object @init is automatically called when the object is created
@init
{
$idnum := $idn
$coordinates := [0.0 | ($npoints)] ; create a table of zeros
$prefix_namespace := $namespace
}
;; A broadcasted signal to all instances of source objects. Useful in panics!
@broadcast reset()
{
;; abort ongoing curves or processes
abort $last_action
}
;; Defining an abort will do additional actions when this object is aborted/killed. Useful for specific temrinal operations.
@abort
{
print "Source " ($idnum) " is killed!"
abort $last_action
}
;;;;;;;; User defined methods
;; goto method will create a curve that goes from $coordinates to $destination in $dur time
@proc_def goto($destination, $dur)
{
curve FlyingEngine @Grain := 0.05s,
@Action :=
{
$coordinates := $x ; store in internal/local coordinates of this source to keep track
@command($prefix_namespace+$idnum+"-spat") ($x)
}
{
$x
{
{ ($coordinates) } @type "sine_in_out"
$dur { ($initlevels($destination)) } @type "sine_in_out"
}
}
}
Marco Stroppa
committed
;; goto_i method: same as goto, but with the possibility to specify the kind of interpolation
@proc_def goto_i($destination, $dur, $itp)
{
curve FlyingEngine @Grain := 0.05s,
@Action :=
{
$coordinates := $x ; store in internal/local coordinates of this source to keep track
@command($prefix_namespace+$idnum+"-spat") ($x)
}
{
$x
{
{ ($coordinates) } @type "sine_in_out"
$dur { ($initlevels($destination)) } @type $itp
}
}
}
Arshia Cont
committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
;; Random space local method
;_________________________________________________________________________________________
/**** Random Granular Spatial Movement Process
* Arguments:
* arg1 $configs: table of string configurations from $initlevels. ex: [ "Front", "Rear", "Right"]
* arg2 $grainrange_min: float - minimum grain time
* arg3 $grainrange_max: float - maximum grain time
* arg4 $stay_percent: float (0.to 1.) - percentage of staying on selected configuration
** IMPORTANT: For now, we give time values in relative. Tempo is fixed inside as 60 BPM.
** This means that $grainrange_min 0.05 is 50ms
****/
@proc_def RandomSpace($configs, $grainrange_min, $grainrange_max, $stay_percent)
{
abort $last_action
;;; Generate first randoms:
@local $grainsize, $randomconfig
$grainsize := @random() * ($grainrange_max - $grainrange_min) + $grainrange_min
;print DEBUG: Initial grain set to ($grainsize)
$last_action :=
{
Loop L $grainsize
{
; Generate a random configuration.
$randomconfig := ($configs[@rand_int(@size($configs))])
; Make the move, in duration that is (1.0 - $stay_percent).
;$Ticket := [$snum, $randomconfig, ($grainsize*(1.0-$stay_percent))]
_ := $THISOBJ.goto( $randomconfig , ($grainsize *(1.0 - $stay_percent ) ) )
;print "DEBUG: random space with grain" ($grainsize) "on" ($randomconfig)
; Generate a new period just before this loop is finishes! Looks like a harakiri!
$grainsize $grainsize := @random() * ($grainrange_max - $grainrange_min) + $grainrange_min
}
}
}
}
;_________________________________________________________________________________________
; General SPACE Macro to assign movements to sources.
; Arguments:
; 1st argument: source number (integer)
; 2nd argument: movement type (string) --> must be in the $initlevels map. Must be wrapped in quotations
; 3rd argument: duration (float, or time in second or milli-second: ex. 3.0 or 3.0s or 3.0ms)
@macro_def Space($snum, $stype, $sdur)
{
; Call the specific GOTO method for source object $snum
_ := $source[$snum].goto($stype,$sdur)
;print Initial coordinate of source ($snum) is ($source[$snum].$coordinates)
;$sdur print Final coordinate of source ($snum) is ($source[$snum].$coordinates)
}
Marco Stroppa
committed
; SPACE_I Macro: same as SPACE with the choice of the interpolation
; Arguments:
; 1st argument: source number (integer)
; 2nd argument: movement type (string) --> must be in the $initlevels map. Must be wrapped in quotations
; 3rd argument: duration (float, or time in second or milli-second: ex. 3.0 or 3.0s or 3.0ms)
@macro_def Space_i($snum, $stype, $sdur, $itp)
{
; Call the specific GOTO method for source object $snum
_ := $source[$snum].goto_i($stype,$sdur, $itp)
;print Initial coordinate of source ($snum) is ($source[$snum].$coordinates)
;$sdur print Final coordinate of source ($snum) is ($source[$snum].$coordinates)
}
Arshia Cont
committed
;FadeOut
@macro_def FadeOut($sourcenum, $dur)
{
_ := $source[$sourcenum].goto("FadeOut",$dur)
;abort ($source[$snum])
}
//////////////////////////////////////////////////////////
Marco Stroppa
committed
; SPACE VOCABULARY: SEE EACH CONFIG FILE
Arshia Cont
committed
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++