SHARE
TWEET

Untitled

a guest Jan 14th, 2014 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <jni.h>
  3. #include <android/log.h>
  4. extern void timidity_start_initialize(void);
  5. extern int timidity_pre_load_configuration(void);
  6. extern int timidity_post_load_configuration(void);
  7. extern void timidity_init_player(void);
  8. extern int timidity_play_main(int nfiles, char **files);
  9. extern int got_a_configuration;
  10. char* configFile;
  11. char* configFile2;
  12. JavaVM  *jvm;
  13. JNIEnv *theGoodEnv;
  14. JNIEXPORT int JNICALL
  15. Java_com_xperia64_timidityae20_MainActivity_prepare(JNIEnv * env, jobject  obj, jstring config, jstring config2)
  16. {
  17.         (*env)->GetJavaVM(env, &jvm); // Store java vm for later
  18.                 jboolean isCopy;
  19.         configFile=(*env)->GetStringUTFChars(env, config, &isCopy);
  20.         configFile2=(*env)->GetStringUTFChars(env, config2, &isCopy);
  21.         int err;
  22.          __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Called RunIt!");
  23.     timidity_start_initialize();
  24.  
  25.         __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Initing Timidity!");
  26.  
  27.  
  28.     if ((err = timidity_pre_load_configuration()) != 0)
  29.         return err;
  30.         __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "No preload err!");
  31.     err += timidity_post_load_configuration();
  32.  
  33.     if (err) {
  34.                 __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Couldn't load config! (who cares)");
  35.         printf("couldn't load configuration file\n");
  36.         // return 1;
  37.     }
  38.         __android_log_print(ANDROID_LOG_ERROR, "TIMIDITY", "No postload err!");
  39.     timidity_init_player();
  40.         __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Initing Player!");
  41.         (*env)->ReleaseStringUTFChars(env, config, configFile);
  42.         (*env)->ReleaseStringUTFChars(env, config2, configFile2);
  43.         return 0;
  44. }
  45. JNIEXPORT int JNICALL
  46. Java_com_xperia64_timidityae20_MainActivity_mainzes(JNIEnv * env, jobject  obj, jstring song)
  47. {
  48.        
  49. (*jvm)->AttachCurrentThread(jvm, &theGoodEnv,NULL);
  50.         int main_ret;
  51.                 jboolean isCopy;
  52.         char** filez = NULL;
  53.         filez = malloc(sizeof(char*) * 1);
  54.  
  55.         filez[0]=(*env)->GetStringUTFChars(env, song, &isCopy); ;
  56.  
  57.         main_ret = timidity_play_main(1, filez);
  58.         __android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Playing!");
  59.         (*env)->ReleaseStringUTFChars(env, song, filez[0]);
  60.     return main_ret;
  61.  
  62. }
  63.  
  64. char* getConfig()
  65. {
  66.         return configFile;
  67. }
  68. char* getConfig2()
  69. {
  70.         return configFile2;
  71. }
  72. int nativePush(char* buf, int nframes)
  73. {
  74.        
  75.         jclass clazz = (*theGoodEnv)->FindClass(theGoodEnv, "com/xperia64/timidityae20/MainActivity");
  76.         jmethodID buffit = (*theGoodEnv)->GetStaticMethodID(theGoodEnv, clazz, "buffit", "([BI)V");
  77.         jbyteArray byteArr = (*theGoodEnv)->NewByteArray(theGoodEnv, nframes+1);
  78.         (*theGoodEnv)->SetByteArrayRegion(theGoodEnv, byteArr , 0, nframes, (jbyte *)buf);
  79.         (*theGoodEnv)->CallStaticVoidMethod(theGoodEnv, clazz, buffit, byteArr, nframes);
  80.         (*theGoodEnv)->DeleteLocalRef(theGoodEnv, byteArr);
  81.         (*theGoodEnv)->DeleteLocalRef(theGoodEnv, clazz);
  82.        
  83.         return 0;
  84. }
  85. void finishPlaying()
  86. {
  87.        
  88.         //exit(0); //? do nothing
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top