Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Carlo Laurenzi
StroppaLibs
Commits
84a41950
Commit
84a41950
authored
Jul 06, 2015
by
Arshia Cont
Browse files
HarmLib: Better modularizations
parent
38540a23
Changes
5
Hide whitespace changes
Inline
Side-by-side
Stroppa-HarmLib/HarmControl.js
View file @
84a41950
...
...
@@ -11,12 +11,15 @@ outlets = 0;
var
numHarms
=
4
;
var
theWindowSize
=
4096
;
var
theOverlapFactor
=
4
;
var
theNameSpace
;
var
theNameSpace
=
'
hr
'
;
// parent elements
var
theMainInlet
;
var
theMainOutlet
;
var
theReceiveTildes
=
new
Array
(
64
);
var
theSendTildes
=
new
Array
(
64
);
var
HarmPatchers
=
new
Array
(
64
);
var
MuteToggles
=
new
Array
(
64
);
var
GlobalGainReceive
;
var
GlobalGainMult
;
var
GlobalGainMess
;
...
...
@@ -62,6 +65,9 @@ function Harms(val)
for
(
k
=
0
;
k
<
numHarms
;
k
++
)
{
this
.
patcher
.
remove
(
HarmPatchers
[
k
]);
this
.
patcher
.
remove
(
MuteToggles
[
k
]);
this
.
patcher
.
remove
(
theReceiveTildes
[
k
]);
this
.
patcher
.
remove
(
theSendTildes
[
k
]);
}
// Create patcher
...
...
@@ -70,27 +76,34 @@ function Harms(val)
theMainOutlet
=
this
.
patcher
.
newdefault
(
20
,
300
,
"
outlet
"
);
var
sendt
=
theNameSpace
+
'
-out
'
;
theSendTilde
=
this
.
patcher
.
newdefault
(
100
,
300
,
"
send~
"
,
sendt
);
// Global Gain Control
GlobalGainReceive
=
this
.
patcher
.
newdefault
(
500
,
25
,
"
receive
"
,
'
hr-out-gain
'
);
GlobalGainMess
=
this
.
patcher
.
newobject
(
"
message
"
,
500
,
50
,
90
,
15
,
"
$1 30
"
);
GlobalGainLine
=
this
.
patcher
.
newdefault
(
500
,
75
,
"
line~
"
);
GlobalGainMult
=
this
.
patcher
.
newdefault
(
20
,
250
,
"
*~
"
,
0.01
);
this
.
patcher
.
connect
(
GlobalGainReceive
,
0
,
GlobalGainMess
,
0
);
this
.
patcher
.
connect
(
GlobalGainMess
,
0
,
GlobalGainLine
,
0
);
this
.
patcher
.
connect
(
GlobalGainLine
,
0
,
GlobalGainMult
,
1
);
for
(
i
=
0
;
i
<
numHarms
;
i
++
)
{
var
snum
=
'
harm
'
+
(
i
+
1
);
var
sin
=
theNameSpace
+
(
i
+
1
)
+
'
-in
'
;
// receive~ input name
var
sout
=
theNameSpace
+
(
i
+
1
)
+
'
-out
'
;
// send~ output name
theReceiveTildes
[
i
]
=
this
.
patcher
.
newdefault
(
20
+
(
i
*
100
),
150
,
"
receive~
"
,
sin
);
var
snum
=
'
harm
'
+
(
i
+
1
);
// patcher name
HarmPatchers
[
i
]
=
this
.
patcher
.
newdefault
(
20
+
(
i
*
100
),
175
,
"
patcher
"
,
snum
);
HarmPatchers
[
i
].
subpatcher
().
wind
.
visible
=
0
;
// hide them!
HarmCreator
(
HarmPatchers
[
i
].
subpatcher
(),
i
);
MuteToggles
[
i
]
=
this
.
patcher
.
newdefault
(
100
+
(
i
*
100
),
200
,
"
toggle
"
);
theSendTildes
[
i
]
=
this
.
patcher
.
newdefault
(
20
+
(
i
*
100
),
200
,
"
send~
"
,
sout
);
// Create connections
this
.
patcher
.
connect
(
theReceiveTildes
[
i
],
0
,
HarmPatchers
[
i
],
0
);
this
.
patcher
.
connect
(
theMainInlet
,
0
,
HarmPatchers
[
i
],
0
);
this
.
patcher
.
connect
(
HarmPatchers
[
i
],
0
,
GlobalGainMult
,
0
);
this
.
patcher
.
connect
(
HarmPatchers
[
i
],
0
,
theSendTildes
[
i
],
0
);
this
.
patcher
.
connect
(
HarmPatchers
[
i
],
1
,
MuteToggles
[
i
],
0
);
this
.
patcher
.
connect
(
GlobalGainMult
,
0
,
theMainOutlet
,
0
);
this
.
patcher
.
connect
(
GlobalGainMult
,
0
,
theSendTilde
,
0
);
// Global Gain Control
GlobalGainReceive
=
this
.
patcher
.
newdefault
(
100
,
100
,
"
receive
"
,
'
hr-out-gain
'
);
GlobalGainMess
=
this
.
patcher
.
newobject
(
"
message
"
,
100
,
125
,
90
,
15
,
"
$1 30
"
);
GlobalGainLine
=
this
.
patcher
.
newdefault
(
100
,
150
,
"
line~
"
);
this
.
patcher
.
connect
(
GlobalGainReceive
,
0
,
GlobalGainMess
,
0
);
this
.
patcher
.
connect
(
GlobalGainMess
,
0
,
GlobalGainLine
,
0
);
this
.
patcher
.
connect
(
GlobalGainLine
,
0
,
GlobalGainMult
,
1
);
}
}
else
...
...
@@ -109,8 +122,8 @@ function HarmCreator(thispatcher, u)
thispatcher
.
connect
(
AudioInlet
[
u
],
0
,
thePffts
[
u
],
0
);
// build variable names
var
interval_var
=
'
hr
'
+
(
u
+
1
)
+
'
-interval
'
;
var
gain_var
=
'
hr
'
+
(
u
+
1
)
+
'
-gain
'
;
var
interval_var
=
theNameSpace
+
(
u
+
1
)
+
'
-interval
'
;
var
gain_var
=
theNameSpace
+
(
u
+
1
)
+
'
-gain
'
;
theIntervalReceivers
[
u
]
=
thispatcher
.
newdefault
(
100
,
20
,
"
receive
"
,
interval_var
);
theGainReceivers
[
u
]
=
thispatcher
.
newdefault
(
50
,
200
,
"
receive
"
,
gain_var
);
...
...
@@ -132,7 +145,8 @@ function HarmCreator(thispatcher, u)
thispatcher
.
connect
(
routo
,
0
,
messo
,
0
);
thispatcher
.
connect
(
routo
,
1
,
thePffts
[
u
],
1
);
thispatcher
.
connect
(
messo
,
0
,
thePffts
[
u
],
0
);
var
toggleoutlet
=
thispatcher
.
newdefault
(
150
,
100
,
"
outlet
"
);
thispatcher
.
connect
(
routo
,
0
,
toggleoutlet
,
0
);
}
...
...
Stroppa-HarmLib/HarmControl.maxpat
View file @
84a41950
...
...
@@ -36,9 +36,8 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 191.0, 421.0, 113.0, 18.0 ],
"presentation_rect" : [ 187.0, 423.0, 0.0, 0.0 ],
"text" : "NameSpace harms"
"patching_rect" : [ 191.0, 421.0, 91.0, 18.0 ],
"text" : "NameSpace hr"
}
}
...
...
Stroppa-HarmLib/HarmLib-Test1.txt
View file @
84a41950
...
...
@@ -2,22 +2,28 @@ BPM 60
;;;; Performing general tests on Table operations for debugging
print General Tests
$a := 33
print ("abc"+$a)
$t := [$x | $x in 1 .. 20 : 2] ;; creates impair numbers up to 10
print Table: ($t)
print Lace test of 3: (@lace($t, 3))
;$index := [1,3,4]
;print Subindexing: ($t[($index)])
$t := [1, 2, 3, 4, 5]
print (@lace($t, 3))
;$u := 1
;curve @command("hr"+$u+"-gain") 0.0, 1.0 1.0
;;;;;;;;; Load Library
@INSERT "zInclude/Lib_Stroppa-harms1.txt"
;;print Db -6.0 gives (@db2linear(-6.0))
curve hr-out-gain 0.0, 0.9 3.0
;;;;;;;;;;;; INITIALIZATIONS
::InitHarms(3)
::InitHarms(5)
::trans([100, -100],3.0)
::trans([100, -100],0.0)
2.0 abort ::trans
print called abort??
NOTE C4 5.0
...
...
Stroppa-HarmLib/Stroppa-HarmLibs-test1.maxpat
View file @
84a41950
...
...
@@ -28,6 +28,37 @@
"digest" : "",
"tags" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-11",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 621.0, 197.0, 81.0, 20.0 ],
"presentation" : 1,
"presentation_rect" : [ 549.0, 184.0, 81.0, 20.0 ],
"text" : "print hr1-gain"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-14",
"maxclass" : "newobj",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 621.0, 163.0, 62.0, 20.0 ],
"presentation" : 1,
"presentation_rect" : [ 549.0, 150.0, 62.0, 20.0 ],
"text" : "r hr1-gain"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
...
...
@@ -69,10 +100,10 @@
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "signal" ],
"patching_rect" : [ 894.5, 599.0, 1
89
.0, 22.0 ],
"patching_rect" : [ 894.5, 599.0, 1
61
.0, 22.0 ],
"presentation" : 1,
"presentation_rect" : [ 541.5, 21.0, 1
89
.0, 22.0 ],
"text" : "HarmControl 5 4096 h
arms
"
"presentation_rect" : [ 541.5, 21.0, 1
61
.0, 22.0 ],
"text" : "HarmControl 5 4096 h
r
"
}
}
...
...
@@ -924,7 +955,7 @@
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-43",
"items" : [ "info", ",", "actions", "off", ",", "actions", "on", ",", "reloadscore" ],
"items" : [ "info", ",", "actions", "off", ",", "actions", "on", ",", "reloadscore"
, ",", "printactions", ",", "printscore"
],
"maxclass" : "umenu",
"numinlets" : 1,
"numoutlets" : 3,
...
...
@@ -1749,7 +1780,6 @@
"presentation" : 1,
"presentation_rect" : [ 17.0, 88.0, 386.0, 25.0 ],
"saved_object_attributes" : {
"Warning" : 1,
"ascograph_height" : 768,
"ascograph_width" : 1024,
"ascographpanel" : 1,
...
...
@@ -1821,6 +1851,15 @@
"source" : [ "obj-12", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-14", 0 ]
}
}
, {
"patchline" : {
...
...
@@ -2193,14 +2232,14 @@
}
],
"parameters" : {
"obj-76::obj-32" : [ "[8]", "[2]", 0 ],
"obj-84::obj-35" : [ "[10]", "Level", 0 ],
"obj-25" : [ "harms.gain~", "harms.gain~", 0 ],
"obj-84::obj-32" : [ "[9]", "[2]", 0 ],
"obj-76::obj-21::obj-6" : [ "live.tab[3]", "live.tab[1]", 0 ],
"obj-25" : [ "harms.gain~", "harms.gain~", 0 ],
"obj-76::obj-35" : [ "[5]", "Level", 0 ],
"obj-4" : [ "Amplification", "Amplification", 0 ],
"obj-84::obj-21::obj-6" : [ "live.tab[1]", "live.tab[1]", 0 ],
"obj-76::obj-35" : [ "[5]", "Level", 0 ]
"obj-76::obj-32" : [ "[8]", "[2]", 0 ],
"obj-84::obj-35" : [ "[10]", "Level", 0 ]
}
,
"dependency_cache" : [ {
...
...
Stroppa-HarmLib/zInclude/Lib_Stroppa-harms1.txt
View file @
84a41950
...
...
@@ -4,23 +4,6 @@
Gain Control in DB (0.0 is linear 1.0)
*/
;;; User function converting DB value to Linear Gain values
@fun_def db2linear($db)
{
if ($db <= -120.0)
{
return 0.0
}else
{
return @pow(10, ($db/20.0))
}
}
@fun_def midi2pitchfactor($midiv)
{
return (@pow(2., ( ($midiv)/100.0)/12.0))
}
; Initialize and (re)construct $source structure
@proc_def ::InitHarms($NumberOfSources)
{
...
...
@@ -33,12 +16,15 @@
$t := tab [$x | $x in $NumberOfSources]
forall $x in $t
{
@command("hr"+($x+1)+"-gain") 0.0 ; linear
curve @command("hr"+($x+1)+"-gain") 0.0, 0.0 50ms
;@command("hr"+($x+1)+"-gain") 0.0 ; linear
@command("hr"+($x+1)+"-interval") mute 1
}
hr-out-gain 0.0 ;; turns off global gain (linear)
}
$MINIMUM_HARM_DBLEVEL := -120.0
;;;;;;;;; Definition of global variables for Harmonizers
; define $initlevels here in case it is undefined. User definition SHOULD come next (after @include)
if (@is_undef($harmintervals))
...
...
@@ -53,19 +39,19 @@ if (@is_undef($harmgains))
$harmgains := tab [ ]
}
$harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
;
$harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
; db = 20*log(linear)
; linear = 10^(db/20)
;; Convenience macros for each harmonizer
/*
@macro_def harm($num,$x)
@macro_def harm($num,$x)
{
;;; Set local level value and shut off if zero
if ($x=0.0)
{
@command("hr"+$num+"-gain") @db2linear(
-120
)
@command("hr"+$num+"-interval") mute 1
@command("hr"+$num+"-gain") @db2linear(
$MINIMUM_HARM_DBLEVEL
)
50ms
@command("hr"+$num+"-interval") mute 1
}else
{
@command("hr"+$num+"-interval") mute 0
...
...
@@ -74,17 +60,150 @@ $harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
;;; Set harm value
@command("hr"+$num+"-interval") (@pow(2., ( $x/100.0)/12.0))
let $harmintervals[($num-1)] := $x
}
*/
}
/* Trans process
/* Transposition Automation process on Intervals with Passive Gains
* Arguments:
* $transtab: table consisting of destination values.
* $dur: duration for interpolation
* Note: Functions on the FIRST elements of harmonizers. Meanign that a tab of [100, -100] will only work on harmonizer 1 and 2
* Always departs from last value of the harmonizer table $harmvals
* Aborting the process will set all values back to 0.0 after fadeout
*
*/
@PROC_DEF trans($transp, $dur)
@abort :=
{
print Aborting ($transp_temp)
@local $initkoo, $fadeout, $tt, $koo
$initkoo := (@lace($harmgains, @size($transp)))
$fadeout := [ ($MINIMUM_HARM_DBLEVEL) | (@size($transp_temp)) ]
print INITKOO ($initkoo) ____ FADEOUT ($fadeout)
; use a curve to set gain to $MINIMUM_HARM_DBLEVEL
curve abortfoo @grain := 0.03s,
@action :=
{
print in Curve with initial value (@lace($initkoo, @size($transp))) and ending at ($fadeout) _ shutting down with ($koo)
$tt := tab [$u | $u in (@size($transp_temp)) ]
forall $u in $tt
{
::set_harmgain( ($u+1), ($koo[$u]))
}
}
{
$koo
{
{ ($initkoo) }
90ms { ($fadeout) }
}
}
;curve @command("hr"+($u+1)+"-gain") 0.0 50ms
;90ms ::set_harminterval( ($u+1), @midi2pitchfactor(0.0))
abort trans_curve
}
{
$harmnorm := (20* @log10(1.0/@size($transp)))
print normalization factor is ($harmnorm) for (@size($transp)) voices
@local $transp_temp
$transp_temp := $transp
;print Trans request on ($transp)
;;; launch curve interpolation
curve trans_curve @grain := 0.03s,
@action :=
{
$t := tab [$u | $u in (@size($transp))]
forall $u in $t
{
@command("hr"+($u+1)+"-interval") mute 0
::set_harminterval($u+1, $xcurve[$u])
::set_harmgain($u+1, $harmnorm)
print Sending ((@midi2pitchfactor(($xcurve[$u])))) to Harm Number ($u+1)
}
}
{
$xcurve
{
{ (@lace($harmintervals, @size($transp))) } ; @lace($t, 3)
$dur { ($transp) }
}
}
}
/* Transposition Automation process on Intervals with NO EFFECT on Gains
* Arguments:
* $destinations: table consisting of indexes. Ex: [1, 3, 5] indicates targetting harmonizers 1, 3 and 5
* $intervals: table indicating target intervals for destinations. Ex: [-100, 100, 300] - Should have same # of elements as in $destinations
* $dur: duration for interpolation
* Note: Always departs from last value of the harmonizer table $harmvals
* Aborting the process will set all values back to 0.0 after fadeout
*
*/
@PROC_DEF trans($transp, $dur)
@PROC_DEF transinterval($destinations, $intervals, $dur)
@abort :=
{
print abort request on trans
$t := tab [$u | $u in (@size(@harmgains)) ]
forall $u in $t
{
;@harm(($u+1), 0.0)
print Supposed to ABORT!
}
}
{
;print transp size is (@size($transp)) _ harmvalues size is (@size($harmvalues))
;;; prepare destination
; if input table does not have size of global harms, then convert it so by adding zeros
; This is also the place to turn harmonizers ON/OFF automatically if need be.
@local $transdest, $transint
if ( (@size($destination)) != @size($intervals))
{
print ERROR IN TRANSINTERVAL CALL: Table mismatch
}
$transint := $intervals
$transdest := $destinations
;print Trans request on ($transp)
;;; launch curve interpolation
curve trans_int @grain := 0.03s,
@action :=
{
forall $u in $transdest
{
@command("hr"+($u)+"-interval") mute 0
::set_harminterval($u, $xcurve[$u])
;print Sending ((@midi2pitchfactor(($xcurve[$u])))) to Harm Number ($u+1)
}
}
{
$xcurve
{
{ (@lace($harmintervals, @size($transp))) } ; @lace($t, 3)
$dur { ($transp) }
}
}
}
/* Transposition Automation process on Gains
* Arguments:
* $transtab: table consisting of destination values.
* $dur: duration for interpolation
* Note: Always departs from last value of the harmonizer table $harmvals
* Aborting the process will set all values back to 0.0 after fadeout
*
*/
@PROC_DEF transgain($transp, $dur)
@abort :=
{
print abort request on trans
...
...
@@ -101,14 +220,14 @@ $harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
; if input table does not have size of global harms, then convert it so by adding zeros
; This is also the place to turn harmonizers ON/OFF automatically if need be.
@local $transdest, $zerovec
if ( (@size($transp)) = @size($harmval
ue
s))
if ( (@size($transp)) = @size($harm
inter
vals))
{
$transdest := $transp
}else
{
; size of transtab should be smaller than $harmvalues.
; concatenate a zeroed vector
$zerovec := [ 0.0 | ( (@size($harmval
ue
s)-@size($transp)) ) ]
$zerovec := [ 0.0 | ( (@size($harm
inter
vals)-@size($transp)) ) ]
$transdest := @concat($transp, $zerovec)
; calculate normalization factor in db
$harmnorm := (20* @log10(1.0/@size($transp) ) )
...
...
@@ -125,7 +244,7 @@ $harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
{
@command("hr"+($u+1)+"-interval") (@midi2pitchfactor(($xcurve[$u])))
let $harmintervals[$u] := ($xcurve[$u])
print Sending ((@midi2pitchfactor(($xcurve[$u])))) to Harm Number ($u+1)
;
print Sending ((@midi2pitchfactor(($xcurve[$u])))) to Harm Number ($u+1)
}
}
{
...
...
@@ -136,3 +255,45 @@ $harmnorm := 0.0 ; harms normalization in db (0.0 is 1.0 in linear)
}
}
}
;;;;;;;;;;;;;; Library Functions
;;; User function converting DB value to Linear Gain values
@fun_def db2linear($db)
{
if ($db <= $MINIMUM_HARM_DBLEVEL)
{
return 0.0
}else
{
return @pow(10, ($db/20.0))
}
}
;;; User function converting MIDICents to PitchFactor Scale
@fun_def midi2pitchfactor($midiv)
{
return (@pow(2., ( ($midiv)/100.0)/12.0))
}
@proc_def ::set_harminterval($index, $val)
{
$harmintervals[$index-1] := $val
@command("hr"+$index+"-interval") @midi2pitchfactor($val)
}
@proc_def ::set_harmgain($index, $val)
{
$harmgains[$index-1] := $val
@command("hr"+$index+"-gain") @db2linear($val)
if ($val <= ($MINIMUM_HARM_DBLEVEL))
{
@command("hr"+$index+"-interval") mute 1
}else
{
@command("hr"+$index+"-interval") mute 0
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment