-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenAdmin.cpp
83 lines (72 loc) · 2.36 KB
/
GenAdmin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* GenAdmin.cpp
*
* Created on: Feb 19, 2014
* Author: edwinrietmeijer
*/
#include "GenAdmin.h"
void addGen( generator::Generator * genObj, std::vector<generator::Generator *> & generatorStack, std::vector<customtypes::GenId> & generatorIds ) {
// Create GenId for object to be added to stack
customtypes::GenId newGenId;
newGenId.scriptName = genObj -> getScriptName();
newGenId.genType = genObj -> getGenId();
bool foundGenType = false;
customtypes::GenId aGenId;
std::vector<customtypes::GenId>::reverse_iterator pos;
for ( pos = generatorIds.rbegin(); pos != generatorIds.rend(); ++pos ) {
aGenId = *pos;
if ( foundGenType == false && aGenId.genType == newGenId.genType ) {
newGenId.instanceNo = aGenId.instanceNo + 1;
foundGenType = true;
}
}
if ( foundGenType == false ) {
newGenId.instanceNo = 0;
}
generatorStack.push_back( genObj );
newGenId.vectorIndex = generatorStack.size() - 1;
// std::cout << newGenId.vectorIndex << " " << newGenId.instanceNo << " " << newGenId.genType << std::endl;
generatorIds.push_back( newGenId );
}
generator::Generator * findGenScriptName( std::string genScriptName ) {
generator::Generator * genToReturn = new generator::Generator;
if ( genScriptName == "serialism") {
genToReturn = new serialism::Serialism();
}
if ( genScriptName == "pernorgard") {
genToReturn = new pernorgard::PerNorgard();
}
if ( genScriptName == "melodygen") {
genToReturn = new melodygen::MelodyGen();
}
if ( genScriptName == "counterpoint") {
genToReturn = new counterpoint::Counterpoint();
}
return genToReturn;
}
int getNrOfGens( generator::Generator * & genToCheck ) {
std::vector<generator::Generator *>::iterator pos;
int nrOfGens = 0;
for ( pos = config::generatorStack.begin(); pos != config::generatorStack.end(); ++pos ) {
if( ( *pos ) -> getGenId() == genToCheck -> getGenId() ) {
++nrOfGens;
}
}
return nrOfGens;
}
int getGenStackIndex( generator::Generator * & genToCheck, int genInstanceNo) {
std::vector<generator::Generator *>::iterator pos;
int nrOfGens = 0;
int genStackIndex = -1;
int genIndex = genStackIndex;
for ( pos = config::generatorStack.begin(); pos != config::generatorStack.end(); ++pos ) {
++genStackIndex;
if( ( *pos ) -> getGenId() == genToCheck -> getGenId() ) {
++nrOfGens;
if( nrOfGens == genInstanceNo ) {
genIndex = genStackIndex;
}
}
}
return genIndex;
}