Skip to content

Commit

Permalink
January 25, 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
tipei authored and tpkurdukar committed Feb 1, 2022
1 parent 12871f2 commit b4dcd48
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 103 deletions.
135 changes: 80 additions & 55 deletions CMOD/src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Event::Event(DOMElement* _element,
currChildNum(0), childType(0),
matrix(0),
type(_type),
previousChildDuration(0),
//previousChildEndTime(0),
discreteFailedResponse(""),
utilities( _utilities),
modifiersIncludingAncestorsElement(NULL),
sieveAligned(false), previousChildStartTime(0.0f) {
sieveAligned(false), previousChildEndTime(0.0f) {

//Initialize parameters
DOMElement* thisEventElement = _element->GFEC();
Expand All @@ -64,6 +64,7 @@ Event::Event(DOMElement* _element,

thisEventElement = thisEventElement->GNES();
name = XMLTC(thisEventElement);
//cout << "Event::Event - name=" << name << endl;
ts = _timeSpan;
tempo = _tempo;

Expand All @@ -87,7 +88,6 @@ Event::Event(DOMElement* _element,

fvTempo.setStartTime(tempo.getStartTime());


if(tempo.getStartTime() == 0){
tempo = fvTempo;
}
Expand Down Expand Up @@ -584,7 +584,9 @@ bool Event::buildContinuum() {
rawChildDuration = utilities->evaluate(XMLTC(childDurationElement),(void*)this);

// assign previousChild Duration here so that the next child can use it
previousChildDuration = rawChildDuration;
// a MISNOMER, actually the ENDTIME of present child
// previousChildDuration = rawChildDuration;
previousChildEndTime = rawChildStartTime + rawChildDuration;

// pre-quantize the duration in case "EDU" is used
int rawChildDurationInt = (int)rawChildDuration;
Expand Down Expand Up @@ -617,8 +619,6 @@ bool Event::buildContinuum() {

checkPoint = (double)tsChild.start / ts.duration;

//cout << "EVENT::buildContinuum - childName: " << childName << endl;

if (utilities->getOutputParticel()){
//Output parameters in the different units available.
Output::beginSubLevel("Continuum");
Expand Down Expand Up @@ -652,24 +652,25 @@ bool Event::buildSweep() {
string durType = XMLTC(childDurationTypeFlag);
string childName;

cout << " " << endl;
cout << "Event::buildSweep - name: " << name << endl;

// Whether we should align notes to sieves
bool align = ( sieveAligned
&& Utilities::isSieveFunction(childStartTimeElement)
&& Utilities::isSieveFunction(childDurationElement)
&& startType == "1"
&& durType == "1");
/*
cout << boolalpha << align << sieveAligned << endl;
int sT; cin >> sT;
*/

// find start time and dur of last child
if (currChildNum == 0) {
tsPrevious.start = 0;
tsPrevious.startEDU = 0;
tsPrevious.end = 0; //IS THIS NECESSARY ?
tsPrevious.endEDU = 0;
}

// Set checkpoint to the endpoint of the last event
checkPoint = tsPrevious.start / ts.duration;
checkPoint = tsPrevious.end / ts.duration;

if (checkPoint > 1) {
cerr << "Event::Sweep -- Error1: tsChild.start outside range of "
Expand All @@ -678,13 +679,13 @@ cout << "Event::buildSweep - name: " << name << endl;
<< ts.duration << endl;
cerr << " in file: " << name << ", childNum="
<< currChildNum << endl;
cerr << "currChildNum=" << currChildNum << " tsPrevious.start="
<< tsPrevious.start << " checkPoint=" << checkPoint << endl;
cerr << "currChildNum=" << currChildNum << " tsPrevious.end="
<< tsPrevious.end << " checkPoint=" << checkPoint << endl;
exit(1);
}

// get the start time
float rawChildStartTime = 0.0;
float rawChildStartTime = 0.0; //Is this necessary for DISCRETE ?
float rawChildDuration = 0.0;
int endTime = 0;

Expand All @@ -701,32 +702,29 @@ cout << "Event::buildSweep - name: " << name << endl;
tsChild.duration = childPt.dur * tempo.getEDUDurationInSeconds().To<float>();
} else {
// get the start time
// rawChildStartTime =
// utilities->evaluate(XMLTC(childStartTimeElement),(void*)this);
/*
rawChildStartTime =
utilities->evaluate(XMLTC(childStartTimeElement),(void*)this);
*/
rawChildStartTime = previousChildEndTime; //actually endTime
//cout << "Event::buildSweep - rawChildStartTime=" << rawChildStartTime << endl;

rawChildStartTime = previousChildStartTime; //actually endTime
cout << "Event:buildSweep - rawChildStartTime=" << rawChildStartTime << endl;
if (startType == "1" ) { //EDU
if (startType == "1" ) { // EDU
tsChild.start = rawChildStartTime *
tempo.getEDUDurationInSeconds().To<float>();
tsChild.startEDU = Ratio((int)rawChildStartTime, 1);
cout << " tsChild.startEDU=" << tsChild.startEDU << endl;
} else if (startType == "2") { //seconds
//cout << " - tsChild.start=" << tsChild.start << endl;
} else if (startType == "2") { //seconds
tsChild.start = rawChildStartTime; // no conversion needed
tsChild.durationEDU = Ratio(0, 0); // floating point is not exact: NaN
} else if (startType == "0") { //fraction
} else if (startType == "0") { //fraction
tsChild.start = rawChildStartTime * ts.duration; // convert to seconds
tsChild.durationEDU = Ratio(0, 0); // floating point is not exact: NaN
}

if (tsChild.start < tsPrevious.start) { // Prevent events from overlapping
tsChild.start = tsPrevious.start;
tsChild.startEDU = tsPrevious.startEDU;
}

if (currChildNum == 0) {
tsChild.start = 0;
tsChild.startEDU = 0;
if (tsChild.start < tsPrevious.end) { // Prevent events from overlapping
tsChild.start = tsPrevious.end;
tsChild.startEDU = tsPrevious.end;
}

// get the type
Expand All @@ -735,28 +733,29 @@ cout << " tsChild.startEDU=" << tsChild.startEDU << endl;

// get the duration
rawChildDuration = utilities->evaluate(XMLTC(childDurationElement),(void*)this);
//cout << " buildSweep - rawChildDuration=" << rawChildDuration << endl;

//assign previousChild Duration here so that the next child can use it
previousChildDuration = rawChildDuration;
// this is a MISNOMER actually the endTime of the present child
previousChildEndTime = rawChildStartTime + rawChildDuration;

// pre-quantize the duration in case "EDU" is used
int rawChildDurationInt = (int)rawChildDuration;
int maxChildDurInt = (int)maxChildDur;

if(rawChildDurationInt > maxChildDurInt)
rawChildDurationInt = maxChildDurInt;
rawChildDurationInt = maxChildDurInt; //enforce limit

if (durType == "1") {
if (durType == "1") { // EDU
tsChild.durationEDU = Ratio(rawChildDurationInt, 1);
tsChild.duration = // convert to seconds
(float)rawChildDurationInt * tempo.getEDUDurationInSeconds().To<float>();
cout << "Event::buildSweep - tsChild.duration=" << tsChild.duration << endl;
} else if (durType == "2") {
} else if (durType == "2") { // secomds
tsChild.duration = rawChildDuration;
if(tsChild.duration > maxChildDur)
tsChild.duration = maxChildDur; // enforce limit
tsChild.durationEDU = Ratio(0, 0); // floating point is not exact: NaN
} else if (durType == "0") {
} else if (durType == "0") { // fraction
tsChild.duration = rawChildDuration * ts.duration; // convert to seconds
if(tsChild.duration > maxChildDur)
tsChild.duration = maxChildDur; // enforce limit
Expand All @@ -765,23 +764,38 @@ cout << "Event::buildSweep - tsChild.duration=" << tsChild.duration << endl;
}

if(startType == "1" && durType == "1") {
endTime = Event::verify_valid(rawChildStartTime + rawChildDuration);
previousChildStartTime = endTime;

tsChild.start = rawChildStartTime *
/*
cout << " - previousChildEndTime=" << previousChildEndTime << endl;
cout << " " <<endl;
*/
endTime = Event::verify_valid(previousChildEndTime); //missnomer !!
tsChild.start = endTime *
tempo.getEDUDurationInSeconds().To<float>();
tsChild.startEDU = Ratio((int)rawChildStartTime, 1);

rawChildDuration = endTime - rawChildStartTime;
int rawChildDurationInt = (int)rawChildDuration;
tsChild.durationEDU = Ratio(rawChildDurationInt, 1);
tsChild.duration = // convert to seconds
rawChildDuration = endTime - rawChildStartTime;
int rawChildDurationInt = (int)rawChildDuration;
tsChild.durationEDU = Ratio(rawChildDurationInt, 1);
tsChild.duration = // convert to seconds
(float)rawChildDurationInt * tempo.getEDUDurationInSeconds().To<float>();
}

tsPrevious.start = tsChild.start;
tsPrevious.startEDU = tsChild.startEDU;
previousChildEndTime = endTime;
}

tsPrevious.end = tsChild.start + tsChild.duration; //same as EndTime above
tsPrevious.endEDU = tsChild.startEDU + tsChild.durationEDU;;
/*
cout << " " << endl;
cout << "Event:buildSweep - rawChildStartTime=" << rawChildStartTime << endl;
cout << " tsChild.start=" << tsChild.start << endl;
cout << " rawChildDuration=" << rawChildDuration << endl;
cout << " tsChild.duration=" << tsChild.duration << endl;
cout << " - endTime=" << endTime << endl;
cout << " - tsPrevious.end=" << tsPrevious.end << endl;
cout << " - tsPrevious.endEDU=" << tsPrevious.endEDU << endl;
cout << " - previousChildEndTime=" << previousChildEndTime << endl;
int sever; cin >> sever;
*/
// set checkpoint to the start of this child event
checkPoint = tsChild.start / ts.duration;

Expand All @@ -802,18 +816,20 @@ cout << "Event::buildSweep - tsChild.duration=" << tsChild.duration << endl;
Output::beginSubLevel("Parameters");
Output::addProperty("Start", rawChildStartTime, unitTypeToUnits(startType));
Output::addProperty("Duration", rawChildDuration, unitTypeToUnits(durType));
} else {
Output::addProperty("Max Duration", maxChildDur, "sec.");
if(unitTypeToUnits(startType) == "EDU")
Output::addProperty("Max Duration", maxChildDur, "EDU");
else
Output::addProperty("Max Duration", maxChildDur, "sec.");
Output::endSubLevel();
Output::beginSubLevel("Seconds");
Output::addProperty("Start", tsChild.start, "sec.");
Output::addProperty("Duration", tsChild.duration, "sec.");
Output::addProperty("Previous", tsPrevious.start, "sec.");
Output::addProperty("Previous", tsPrevious.end, "sec.");
Output::endSubLevel();
Output::beginSubLevel("EDU");
Output::addProperty("Start", tsChild.startEDU, "EDU");
Output::addProperty("Duration", tsChild.durationEDU, "EDU");
Output::addProperty("Previous", tsPrevious.startEDU, "EDU");
Output::addProperty("Previous", tsPrevious.endEDU, "EDU");
Output::endSubLevel();
Output::addProperty("Checkpoint", checkPoint, "of parent");
Output::endSubLevel();
Expand Down Expand Up @@ -1410,23 +1426,32 @@ void Event::buildMatrix(bool discrete) {
//----------------------------------------------------------------------------//

int Event::verify_valid(int endTime){

int beatEDUs = tempo.getEDUPerTimeSignatureBeat().Num();

if (sieveSweep == NULL){
sieveSweep = utilities->evaluateSieve(XMLTC(childStartTimeElement), (void*) this);
/*
if (sieveSweep == NULL) {
sieveSweep = utilities->evaluateSieve(XMLTC(childDurationElement), (void*) this);
}
*/

vector<double> attProbs;
vector<int> attTimes;
sieveSweep->FillInVectors(attTimes, attProbs);
attackSweep.clear();

//cout << "Event::verify_valid - attTimes: " << endl;
for (int i = 0; i < attTimes.size(); i++){
if (attTimes[i] >= beatEDUs){
break;
}
//cout << "Event::verify_valid - attTimes: "<< attTimes[i] << " ";
//cout << attTimes[i] << " ";
attackSweep.push_back(attTimes[i]);
}
//cout << " " << endl;
}
//cout << " validate - sieve != NULL " << endl;

int length = attackSweep.size();
int low = 0;
Expand Down
13 changes: 7 additions & 6 deletions CMOD/src/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ class Event {
double checkPoint;

//Previous start time for Sweep //added by sever
double previousChildStartTime;
double previousChildEndTime;

//Previous start time (only used by sweep generation method)
TimeSpan tsPrevious;

//Previous child duration
double previousChildDuration;
//Previous child duration NOT USED
//double previousChildDuration;

// Whether to align note durations to a sieve. True for Bottoms that contain Notes.
// Whether to align note durations to a sieve. True for Bottoms
// that contain Notes.
bool sieveAligned;
//-------------------------- Layers and Types ----------------------------//

Expand Down Expand Up @@ -309,9 +310,9 @@ class Event {

/**
* Returns the previous child duration
* NOT USED
**/

double getPreviousChildDuration(){ return previousChildDuration;}
double getPreviousChildEndTime(){ return previousChildEndTime;}

/**
* Returns the number of current partial -- will call to bottom in most cases
Expand Down
2 changes: 1 addition & 1 deletion CMOD/src/FileValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ void FileValue::static_ftn_PREVIOUS_CHILD_DURATION() {
exit(1);
}
return_type = FVAL_NUMBER;
n = evptr->getPreviousChildDuration();
n = evptr->getPreviousChildEndTime();
}


Expand Down
12 changes: 7 additions & 5 deletions CMOD/src/Sieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Sieve::BuildFromExpr(int minVal, int maxVal,
ModParser mp(offsetVect);
mp.parseExpr(expr, minVal, maxVal);
eList = mp.getElements();
//Sieve::print_eList();
Sieve::Weights(mp.getMods(), wMethod, wArgVect, mp.getOffsets());
}

Expand All @@ -79,11 +79,11 @@ void Sieve::Build(int minVal, int maxVal,
//---------------------------------------------------------------------------//

void Sieve::FillInVectors(vector<int>& intVect, vector<double>& doubleVect) {


list<int>::iterator eIter = eList.begin();
list<double>::iterator wIter = wList.begin();

//cout << "Sieve::FillInVectors - eList.size()=" << eList.size() << "wList.size()=" << wList.size() << endl;

if ( eList.size() >= wList.size() ) {
while (eIter != eList.end()) {
intVect.push_back( *eIter );
Expand Down Expand Up @@ -308,9 +308,11 @@ void Sieve::HierarchicWeights(const std::vector<int>& eArgVect,
/*
cout << "Sieve::Hierarchic - eList.end=" << eList.end() << " eArgVect.size()="
<< eArgVect.size() << " wArgVect.size=" << wArgVect.size() << endl;
print_eList();
print_eList(); cout << " " << endl;
print_wList();
cout << "Sieve::HierarchicWeights - wArgVect.size()=" << wArgVect.size() << endl;
int sever; cin >> sever;
*/

while (eIter != eList.end()) {
whichMod = 0;
probability = 0;
Expand Down
2 changes: 1 addition & 1 deletion CMOD/src/Sieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Sieve {
/**
* FillInVectors calls CumulWeights to normalize and and add the result in
* a cumulative way resulting in probabilities from 0 to 1 and then copies
* them into the vectors
* them into the vectors ???
* \param intVect a vector of ints
* \param doubleVect a vector of doubles
**/
Expand Down
4 changes: 3 additions & 1 deletion CMOD/src/TimeSpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ seconds and, in the case of it being an exact interval, EDU.*/
struct TimeSpan {
float start;
float duration;
float end;
Ratio startEDU;
unsigned long long int startEDUAbsolute;
Ratio durationEDU;
Ratio endEDU;

TimeSpan() : start(0), duration(0), startEDU(0, 0), startEDUAbsolute(0), durationEDU(0, 0) {}
TimeSpan() : start(0), duration(0), end(0), startEDU(0, 0), startEDUAbsolute(0), durationEDU(0, 0), endEDU(0, 0) {}
};
#endif /* TIMESPAN_H */

Loading

0 comments on commit b4dcd48

Please sign in to comment.