bool DSPServer::deleteFactory(MHD_Connection* connection, dsp_server_connection_info* info) { // Returns the factory (with incremented reference counter) #ifdef LLVM_DSP_FACTORY dsp_factory* factory = getDSPFactoryFromSHAKey(info->fSHAKey); #else dsp_factory* factory = getInterpreterDSPFactoryFromSHAKey(info->fSHAKey); #endif if (factory) { // Remove from the list fFactories.erase(factory); // Has to be done twice since getDSPFactoryFromSHAKey has incremented once more... #ifdef LLVM_DSP_FACTORY deleteDSPFactory(dynamic_cast<llvm_dsp_factory*>(factory)); deleteDSPFactory(dynamic_cast<llvm_dsp_factory*>(factory)); #else deleteInterpreterDSPFactory(dynamic_cast<interpreter_dsp_factory*>(factory)); deleteInterpreterDSPFactory(dynamic_cast<interpreter_dsp_factory*>(factory)); #endif return sendPage(connection, "", MHD_HTTP_OK, "text/html"); } else { return sendPage(connection, builtError(ERROR_FACTORY_NOTFOUND), MHD_HTTP_BAD_REQUEST, "text/html"); } }
bool dsp_server_connection_info::getFactoryFromSHAKey(DSPServer* server) { // Will increment factory reference counter... llvm_dsp_factory* factory = getDSPFactoryFromSHAKey(fSHAKey); //llvm_dsp_factory* factory = getCDSPFactoryFromSHAKey(fSHAKey.c_str()); if (factory) { getJson(factory); return true; } else { fAnswer = "Factory not found"; return false; } }
bool dsp_server_connection_info::getFactoryFromSHAKey(DSPServer* server) { // Will increment factory reference counter... #ifdef LLVM_DSP_FACTORY dsp_factory* factory = getDSPFactoryFromSHAKey(fSHAKey); #else dsp_factory* factory = getInterpreterDSPFactoryFromSHAKey(fSHAKey); #endif if (factory) { getJson(factory); return true; } else { fAnswer = "Factory not found"; return false; } }
bool DSPServer::deleteFactory(MHD_Connection* connection, dsp_server_connection_info* info) { // Returns the factory (with incremented reference counter) llvm_dsp_factory* factory = getDSPFactoryFromSHAKey(info->fSHAKey); //llvm_dsp_factory* factory = getCDSPFactoryFromSHAKey(info->fSHAKey.c_str()); if (factory) { // Remove from the list fFactories.erase(factory); // Has to be done twice since getDSPFactoryFromSHAKey has incremented once more... deleteDSPFactory(factory); deleteDSPFactory(factory); return sendPage(connection, "", MHD_HTTP_OK, "text/html"); } else { return sendPage(connection, builtError(ERROR_FACTORY_NOTFOUND), MHD_HTTP_BAD_REQUEST, "text/html"); } }
// Create DSP Factory llvm_dsp_factory* dsp_server_connection_info::crossCompileFactory(DSPServer* server, string& error) { llvm_dsp_factory* factory; // Already in the cache... if ((factory = getDSPFactoryFromSHAKey(fSHAKey))) { // if ((factory = getCDSPFactoryFromSHAKey(fSHAKey.c_str()))) { return factory; } else { // Sort out compilation options int argc = fCompilationOptions.size(); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } /* char error1[256]; factory = createCDSPFactoryFromString(fNameApp.c_str(), fFaustCode.c_str(), argc, argv, fTarget.c_str(), error1, atoi(fOptLevel.c_str())); */ string error1; factory = createDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, fTarget, error1, atoi(fOptLevel.c_str())); error = error1; if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; } }
// Create DSP Instance bool DSPServer::createInstance(dsp_server_connection_info* con_info) { #ifdef LLVM_DSP_FACTORY dsp_factory* factory = getDSPFactoryFromSHAKey(con_info->fSHAKey); #else dsp_factory* factory = getInterpreterDSPFactoryFromSHAKey(con_info->fSHAKey); #endif audio_dsp* audio = NULL; dsp* dsp = NULL; if (factory) { try { if (con_info->fAudioType == "kNetJack") { std::cout << con_info->fPoly << " " << con_info->fVoices << " " << con_info->fGroup << std::endl; #ifdef NETJACK audio = new netjack_dsp(factory, con_info->fCompression, con_info->fIP, con_info->fPort, con_info->fMTU, con_info->fLatency, factory->getName(), con_info->fInstanceKey, con_info->fPoly, con_info->fVoices, con_info->fGroup, fCreateDSPInstanceCb, fCreateDSPInstanceCb_arg, fDeleteDSPInstanceCb, fDeleteDSPInstanceCb_arg); pthread_t thread; AudioStarter* starter = new AudioStarter(this, audio); if (pthread_create(&thread, NULL, DSPServer::open, starter) != 0) { goto error; } #endif } else if (con_info->fAudioType == "kLocalAudio") { /* // Steph : 06/15 if (!(dsp = factory->createDSPInstance())) { return false; } if (fCreateDSPInstanceCb) { fCreateDSPInstanceCb(dsp, fCreateDSPInstanceCb_arg); } */ audio = new audio_dsp(factory, atoi(con_info->fPoly.c_str()), atoi(con_info->fVoices.c_str()), atoi(con_info->fGroup.c_str()), atoi(con_info->fOSC.c_str()), atoi(con_info->fHTTPD.c_str()), atoi(con_info->fMIDI.c_str()), factory->getName(), //getCName(factory), con_info->fInstanceKey, fCreateDSPInstanceCb, fCreateDSPInstanceCb_arg, fDeleteDSPInstanceCb, fDeleteDSPInstanceCb_arg); //if (audio->init(atoi(con_info->fSampleRate.c_str()), atoi(con_info->fBufferSize.c_str()))) { if (audio->init(22050, 1024)) { fRunningDsp.push_back(audio); } else { delete audio; } } } catch (...) { goto error; } // Not more use of the locally needed factory (actually only decrement it's reference counter...) #ifdef LLVM_DSP_FACTORY deleteDSPFactory(dynamic_cast<llvm_dsp_factory*>(factory)); #else deleteInterpreterDSPFactory(dynamic_cast<interpreter_dsp_factory*>(factory)); #endif return true; } else { con_info->fAnswer = builtError(ERROR_FACTORY_NOTFOUND); return false; } error: con_info->fAnswer = builtError(ERROR_INSTANCE_NOTCREATED); return false; }
// Create DSP Factory dsp_factory* dsp_server_connection_info::crossCompileFactory(DSPServer* server, string& error) { dsp_factory* factory; // Already in the cache... #ifdef LLVM_DSP_FACTORY if ((factory = getDSPFactoryFromSHAKey(fSHAKey))) { #else if ((factory = getInterpreterDSPFactoryFromSHAKey(fSHAKey))) { #endif return factory; } else { // Sort out compilation options int argc = int(fCompilationOptions.size()); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } string error1; #ifdef LLVM_DSP_FACTORY factory = createDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, fTarget, error1, atoi(fOptLevel.c_str())); #else factory = createInterpreterDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, error1); #endif error = error1; if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; } } // Create DSP Factory dsp_factory* dsp_server_connection_info::createFactory(DSPServer* server, string& error) { // Sort out compilation options int argc = fCompilationOptions.size(); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } dsp_factory* factory = NULL; if (isopt(argc, argv, "-lm")) { // Machine code #ifdef LLVM_DSP_FACTORY factory = readDSPFactoryFromMachine(fFaustCode, loptions(argv, "-lm", "")); #else factory = readInterpreterDSPFactoryFromMachine(fFaustCode); #endif } else { // DSP code string error1; #ifdef LLVM_DSP_FACTORY factory = createDSPFactoryFromString(fNameApp,fFaustCode, argc, argv, "", error, atoi(fOptLevel.c_str())); #else factory = createInterpreterDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, error); #endif error = error1; } if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; }