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 DSPServer::stop(MHD_Connection* connection, dsp_server_connection_info* info) { if (stop(info->fInstanceKey)) { return sendPage(connection, "", MHD_HTTP_OK, "text/html"); } else { return sendPage(connection, builtError(ERROR_INSTANCE_NOTFOUND), MHD_HTTP_BAD_REQUEST, "text/html"); } }
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 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; }