41
void MusicModel::generate()
43
int MusicModel::generate()
43
46
cppSound->removeScore();
44
47
if (children.size()) {
47
50
traverse(getLocalCoordinates(), score);
48
51
System::message("Generated %d events.\n", score.size());
51
void MusicModel::render()
55
int MusicModel::render()
54
createCsoundScore(csoundScoreHeader);
57
int errorStatus = generate();
61
errorStatus = perform();
58
65
void MusicModel::createCsoundScore(std::string addToScore, double extendSeconds)
66
73
char buffer[0x100];
67
74
std::sprintf(buffer, "\ns %9.3f", extendSeconds);
68
75
cppSound->addScoreLine(buffer);
69
std::sprintf(buffer, "\ne %9.3f", extendSeconds);
70
cppSound->addScoreLine(buffer);
76
//std::sprintf(buffer, "\ne %9.3f", extendSeconds);
77
//cppSound->addScoreLine(buffer);
71
78
cppSound->exportForPerformance();
74
void MusicModel::perform()
81
int MusicModel::perform()
84
cppSound->setCommand(getCsoundCommand());
85
createCsoundScore(csoundScoreHeader);
86
errorStatus = cppSound->perform();
87
if (errorStatus == 1) {
90
// The Csound command is managed from MusicModel,
91
// not from CppSound. So we clear out what we set.
92
cppSound->setCommand("");
81
96
void MusicModel::clear()
85
100
cppSound->removeScore();
130
145
void MusicModel::arrange(int oldInstrumentNumber,
131
int newInstrumentNumber,
146
int newInstrumentNumber,
134
149
score.arrange(oldInstrumentNumber, newInstrumentNumber, gain);
137
152
void MusicModel::arrange(int oldInstrumentNumber,
138
int newInstrumentNumber,
153
int newInstrumentNumber,
142
157
score.arrange(oldInstrumentNumber, newInstrumentNumber, gain, pan);
153
168
int csoundInstrumentNumber = cppSound->getInstrumentNumber(csoundInstrumentName);
154
169
arrange(silenceInstrumentNumber, csoundInstrumentNumber, gain);
157
172
void MusicModel::arrange(int silenceInstrumentNumber, std::string csoundInstrumentName, double gain, double pan)
173
188
std::string MusicModel::getCsoundCommand() const
175
return cppSound->getCommand();
190
std::string command_ = cppSound->getCommand();
191
if (command_.size() == 0)
193
const char *temp_path = std::getenv("TEMP");
198
std::string orcname = std::tmpnam(0);
199
std::string sconame = std::tmpnam(0);
202
"csound --midi-key=4 --midi-velocity=5 -m167 -RWdfo %s %s%s.orc %s%s.sco",
203
getOutputSoundfileName().c_str(), temp_path, orcname.c_str(), temp_path, sconame.c_str());
178
209
long MusicModel::getThis()
185
216
return (Node *)this;
219
int MusicModel::processArgs(const std::vector<std::string> &args)
221
System::inform("BEGAN MusicModel::processArgv()...\n");
222
std::map<std::string, std::string> argsmap;
224
for (size_t i = 0, n = args.size(); i < n; ++i)
226
const std::string token = args[i];
227
std::string value = "";
228
if (token.find("--") == 0)
236
argsmap[key] = value;
237
System::inform("argument[%2d]: %s = %s\n", i, key.c_str(), value.c_str());
241
bool postPossible = false;
242
std::string playSoundfileName = getOutputSoundfileName();
243
if ((argsmap.find("--midi") != argsmap.end()) && !errorStatus)
245
errorStatus = generate();
249
getScore().save(getMidiFilename().c_str());
251
if ((argsmap.find("--csound") != argsmap.end()) && !errorStatus)
254
errorStatus = render();
256
if ((argsmap.find("--pianoteq") != argsmap.end()) && !errorStatus)
258
std::sprintf(command, "Pianoteq --midi %s\n", getMidiFilename().c_str());
259
System::inform("Executing command: %s", command);
260
errorStatus = std::system(command);
262
if ((argsmap.find("--pianoteq-wav") != argsmap.end()) && !errorStatus)
265
std::sprintf(command, "Pianoteq --headless --midi %s --rate 48000 --wav %s\n", getMidiFilename().c_str(), getOutputSoundfileName().c_str());
266
System::inform("Executing command: %s", command);
267
errorStatus = std::system(command);
269
if ((argsmap.find("--playmidi") != argsmap.end()) && !errorStatus)
271
std::sprintf(command, "%s %s\n", argsmap["--playmidi"].c_str(), getMidiFilename().c_str());
272
System::inform("Executing command: %s", command);
273
errorStatus = std::system(command);
275
if ((argsmap.find("--post") != argsmap.end()) && !errorStatus && postPossible)
277
errorStatus = translateMaster();
278
playSoundfileName = getNormalizedSoundfileName();
280
if ((argsmap.find("--playwav") != argsmap.end()) && !errorStatus)
282
std::sprintf(command, "%s %s\n", argsmap["--playwav"].c_str(), playSoundfileName.c_str());
283
System::inform("Executing command: %s", command);
284
errorStatus = std::system(command);
286
System::inform("ENDED MusicModel::processArgv().\n");
290
void MusicModel::stop()
292
std::cout << "MusicModel::stop()..." << std::endl;