this change should ensure the final cadence is a harmonic series

main
mwinter 4 years ago
parent 483162b94d
commit 3fb0e2382a

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -59,13 +59,13 @@ harmonicDistance = {arg fr; log2(fr[0].asFloat.product * fr[1].asFloat.product)}
//~~~~~~~~~~~~GENERATE MODE~~~~~~~~~~~~
//TODO: Play with this a bit more (should I go back to the old way)
genMode = {
genMode = {arg forceHS = false;
var mode, alternateProb;
alternateProb = [1, 0].wchoose([1, 4].normalizeSum);
alternateProb = [1, 0].wchoose([if(forceHS, {0}, {1}), 4].normalizeSum);
mode = [
[1, 1],
[9, 8],
[[5, 4], [6, 5]].wchoose([3, 1].normalizeSum),
[[5, 4], [6, 5]].wchoose([3, if(forceHS, {0}, {1})].normalizeSum),
[[4, 3], [11, 8]].wchoose([alternateProb, 1].normalizeSum),
[3, 2],
[[8, 5], [13, 8]].wchoose([alternateProb, 1].normalizeSum),
@ -119,7 +119,7 @@ initModeState = {
curModeState;
};
advanceMode = {arg lastModeState, lastCadenceState;
advanceMode = {arg lastModeState, lastCadenceState, forceHS = false;
var curModeState, curRoots, lastRoots, lastCadenceRoot, changeCount;
curModeState = lastModeState.deepCopy;
@ -169,10 +169,10 @@ advanceMode = {arg lastModeState, lastCadenceState;
old = frNearestInList.value([new, rootSel], curModeState);
if(curModeState[old][\count] >= 20, {
var mode, root;
mode = genMode.value;
//mode = genMode.value;
root = [rootSel, curModeState[rootSel][\mode]];
curModeState.add(new ->
Dictionary.with(*[\count->1,\mode->genMode.value, \root->root, \mult->multSel, \fr->new]));
Dictionary.with(*[\count->1,\mode->genMode.value(forceHS), \root->root, \mult->multSel, \fr->new]));
curModeState.removeAt(old);
changeCount = changeCount + 1;
})
@ -278,7 +278,7 @@ genEnsemblePart = {arg partState, modeState, temporalData, roots, part, offset;
partState[\lastDur] = partState[\lastDur] + 1;
timeStamp = ts + offset;
change = [val == 1, (val == 1) && firstChange.not].wchoose([1, 2].normalizeSum);//5 * abs((curPulse / totalLen).clip(0, 1) - 1)].normalizeSum);
change = [val == 1, (val == 1) && firstChange.not].wchoose([1, 2].normalizeSum);//5 * abs((curPulse / minTotalLen).clip(0, 1) - 1)].normalizeSum);
if(
(partState[\index] == 0) &&
(frToFloat.value(partState[\lastFreqRatio]) >= 4.0) &&
@ -359,7 +359,7 @@ genAccompPart = {arg modeState, temporalData, offset, trans, part, register;
accompData = [];
temporalData.do({arg val, tS;
var change;
change = [val == 1, (val == 1) && firstChange.not].wchoose([1, if(part == 0, {5}, {3})].normalizeSum); //5 * abs((curPulse / totalLen).clip(0, 0.8) - 1)].normalizeSum);
change = [val == 1, (val == 1) && firstChange.not].wchoose([1, if(part == 0, {5}, {3})].normalizeSum); //5 * abs((curPulse / minTotalLen).clip(0, 0.8) - 1)].normalizeSum);
if(change, {
var sel, freq, amp;
sel = wchooseDict.value(modeState, 0.1);
@ -422,8 +422,9 @@ genAmpCurve = {arg temporalData1, temporalData2, offset1, offset2, type;
//~~~~~~~~~~~~GENERATE ALL MUSIC DATA~~~~~~~~~~~~
~genMusicData = {arg seed;
var totalDur, section1Dur, dUnit, curLen, cadence, ultimate,
totalLen, section1Len,
var minTotalDur, minSection1Dur, dUnit, curLen, cadence,
ultimateSubsection, ultimateSection, ultimateCadenceCount,
minTotalLen, minSection1Len,
modeState, temporalState, partStates,
lastCadenceTemporalData, lastCadenceState, lastSectionPoint,
ensData, accompData, bassData, ampData,
@ -431,19 +432,20 @@ genAmpCurve = {arg temporalData1, temporalData2, offset1, offset2, type;
sectionCount, subsectionCount,
lastRoots, roots, ampDataTmp;
thisThread.randSeed = seed.postln;
thisThread.randSeed = seed;
# totalDur, section1Dur, dUnit, curLen, cadence, ultimate = [16 * 60, 8 * 60, 8.reciprocal, 0, false, false];
# totalLen, section1Len = [(totalDur / dUnit).round(16), (section1Dur / dUnit).round(16)];
# minTotalDur, minSection1Dur, dUnit, curLen, cadence = [15 * 60, 8 * 60, 8.reciprocal, 0, false];
# ultimateSubsection, ultimateSection, ultimateCadenceCount = [false, false, 0];
# minTotalLen, minSection1Len = [(minTotalDur / dUnit).round(16), (minSection1Dur / dUnit).round(16)];
# modeState, temporalState, partStates = [initModeState.value, initTemporalState.value, initPartStates.value];
# lastCadenceTemporalData, lastCadenceState, lastSectionPoint = [nil, modeState.deepCopy, 0];
# ensData, accompData, bassData, ampData = [4.collect({[]}), 4.collect({6.collect({[]})}), 2.collect({[]}), 3.collect({[]})];
# sectionData, sectionNavDict = [Dictionary.new, Dictionary.new];
# sectionCount, subsectionCount = [1, 1];
while({(curLen < totalLen) || ((curLen >= totalLen) && cadence.not)}, {
while({(curLen < minTotalLen) || ((curLen >= minTotalLen) && cadence.not) || ultimateSection.not}, {
var temporalData;
# temporalData, temporalState = genTemporalData.value(temporalState, modeState, curLen <= section1Len);
# temporalData, temporalState = genTemporalData.value(temporalState, modeState, curLen <= minSection1Len);
collectRoots.value(modeState).collect({arg fr; [fr[0].asFloat.product, fr[1].asFloat.product]}).postln;
//modeState.keys.postln;
@ -453,7 +455,7 @@ genAmpCurve = {arg temporalData1, temporalData2, offset1, offset2, type;
roots = distributeRoots.value(modeState, lastRoots);
sectionData.add((curLen / 4).asInteger->[roots, lastRoots.collect({arg fr, part;
[fr, 36.midicps * pow(2, [1, 0, 1, 2][part]) * frToFloat.value(fr)]}), sectionCount, subsectionCount, cadence, ultimate]);
[fr, 36.midicps * pow(2, [1, 0, 1, 2][part]) * frToFloat.value(fr)]}), sectionCount, subsectionCount, cadence, ultimateSubsection]);
sectionNavDict.add([sectionCount, subsectionCount]->[(curLen / 16 + 1).asInteger]);
4.do({arg part;
@ -484,7 +486,7 @@ genAmpCurve = {arg temporalData1, temporalData2, offset1, offset2, type;
curLen = curLen + temporalData[0].size;
if(curLen > section1Len, {
if(curLen > minSection1Len, {
if(collectRoots.value(modeState).size == 1, {
ampData[0] = ampData[0] ++ genAmpCurve.value(lastCadenceTemporalData, temporalData, lastSectionPoint, curLen, 0);
@ -509,10 +511,14 @@ genAmpCurve = {arg temporalData1, temporalData2, offset1, offset2, type;
# sectionCount, subsectionCount = [sectionCount + 1, 1];
# lastCadenceTemporalData, lastCadenceState, lastSectionPoint = [temporalData, modeState, curLen];
cadence = true;
//this should ensure that the final cadence is a HS
if(curLen >= minTotalLen, {ultimateCadenceCount = ultimateCadenceCount + 1});
ultimateSection = ultimateCadenceCount > 1;
}, {
cadence = false
});
modeState = advanceMode.value(modeState, lastCadenceState);
modeState = advanceMode.value(modeState, lastCadenceState, curLen >= minTotalLen);
});
});

Loading…
Cancel
Save