[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] SF.net SVN: quarks:[1297] Ctk/Ctk classes
Revision: 1297
http://quarks.svn.sourceforge.net/quarks/?rev=1297&view=rev
Author: joshpar
Date: 2009-12-18 16:31:44 +0000 (Fri, 18 Dec 2009)
Log Message:
-----------
various Ctk/Ntk updates
Modified Paths:
--------------
Ctk/Ctk classes/CTK.sc
Ctk/Ctk classes/LP.sc
Ctk/Ctk classes/PitchClass.sc
Ctk/Ctk classes/addSimpleNumber.sc
Modified: Ctk/Ctk classes/CTK.sc
===================================================================
--- Ctk/Ctk classes/CTK.sc 2009-12-18 13:29:15 UTC (rev 1296)
+++ Ctk/Ctk classes/CTK.sc 2009-12-18 16:31:44 UTC (rev 1297)
@@ -63,13 +63,14 @@
var <masterScore, <allScores, <masterNotes, <masterControls, <masterBuffers,
<masterGroups, <masterMessages, cmdPeriod;
-
*new {arg ... events;
^super.new.init(events);
}
init {arg events;
masterScore = [];
+ // I think this is where the mem leak comes in... all CtkObjs create this
+ // Dictionary - and this is bad.
objargs = Dictionary.new;
score = Score.new;
ctkscores = Array.new;
@@ -187,9 +188,10 @@
addBuffers {
buffersScored.not.if({
+ endtime = endtime + 0.1;
buffers.do({arg me;
this.add(CtkMsg(me.server, 0.0, me.bundle).bufflag_(true));
- this.add(CtkMsg(me.server, endtime + 0.1, me.freeBundle));
+ this.add(CtkMsg(me.server, endtime, me.freeBundle));
(me.closeBundle.notNil).if({
this.add(CtkMsg(me.server, endtime, me.closeBundle));
});
@@ -595,7 +597,7 @@
this.buildControls;
}, {
synthdef = sd.def;
- args = Dictionary.new;
+ args = IdentityDictionary.new;
synthdefname = synthdef.name;
count = 0;
namesAndPos = [];
@@ -653,7 +655,7 @@
buildControls {
var kouts;
synthdef.load(server ?? {Server.default});
- args = Dictionary.new;
+ args = IdentityDictionary.new;
synthdefname = synthdef.name;
synthdef.allControlNames.do({arg ctl, i;
var def, name = ctl.name;
@@ -1279,6 +1281,9 @@
(aValue.duration.notNil and:
{duration.notNil and: {aValue.duration > duration}}).if({
aValue.duration_(duration);
+ });
+ (aValue.duration.isNil and: {duration.notNil}).if({
+ aValue.duration_(duration)
})
})
}
@@ -2090,7 +2095,9 @@
*initClass {
var thisctkno;
- sddict = CtkProtoNotes(
+// "Adding Ctk Notes".postln;
+ sddict = CtkProtoNotes.new;
+ sddict.add(
SynthDef(\ctkenv, {arg gate = 1, outbus, levelScale = 1, levelBias = 0,
timeScale = 1, doneAction = 0;
Out.kr(outbus,
Modified: Ctk/Ctk classes/LP.sc
===================================================================
--- Ctk/Ctk classes/LP.sc 2009-12-18 13:29:15 UTC (rev 1296)
+++ Ctk/Ctk classes/LP.sc 2009-12-18 16:31:44 UTC (rev 1297)
@@ -306,7 +306,7 @@
file.write("\n");
});
score.do({arg part, i;
- file.write("%Voice" ++ i ++"\n");
+ file.write("%Voice" ++ i ++"\n");
part.output(file, this);
});
file.write("\\score {\n");
@@ -314,6 +314,9 @@
score.do({arg part, i;
// score contains parts - each part gets an opening '<<' and closing '>>'
file.write("\t\\new Staff = \""++ part.id.asString ++ "\" <<\n");
+ part.partFunctions.do({arg me;
+ file.write("\t\t"++me++"\n");
+ });
part.headOutput(file, this);
part.voices.do({arg voice;
file.write("\t\t\\"++voice.id++"\n");
@@ -384,7 +387,7 @@
LPPart : LPObj {
var <voices, <>clef, <>timeSig, <>keySig, <>id, <>spatial = false;
var showClef, showTimeSig, showKeySig, showBarLine, <>staffLines = 5;
- var <instrumentName, <shortInstrumentName;
+ var <instrumentName, <shortInstrumentName, <partFunctions;
*new {arg id, clef, timeSig, keySig, voice;
^super.new.initLPPart(id, voice, clef, timeSig, keySig);
@@ -393,6 +396,7 @@
initLPPart {arg argID, argVoice, argClef, argTimeSig, argKeySig;
id = argID;
voices = [];
+ partFunctions = [];
argVoice.isNil.if({
this.addVoice(LPVoice(id))
}, {
@@ -427,7 +431,17 @@
this.showBarLine_(showBars);
spatial = true
}
-
+
+ addFunction {arg functionString ... args;
+ var str;
+ str = "#("++functionString;
+ args.do({arg me;
+ str = str + "'"++me;
+ });
+ str = str +")";
+ partFunctions = partFunctions.add(str);
+ }
+
showClef_ {arg bool = true; showClef = bool}
showKeySig_ {arg bool = true; showKeySig = bool}
showTimeSig_ {arg bool = true; showTimeSig = bool}
@@ -455,7 +469,7 @@
addToVoice {arg voice ... events;
voices[voice].add(*events);
}
-
+
output {arg file, score;
voices.do({arg me;
me.output(file, score)
@@ -927,7 +941,6 @@
// this needs to allow chords
note_ {arg ... aPitchClass;
- var rem;
aPitchClass = aPitchClass.flat;
note = Array.newClear(aPitchClass.size);
// then, fill note... need to parse note correclt later
@@ -936,9 +949,7 @@
{thisPC.isKindOf(SimpleNumber)}
{
// check if there is an alteration... round to quarter-tones for now?
- rem = (thisPC % 1.0).round(0.5);
- thisPC = thisPC.trunc;
- note[i] = PitchClass(thisPC, alter: rem);
+ note[i] = PitchClass(thisPC);
}
{thisPC.isKindOf(Symbol)}
{note[i] = PitchClass(thisPC)}
Modified: Ctk/Ctk classes/PitchClass.sc
===================================================================
--- Ctk/Ctk classes/PitchClass.sc 2009-12-18 13:29:15 UTC (rev 1296)
+++ Ctk/Ctk classes/PitchClass.sc 2009-12-18 16:31:44 UTC (rev 1297)
@@ -101,7 +101,51 @@
change = this.keynum - center * 2;
^this.class.new(this.keynum - change)
}
+
+ mapIntoRange {arg range = 6, target, numturns = 0, maxturns = 10, origval;
+ var newtestval, targetkey, rangesteps;
+ origval = origval ?? {this};
+ targetkey = target.keynum;
+ rangesteps = range.halfsteps;
+ (numturns < maxturns).if({
+ ((keynum - targetkey).abs > rangesteps).if({
+ newtestval = (keynum > targetkey).if({
+ PC(pitch, octave - 1, alter)
+ }, {
+ PC(pitch, octave + 1, alter)
+ });
+ ^newtestval.mapIntoRange(range, target, numturns + 1, maxturns, origval);
+ }, {
+ ^this
+ });
+ }, {
+ "Your PitchClass couldn't be wrapped into the desired range. Check your parameters or increase maxturns.".warn;
+ ^origval;
+ })
+ }
+
+ mapIntoBounds {arg low, high;
+ var tmp, dif, lowkey, highkey;
+ ((lowkey = low.keynum) > (highkey = high.keynum)).if({
+ tmp = high;
+ high = low;
+ low = tmp;
+ });
+ dif = highkey - lowkey * 0.5;
+ ^this.mapIntoRange(dif, lowkey + dif);
+ }
+ /*
+ a = PC(\fs, 8).mapIntoRange(6, PC(\c, 4));
+ a.octave;
+ a.pitch;
+
+ a = PC(\fs, 8).mapIntoBounds(PC(\cdfs, 3), PC(\c, 4));
+ a.octave;
+ a.pitch;
+ \fs4.mapIntoRange
+ */
+
// // direction should be \up or \down - aPitchInterval can be an instance of PitchInterval
// OR an + or - integer (direction can be exculded in this case
transpose {arg aPitchInterval, direction = \up;
@@ -610,7 +654,8 @@
}
PitchInterval {
- var <quality, <size, <mod;
+ classvar basesteps;
+ var <quality, <size, <mod, <halfsteps;
//quality is a symbol of \major, \minor, \perf, \dim or \aug
// size is a
*new {arg quality, size;
@@ -619,7 +664,7 @@
mod = (size > 7).if({(size.round % 8) + 1}, {size});
((mod == 1) || (mod == 4) || (mod == 5)).if({
((quality == \perf) || (quality == \aug) || (quality == \dim)).if({
- ^super.newCopyArgs(quality, size, mod)
+ ^super.newCopyArgs(quality, size, mod).initPitchInterval;
}, {
"Unisons, fourths, fifths or octaves need to be \\perf or \\aug".warn;
^nil;
@@ -628,7 +673,7 @@
((mod == 2) || (mod == 3) || (mod == 6) || (mod == 7)).if({
((quality == \major) || (quality == \minor) ||
(quality == \dim) || (quality == \aug)).if({
- ^super.newCopyArgs(quality, size, mod)
+ ^super.newCopyArgs(quality, size, mod).initPitchInterval;
}, {
"Seconds, thirds, sixths or sevents need to be \\major, \\minor, \\dim or \\aug".warn;
^nil;
@@ -636,6 +681,48 @@
})
})
}
+
+ initPitchInterval {
+ halfsteps = basesteps[mod - 1];
+ ((mod == 1) or: {(mod == 4) or: {mod == 5}}).if({
+ case {
+ quality == \perf
+ } {
+ nil
+ } {
+ quality == \aug
+ } {
+ halfsteps = halfsteps + 1;
+ } {
+ quality == \dim
+ } {
+ halfsteps = halfsteps - 1;
+ }
+ }, {
+ case {
+ quality == \minor
+ } {
+ nil
+ } {
+ quality == \major
+ } {
+ halfsteps = halfsteps + 1;
+ } {
+ quality == \dim
+ } {
+ halfsteps = halfsteps - 1;
+ } {
+ quality == \aug
+ } {
+ halfsteps = halfsteps + 2;
+ }
+ })
+
+ }
+
+ *initClass {
+ basesteps = [0, 1, 3, 5, 7, 8, 10];
+ }
}
PitchCollection {
@@ -993,6 +1080,7 @@
noteName {arg hertz = false, round = 1.0; ^this.calcPC(hertz, round).note}
noteAccidental {arg hertz = false, round = 1.0; ^this.calcPC(hertz, round).acc}
noteOctave {arg hertz = false, round = 1.0; ^this.calcPC(hertz, round).octave}
+ halfsteps {^this}
calcPC {arg hertz = false, round = 1.0;
var tmp;
tmp = hertz.if({
Modified: Ctk/Ctk classes/addSimpleNumber.sc
===================================================================
--- Ctk/Ctk classes/addSimpleNumber.sc 2009-12-18 13:29:15 UTC (rev 1296)
+++ Ctk/Ctk classes/addSimpleNumber.sc 2009-12-18 16:31:44 UTC (rev 1297)
@@ -6,23 +6,34 @@
((this - target).abs > range).if({
newtestval = (this > target).if({
this - steps
- }, {
+ }, {
this + steps
- });
- ^newtestval.mod(120).mapIntoRange(range, target, steps,
+ });
+ ^newtestval.mapIntoRange(range, target, steps,
numturns + 1, maxturns, origval)
- }, {
- ^this;
- })
}, {
- "Your Number couldn't be wrapped into the desired range".warn;
+ ^this;
+ })
+ }, {
+ "Your Number couldn't be wrapped into the desired range. Check your parameters or increase maxturns.".warn;
^origval;
- })
- }
+ })
}
-
+
+ mapIntoBounds {arg low, high, steps = 12;
+ var tmp, dif;
+ (low > high).if({
+ tmp = high;
+ high = low;
+ low = tmp;
+ });
+ dif = high - low * 0.5;
+ ^this.mapIntoRange(dif, low + dif, steps);
+ }
+}
+
/*
-a = 76.3.mapIntoRange(12, 60);
+a = -5.3.mapIntoRange(6, 60);
a
*/
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
sc-dev mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/