void testApp::loadDylib(string file) { mutex->lock(); if(livecodeLib!=NULL) { dlclose(livecodeLib); delete eff; livecodeLib = NULL; } livecodeLib = dlopen(file.c_str(), RTLD_LAZY); if (livecodeLib == NULL) { // report error ... printf("Error: No dice loading %s\n", file.c_str()); } else { // use the result in a call to dlsym printf("Success loading\n"); void *ptrFunc = dlsym(livecodeLib, "getAudioEffect"); if(ptrFunc!=NULL) { AudioEffect *e = ((AudioEffect *(*)())ptrFunc)(); e->setup(); doGui(e); eff = e; } else { printf("Couldn't find the getAudioEffect() function\n"); } } mutex->unlock(); }
static jint android_media_AudioEffect_native_command(JNIEnv *env, jobject thiz, jint cmdCode, jint cmdSize, jbyteArray jCmdData, jint replySize, jbyteArray jReplyData) { jbyte* pCmdData = NULL; jbyte* pReplyData = NULL; jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; // retrieve the AudioEffect object AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz, fields.fidNativeAudioEffect); if (lpAudioEffect == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Unable to retrieve AudioEffect pointer for setParameter()"); return AUDIOEFFECT_ERROR_NO_INIT; } if ((cmdSize != 0 && jCmdData == NULL) || (replySize != 0 && jReplyData == NULL)) { return AUDIOEFFECT_ERROR_BAD_VALUE; } // get the pointer for the command from the java array if (cmdSize != 0) { pCmdData = (jbyte *) env->GetPrimitiveArrayCritical(jCmdData, NULL); if (pCmdData == NULL) { ALOGE("setParameter: Error retrieving command pointer"); goto command_Exit; } } // get the pointer for the reply from the java array if (replySize != 0 && jReplyData != NULL) { pReplyData = (jbyte *) env->GetPrimitiveArrayCritical(jReplyData, NULL); if (pReplyData == NULL) { ALOGE("setParameter: Error retrieving reply pointer"); goto command_Exit; } } lStatus = translateError(lpAudioEffect->command((uint32_t)cmdCode, (uint32_t)cmdSize, pCmdData, (uint32_t *)&replySize, pReplyData)); command_Exit: if (pCmdData != NULL) { env->ReleasePrimitiveArrayCritical(jCmdData, pCmdData, 0); } if (pReplyData != NULL) { env->ReleasePrimitiveArrayCritical(jReplyData, pReplyData, 0); } if (lStatus == NO_ERROR) { return replySize; } return lStatus; }
PUBLIC AEffect* VSTPluginMain(audioMasterCallback audioMaster) { if (!audioMaster (0, audioMasterVersion, 0, 0, 0, 0)) { return 0; } AudioEffect* effect = new CsoundVST(audioMaster); if (!effect) { return 0; } return effect->getAeffect(); }
//----------------------------------------------------------------------------- long dispatchEffectClass(AEffect * e, long opCode, long index, long value, void *ptr, float opt) { AudioEffect *ae = (AudioEffect *) (e->object); if (opCode == effClose) { ae->dispatcher(opCode, index, value, ptr, opt); delete ae; return 1; } return ae->dispatcher(opCode, index, value, ptr, opt); }
//------------------------------------------------------------------------ VST_EXPORT __declspec(dllexport) int main(audioMasterCallback audioMaster) { // Get VST Version if (!audioMaster (0, audioMasterVersion, 0, 0, 0, 0)) return 0; // old version // Create the AudioEffect AudioEffect* effect = createEffectInstance (audioMaster); if (!effect) return 0; return (int)effect->getAeffect (); }
//------------------------------------------------------------------------------------------------------- VstIntPtr AudioEffect::dispatchEffectClass (AEffect* e, VstInt32 opCode, VstInt32 index, VstIntPtr value, void* ptr, float opt) { AudioEffect* ae = (AudioEffect*)(e->object); if (opCode == effClose) { ae->dispatcher (opCode, index, value, ptr, opt); delete ae; return 1; } return ae->dispatcher (opCode, index, value, ptr, opt); }
VST_EXPORT AEffect* VSTInstrumentMain (audioMasterCallback audioMaster) { // Get VST Version of the Host if (!audioMaster (0, audioMasterVersion, 0, 0, 0, 0)) return 0; // old version // Create the AudioEffect AudioEffect* effect = createEffectInstance (audioMaster,true); if (!effect) return 0; // Return the VST AEffect structur return effect->getAeffect (); }
static jint android_media_AudioEffect_native_setEnabled(JNIEnv *env, jobject thiz, jboolean enabled) { // retrieve the AudioEffect object AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( thiz, fields.fidNativeAudioEffect); if (lpAudioEffect == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Unable to retrieve AudioEffect pointer for enable()"); return AUDIOEFFECT_ERROR_NO_INIT; } return translateError(lpAudioEffect->setEnabled(enabled)); }
static jboolean android_media_AudioEffect_native_getEnabled(JNIEnv *env, jobject thiz) { // retrieve the AudioEffect object AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( thiz, fields.fidNativeAudioEffect); if (lpAudioEffect == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Unable to retrieve AudioEffect pointer for getEnabled()"); return false; } return (jboolean)lpAudioEffect->getEnabled(); }
AEffect *main (audioMasterCallback audioMaster) { // get vst version if (!audioMaster (0, audioMasterVersion, 0, 0, 0, 0)) return 0; // old version AudioEffect* effect = new LowPass(audioMaster); if (!effect) return 0; if (oome) { delete effect; return 0; } return effect->getAeffect (); }
static jboolean android_media_AudioEffect_native_hasControl(JNIEnv *env, jobject thiz) { // retrieve the AudioEffect object AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField( thiz, fields.fidNativeAudioEffect); if (lpAudioEffect == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Unable to retrieve AudioEffect pointer for hasControl()"); return false; } if (lpAudioEffect->initCheck() == NO_ERROR) { return true; } else { return false; } }
virtual long open(void *ptr) { AEffEditor::open(ptr); if(!m_view.m_hWnd) { m_synth->SetCurrentPatchIndex(vsti->getProgram()); HWND m_hWndClient = m_view.Create((HWND)ptr); //, CWindow::rcDefault, "v2 frame", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); } //if (m_view.m_hWnd) m_view.SetWindowPos(0,0,0,420/*+10*/+280 -10,570+110,SWP_NOZORDER|SWP_SHOWWINDOW); return (long)m_view.m_hWnd; }
void AudioEffect::processClassDoubleReplacing (AEffect* e, double** inputs, double** outputs, VstInt32 sampleFrames) { AudioEffect* ae = (AudioEffect*)(e->object); ae->processDoubleReplacing (inputs, outputs, sampleFrames); }
//----------------------------------------------------------------------------- void processClassReplacing(AEffect *e, float **inputs, float **outputs, long sampleFrames) { AudioEffect *ae = (AudioEffect *)(e->object); ae->processReplacing(inputs, outputs, sampleFrames); }
//----------------------------------------------------------------------------- void setParameterClass(AEffect *e, long index, float value) { AudioEffect *ae = (AudioEffect *)(e->object); ae->setParameter(index, value); }
//----------------------------------------------------------------------------- float getParameterClass(AEffect *e, long index) { AudioEffect *ae = (AudioEffect *)(e->object); return ae->getParameter(index); }
static jint android_media_AudioEffect_native_getParameter(JNIEnv *env, jobject thiz, int psize, jbyteArray pJavaParam, jintArray pJavaValueSize, jbyteArray pJavaValue) { // retrieve the AudioEffect object jbyte* lpParam = NULL; jbyte* lpValue = NULL; jbyte* lpValueSize = NULL; jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; effect_param_t *p; int voffset; AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz, fields.fidNativeAudioEffect); if (lpAudioEffect == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Unable to retrieve AudioEffect pointer for getParameter()"); return AUDIOEFFECT_ERROR_NO_INIT; } if (psize == 0 || pJavaValueSize == NULL || pJavaParam == NULL || pJavaValue == NULL) { return AUDIOEFFECT_ERROR_BAD_VALUE; } // get the pointer for the param from the java array lpParam = (jbyte *) env->GetPrimitiveArrayCritical(pJavaParam, NULL); if (lpParam == NULL) { LOGE("getParameter: Error retrieving param pointer"); goto getParameter_Exit; } // get the pointer for the value from the java array lpValue = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValue, NULL); if (lpValue == NULL) { LOGE("getParameter: Error retrieving value pointer"); goto getParameter_Exit; } // get the pointer for the value size from the java array lpValueSize = (jbyte *) env->GetPrimitiveArrayCritical(pJavaValueSize, NULL); if (lpValueSize == NULL) { LOGE("getParameter: Error retrieving value size pointer"); goto getParameter_Exit; } voffset = ((psize - 1) / sizeof(int) + 1) * sizeof(int); p = (effect_param_t *) malloc(sizeof(effect_param_t) + voffset + lpValueSize[0]); memcpy(p->data, lpParam, psize); p->psize = psize; p->vsize = lpValueSize[0]; lStatus = lpAudioEffect->getParameter(p); if (lStatus == NO_ERROR) { lStatus = p->status; if (lStatus == NO_ERROR) { memcpy(lpValue, p->data + voffset, p->vsize); lpValueSize[0] = p->vsize; } } free(p); getParameter_Exit: if (lpParam != NULL) { env->ReleasePrimitiveArrayCritical(pJavaParam, lpParam, 0); } if (lpValue != NULL) { env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0); } if (lpValueSize != NULL) { env->ReleasePrimitiveArrayCritical(pJavaValueSize, lpValueSize, 0); } return translateError(lStatus); }
static jint android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_this, jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId, jobjectArray javadesc) { LOGV("android_media_AudioEffect_native_setup"); AudioEffectJniStorage* lpJniStorage = NULL; int lStatus = AUDIOEFFECT_ERROR_NO_MEMORY; AudioEffect* lpAudioEffect = NULL; jint* nId = NULL; const char *typeStr = NULL; const char *uuidStr = NULL; effect_descriptor_t desc; jobject jdesc; char str[EFFECT_STRING_LEN_MAX]; jstring jdescType; jstring jdescUuid; jstring jdescConnect; jstring jdescName; jstring jdescImplementor; if (type != NULL) { typeStr = env->GetStringUTFChars(type, NULL); if (typeStr == NULL) { // Out of memory jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); goto setup_failure; } } if (uuid != NULL) { uuidStr = env->GetStringUTFChars(uuid, NULL); if (uuidStr == NULL) { // Out of memory jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); goto setup_failure; } } if (typeStr == NULL && uuidStr == NULL) { lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; goto setup_failure; } lpJniStorage = new AudioEffectJniStorage(); if (lpJniStorage == NULL) { LOGE("setup: Error creating JNI Storage"); goto setup_failure; } lpJniStorage->mCallbackData.audioEffect_class = (jclass)env->NewGlobalRef(fields.clazzEffect); // we use a weak reference so the AudioEffect object can be garbage collected. lpJniStorage->mCallbackData.audioEffect_ref = env->NewGlobalRef(weak_this); LOGV("setup: lpJniStorage: %p audioEffect_ref %p audioEffect_class %p, &mCallbackData %p", lpJniStorage, lpJniStorage->mCallbackData.audioEffect_ref, lpJniStorage->mCallbackData.audioEffect_class, &lpJniStorage->mCallbackData); if (jId == NULL) { LOGE("setup: NULL java array for id pointer"); lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; goto setup_failure; } // create the native AudioEffect object lpAudioEffect = new AudioEffect(typeStr, uuidStr, priority, effectCallback, &lpJniStorage->mCallbackData, sessionId, 0); if (lpAudioEffect == NULL) { LOGE("Error creating AudioEffect"); goto setup_failure; } lStatus = translateError(lpAudioEffect->initCheck()); if (lStatus != AUDIOEFFECT_SUCCESS && lStatus != AUDIOEFFECT_ERROR_ALREADY_EXISTS) { LOGE("AudioEffect initCheck failed %d", lStatus); goto setup_failure; } nId = (jint *) env->GetPrimitiveArrayCritical(jId, NULL); if (nId == NULL) { LOGE("setup: Error retrieving id pointer"); lStatus = AUDIOEFFECT_ERROR_BAD_VALUE; goto setup_failure; } nId[0] = lpAudioEffect->id(); env->ReleasePrimitiveArrayCritical(jId, nId, 0); nId = NULL; if (typeStr) { env->ReleaseStringUTFChars(type, typeStr); typeStr = NULL; } if (uuidStr) { env->ReleaseStringUTFChars(uuid, uuidStr); uuidStr = NULL; } // get the effect descriptor desc = lpAudioEffect->descriptor(); AudioEffect::guidToString(&desc.type, str, EFFECT_STRING_LEN_MAX); jdescType = env->NewStringUTF(str); AudioEffect::guidToString(&desc.uuid, str, EFFECT_STRING_LEN_MAX); jdescUuid = env->NewStringUTF(str); if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { jdescConnect = env->NewStringUTF("Auxiliary"); } else { jdescConnect = env->NewStringUTF("Insert"); } jdescName = env->NewStringUTF(desc.name); jdescImplementor = env->NewStringUTF(desc.implementor); jdesc = env->NewObject(fields.clazzDesc, fields.midDescCstor, jdescType, jdescUuid, jdescConnect, jdescName, jdescImplementor); env->DeleteLocalRef(jdescType); env->DeleteLocalRef(jdescUuid); env->DeleteLocalRef(jdescConnect); env->DeleteLocalRef(jdescName); env->DeleteLocalRef(jdescImplementor); if (jdesc == NULL) { LOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)"); goto setup_failure; } env->SetObjectArrayElement(javadesc, 0, jdesc); env->SetIntField(thiz, fields.fidNativeAudioEffect, (int)lpAudioEffect); env->SetIntField(thiz, fields.fidJniData, (int)lpJniStorage); return AUDIOEFFECT_SUCCESS; // failures: setup_failure: if (nId != NULL) { env->ReleasePrimitiveArrayCritical(jId, nId, 0); } if (lpAudioEffect) { delete lpAudioEffect; } env->SetIntField(thiz, fields.fidNativeAudioEffect, 0); if (lpJniStorage) { delete lpJniStorage; } env->SetIntField(thiz, fields.fidJniData, 0); if (uuidStr != NULL) { env->ReleaseStringUTFChars(uuid, uuidStr); } if (typeStr != NULL) { env->ReleaseStringUTFChars(type, typeStr); } return lStatus; }
//------------------------------------------------------------------------------------------------------- void AudioEffect::DECLARE_VST_DEPRECATED (processClass) (AEffect* e, float** inputs, float** outputs, VstInt32 sampleFrames) { AudioEffect* ae = (AudioEffect*)(e->object); ae->DECLARE_VST_DEPRECATED (process) (inputs, outputs, sampleFrames); }
//------------------------------------------------------------------------------------------------------- void AudioEffect::setParameterClass (AEffect* e, VstInt32 index, float value) { AudioEffect* ae = (AudioEffect*)(e->object); ae->setParameter (index, value); }
//------------------------------------------------------------------------------------------------------- float AudioEffect::getParameterClass (AEffect* e, VstInt32 index) { AudioEffect* ae = (AudioEffect*)(e->object); return ae->getParameter (index); }