Skip to content

Commit

Permalink
Implement modifier application by groups (APPLY BY SOUND ONLY)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenHeartcore committed Jul 25, 2023
1 parent c339f3e commit 16622d4
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 37 deletions.
97 changes: 65 additions & 32 deletions CMOD/src/Bottom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Bottom::Bottom(DOMElement* _element,
<Spatialization>5</Spatialization>
<Reverb>6</Reverb>
<Filter>f</Filter>
<ModifierGroup></ModifierGroup>
<Modifiers>
</Modifiers>
</ExtraInfo>
Expand Down Expand Up @@ -90,8 +91,10 @@ Bottom::Bottom(DOMElement* _element,
filterElement = loudnessElement->GNES()->GNES()->GNES();
}

/* ZIYUAN CHEN, July 2023 */
modifierGroupElement = loudnessElement->GNES()->GNES()->GNES()->GNES();

modifiersElement = loudnessElement->GNES()->GNES()->GNES()->GNES();
modifiersElement = loudnessElement->GNES()->GNES()->GNES()->GNES()->GNES();

}

Expand Down Expand Up @@ -1234,8 +1237,7 @@ Reverb* Bottom::computeReverberationAdvanced(DOMElement* percentElement,
//-----------------------------------------------------------------------------/

void Bottom::applyModifiers(Sound *s, int numPartials) {
vector<Modifier> modNoDep; //mods without dependencies
map<string, vector<Modifier> > modMutEx; // map mutex group names to the mods
map<string, vector<Modifier> > modGroups; // ZIYUAN CHEN, July 2023 - map group names to the mods


DOMElement* modifiersIncludingAncestorsElement = (DOMElement*) modifiersElement->cloneNode(true);
Expand Down Expand Up @@ -1356,16 +1358,18 @@ float vel;
delete env;
}

arg = widthElement->GNES();//group name (MUT_EX)
string mutExGroup = XMLTC(arg);
if (mutExGroup == "") {
// not MUT_EX
modNoDep.push_back(newMod);
} else {
// mutually exclusive
modMutEx[mutExGroup].push_back(newMod);
/* ZIYUAN CHEN, July 2023 - Categorizing a modifier into groups */
arg = velocityElement->GNES();//group name
std::stringstream ss(XMLTC(arg));
std::string groupName;
while (std::getline(ss, groupName, ',')) {
/* strip leading and trailing whitespaces to be compatible with
<List>Name1, Name2, Name3</List> in Select - RandomInt function */
groupName.erase(0, groupName.find_first_not_of(' '));
groupName.erase(groupName.find_last_not_of(' ') + 1);
modGroups[groupName].push_back(newMod);
cout << "Added modifier to group " << groupName << endl;
}
newMod.applyModifier(s);
delete probEnv;
}
else if (applyHow == "PARTIAL") {
Expand Down Expand Up @@ -1423,41 +1427,70 @@ float vel;


// delete probEnv;
modNoDep.push_back(newPartialMod);
arg = velocityElement->GNES();//group name
std::stringstream ss(XMLTC(arg));
std::string groupName;
while (std::getline(ss, groupName, ',')) {
groupName.erase(0, groupName.find_first_not_of(' '));
groupName.erase(groupName.find_last_not_of(' ') + 1);
modGroups[groupName].push_back(newPartialMod);
cout << "Added modifier to group " << groupName << endl;
}
envelopeElement = envelopeElement->GNES();
}
}

modifierElement = modifierElement->GNES(); // go to the next MOD in the list
} // end of the main while loop

// go through the non-exclusive mods

for (int i = 0; i < modNoDep.size(); i++) {
/* ZIYUAN CHEN, July 2023 -
Here, we evaluate the target "Modifier Group" name to be applied.
The user may put a string (e.g., "Apple") or a function in this field.
The function is always a random selection between strings with the following syntax:
<Fun>
<Name>Select</Name>
<List>Apple,Boy,Cat</List>
<Index>
<Fun>
<Name>RandomInt</Name>
<LowBound>0</LowBound>
<HighBound>2</HighBound>
</Fun>
</Index>
</Fun>
Since utilities->evaluate() returns a double everywhere else (and correspondingly,
<List> holds numbers instead of strings), a special mechanism is implemented here
to (1) evaluate <Index> as a "RandomInt" function and (2) manually extract the
desired <List> element, instead of rewriting utilities->evaluate().
*/

if (modNoDep[i].willOccur(checkPoint)) {
string targetModGroupName = XMLTC(modifierGroupElement);

modNoDep[i].applyModifier(s);
if (targetModGroupName.find("<Fun>") != string::npos) { // evaluate if it's function string

}
}
DOMElement* modifierGroupListElement = modifierGroupElement->GFEC()->GFEC()->GNES(); // <List>
DOMElement* modifierGroupIndexFunElement = modifierGroupListElement->GNES(); // <Index>
int targetModGroupIndex = (int)utilities->evaluate(XMLTC(modifierGroupIndexFunElement), this);

std::stringstream ss(XMLTC(modifierGroupListElement));
while (std::getline(ss, targetModGroupName, ',') && targetModGroupIndex > 0) {
targetModGroupName.erase(0, targetModGroupName.find_first_not_of(' '));
targetModGroupName.erase(targetModGroupName.find_last_not_of(' ') + 1);
targetModGroupIndex--;
}

// go through the exclusive mods
map<string, vector<Modifier> >::iterator iter = modMutEx.begin();
while (iter != modMutEx.end()) {
vector<Modifier> modGroup = (*iter).second;
}

//go through the group, and apply 1 at most
bool appliedMod = false;
for (int i = 0; i < modGroup.size() && !appliedMod; i++) {
if (modGroup[i].willOccur(checkPoint)) {
modGroup[i].applyModifier(s);
appliedMod = true;
}
// ZIYUAN CHEN, July 2023 - apply the specified one (1) group of modifiers
if (modGroups.find(targetModGroupName) != modGroups.end()) {
vector<Modifier> modGroup = modGroups[targetModGroupName];
for (int i = 0; i < modGroup.size(); i++) {
modGroup[i].applyModifier(s);
}
iter ++;
} else {
cerr << "WARNING: Specified modifier group " << targetModGroupName << " not found!" << endl;
}

//delete modifiersIncludingAncestorsElement;
}

Expand Down
3 changes: 3 additions & 0 deletions CMOD/src/Bottom.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Bottom : public Event {
DOMElement* frequencyElement;
DOMElement* loudnessElement;
DOMElement* modifiersElement;
/* ZIYUAN CHEN, July 2023 - The "Modifier Group" is only present
in Bottom events, so this element doesn't appear in Event.h */
DOMElement* modifierGroupElement;
DOMElement* ancestorModifiersElement;

//Current partial during the processing of the event
Expand Down
47 changes: 47 additions & 0 deletions LASSIE/src/EventAttributesViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ EventAttributesViewController::EventAttributesViewController(
"BottomSubAttributesFilterButton", button);
button->signal_clicked().connect(sigc::mem_fun(*this, & EventAttributesViewController::BSFilterButtonClicked));

// ZIYUAN CHEN, July 2023
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupButton", button);
button->signal_clicked().connect(sigc::mem_fun(*this, & EventAttributesViewController::BSModifierGroupButtonClicked));

attributesRefBuilder->get_widget(
"BottomSubAttributesWellTemperedButto", button);
button->signal_clicked().connect(sigc::mem_fun(*this, & EventAttributesViewController::BSWellTemperedButtonClicked));
Expand Down Expand Up @@ -669,6 +674,11 @@ EventAttributesViewController::EventAttributesViewController(
"BottomSubAttributesFilterEntry", entry);
entry->signal_changed().connect(sigc::mem_fun(*this, & EventAttributesViewController::modified));

// ZIYUAN CHEN, July 2023
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupEntry", entry);
entry->signal_changed().connect(sigc::mem_fun(*this, & EventAttributesViewController::modified));

attributesRefBuilderSound->get_widget(
"SoundAttributesNumPartialEntry", entry);
entry->signal_changed().connect(sigc::mem_fun(*this, & EventAttributesViewController::modified));
Expand Down Expand Up @@ -1189,6 +1199,11 @@ void EventAttributesViewController::saveCurrentShownEventData(){
"BottomSubAttributesFilterEntry", entry);
currentlyShownEvent->getEventExtraInfo()->setFilter(entry->get_text());

// ZIYUAN CHEN, July 2023
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupEntry", entry);
currentlyShownEvent->getEventExtraInfo()->setModifierGroup(entry->get_text());

}// end handle BottomExtraInfo


Expand Down Expand Up @@ -2214,6 +2229,12 @@ void EventAttributesViewController::showCurrentEventData(){
entry->set_text(extraInfo->getFilter());
entry->set_sensitive(true);

// ZIYUAN CHEN, July 2023
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupEntry", entry);
entry->set_text(extraInfo->getModifierGroup());
entry->set_sensitive(true);

}
else {

Expand All @@ -2232,6 +2253,12 @@ void EventAttributesViewController::showCurrentEventData(){
entry->set_text("");
entry->set_sensitive(false);

// ZIYUAN CHEN, July 2023
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupEntry", entry);
entry->set_text("");
entry->set_sensitive(false);



}
Expand Down Expand Up @@ -4760,6 +4787,26 @@ void EventAttributesViewController::BSFilterButtonClicked(){

}

// ZIYUAN CHEN, July 2023
void EventAttributesViewController::BSModifierGroupButtonClicked(){

if (currentlyShownEvent->getEventExtraInfo()->getChildTypeFlag()!= 0){
return;
}

Gtk::Entry* entry;
attributesRefBuilder->get_widget(
"BottomSubAttributesModifierGroupEntry", entry);
FunctionGenerator* generator =
new FunctionGenerator(functionReturnMGP,entry->get_text());
int result = generator->run();
if (generator->getResultString() !=""&& result ==0){
entry->set_text(generator->getResultString());
}
delete generator;

}

void EventAttributesViewController::BSWellTemperedButtonClicked(){
Gtk::Entry* entry;
attributesRefBuilder->get_widget(
Expand Down
1 change: 1 addition & 0 deletions LASSIE/src/EventAttributesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class EventAttributesViewController:public Gtk::Frame {
void BSSpatializationButtonClicked();
void BSReverbButtonClicked();
void BSFilterButtonClicked();
void BSModifierGroupButtonClicked(); // ZIYUAN CHEN, July 2023
void BSWellTemperedButtonClicked();
void BSFunFreqButton1Clicked();
void BSFunFreqButton2Clicked();
Expand Down
13 changes: 12 additions & 1 deletion LASSIE/src/FunctionGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,16 @@ FunctionGenerator::FunctionGenerator(
row[functionListColumns.m_col_name] = "Select";


}

// ZIYUAN CHEN, July 2023 - Function generator for "Modifier Group"
else if (_returnType ==functionReturnMGP){
Gtk::TreeModel::Row row = *(functionListTreeModel->append());
// this is based on Sever's request
row[functionListColumns.m_col_id] = functionSelect;
row[functionListColumns.m_col_name] = "Select";


}
else if (_returnType ==functionReturnPAT){
Gtk::TreeModel::Row row = *(functionListTreeModel->append());
Expand Down Expand Up @@ -4250,7 +4260,8 @@ void FunctionGenerator::selectEntryChanged(){
stringbuffer = stringbuffer + current->toString();
current = current ->next;
while (current != NULL) {
stringbuffer = stringbuffer + ", " + current->toString();
// ZIYUAN CHEN, July 2023 - Remove the space from ", "
stringbuffer = stringbuffer + "," + current->toString();
current = current->next;
}
}
Expand Down
24 changes: 23 additions & 1 deletion LASSIE/src/IEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ IEvent::IEvent(){
childEventDefAttackSieve = "";
childEventDefDurationSieve = "";

// ZIYUAN CHEN, July 2023
modifierGroup = "";
filter = "";
reverb = "";
spatialization = "";
Expand Down Expand Up @@ -870,6 +872,14 @@ void IEvent::BottomEventExtraInfo::setFilter(std::string _string){
filter = _string;
}

// ZIYUAN CHEN, July 2023
std::string IEvent::BottomEventExtraInfo::getModifierGroup(){
return modifierGroup;
}
void IEvent::BottomEventExtraInfo::setModifierGroup(std::string _string){
modifierGroup = _string;
}

void IEvent::BottomEventExtraInfo::setChildTypeFlag(int _type){
childTypeFlag = _type;
};
Expand Down Expand Up @@ -1975,6 +1985,7 @@ IEvent::BottomEventExtraInfo::BottomEventExtraInfo(
loudness = _original->loudness;
spatialization = _original->spatialization;
reverb = _original->reverb;
modifierGroup = _original->modifierGroup; // ZIYUAN CHEN, July 2023


if (_original->modifiers == NULL){
Expand Down Expand Up @@ -2477,6 +2488,7 @@ string IEvent::getXMLTHMLB(){
" <Spatialization>" + spatialization + "</Spatialization>\n"
" <Reverb>" + reverb + "</Reverb>\n"
" <Filter>" + filter + "</Filter>\n" ;
// ZIYUAN CHEN, July 2023 - <ModifierGroup> only appears in Bottom events


if (eventType == eventBottom){
Expand Down Expand Up @@ -2510,6 +2522,7 @@ string IEvent::getXMLTHMLB(){
" <Spatialization>" + extraInfo->getSpatialization() + "</Spatialization>\n"
" <Reverb>" + extraInfo->getReverb() + "</Reverb>\n"
" <Filter>" + extraInfo->getFilter() + "</Filter>\n"
" <ModifierGroup>" + extraInfo->getModifierGroup() + "</ModifierGroup>\n"
+ modifiersbuffer +
" </ExtraInfo>\n";
stringbuffer = stringbuffer + bottomBuffer;
Expand Down Expand Up @@ -3005,7 +3018,16 @@ IEvent::BottomEventExtraInfo::BottomEventExtraInfo(int _childTypeFlag, DOMElemen
if (temp != NULL){ // in case there is no <Filter></Filter>
filter = getFunctionString(thisElement);

modifiers = buildModifiersFromDOMElement(thisElement->getNextElementSibling()->getFirstElementChild());
// ZIYUAN CHEN, July 2023 - A new sibling may be present before <Modifier>
DOMElement* temp2 = temp->getNextElementSibling();
if (temp2 != NULL){
modifierGroup = getFunctionString(temp);
modifiers = buildModifiersFromDOMElement(temp2->getFirstElementChild());
}
else {
modifierGroup = "";
modifiers = buildModifiersFromDOMElement(temp->getFirstElementChild());
}
}
else {
filter = "";
Expand Down
6 changes: 6 additions & 0 deletions LASSIE/src/IEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ class IEvent {
virtual void setReverb(std::string _string){}
virtual std::string getFilter(){return "";}
virtual void setFilter(std::string _string){}
virtual std::string getModifierGroup(){return "";}
virtual void setModifierGroup(std::string _string){}
virtual EventBottomModifier* getModifiers(){return NULL;}
virtual EventBottomModifier* addModifier(){return NULL;}
virtual void removeModifier(EventBottomModifier* _modifier){}
Expand Down Expand Up @@ -629,6 +631,8 @@ class IEvent {
void setReverb(std::string _string);
std::string getFilter();
void setFilter(std::string _string);
std::string getModifierGroup();
void setModifierGroup(std::string _string);
EventBottomModifier* getModifiers();
EventBottomModifier* addModifier();
void removeModifier(EventBottomModifier* _modifier);
Expand All @@ -649,6 +653,7 @@ class IEvent {
std::string spatialization;
std::string reverb;
std::string filter;
std::string modifierGroup; // ZIYUAN CHEN, July 2023



Expand Down Expand Up @@ -843,6 +848,7 @@ class IEvent {
std::string childEventDefAttackSieve;
std::string childEventDefDurationSieve;

std::string modifierGroup; // ZIYUAN CHEN, July 2023
std::string filter;
std::string reverb;
std::string spatialization;
Expand Down
1 change: 1 addition & 0 deletions LASSIE/src/LASSIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ typedef enum {
functionReturnPAT,
funcitonReturnMEA,
functionReturnFIL, // added for filter object
functionReturnMGP, // ZIYUAN CHEN, July 2023 - added for "Modifier Group"
functionReturnSPE, //added for generating spectrum from distance
functionReturnIntList,
functionReturnFloatList,
Expand Down

0 comments on commit 16622d4

Please sign in to comment.