*/}}
Pārlūkot izejas kodu

Add custom audio callback

YimingWu 3 mēneši atpakaļ
vecāks
revīzija
8059100e16
3 mainītis faili ar 40 papildinājumiem un 7 dzēšanām
  1. 8 0
      la_audio.c
  2. 4 1
      la_interface.h
  3. 28 6
      la_kernel.c

+ 8 - 0
la_audio.c

@@ -839,12 +839,20 @@ int laEvalSynthGraphs(){
     return any;
 }
 
+void laSetAudioCallback(laAudioCallbackF Callback){
+    MAIN.Audio->Callback = Callback;
+}
+
 void laaudio_DataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){
     float* out=pOutput,*in=pInput; int Paused; int any=0;
     laSpinLock(&MAIN.Audio->AudioStatusLock);
     Paused = MAIN.Audio->Paused;
     laSpinUnlock(&MAIN.Audio->AudioStatusLock);
     
+    if(MAIN.Audio->Callback){
+        if(MAIN.Audio->Callback(Paused, pInput, pOutput, frameCount)) return;
+    }
+
     if(Paused){ memset(out,0,sizeof(float)*LA_SYNTH_PLEN);
         memset(MAIN.Audio->InputSamplesL,0,sizeof(float)*LA_SYNTH_PLEN);
         memset(MAIN.Audio->InputSamplesR,0,sizeof(float)*LA_SYNTH_PLEN); return;

+ 4 - 1
la_interface.h

@@ -2046,6 +2046,7 @@ STRUCTURE(laAudioDevice){
     laSafeString Name;
 };
 
+typedef int (*laAudioCallbackF)(int Paused, float* input, float* output, uint32_t framecount);
 STRUCTURE(laAudio){
     int Paused;
     
@@ -2067,9 +2068,11 @@ STRUCTURE(laAudio){
     real* InputSamplesL,*InputSamplesR;
     real *OutputSamplesL,*OutputSamplesR;
     int NextAudioSample,AudioSampleRate;//,NextInputSample;
+    
+    laAudioCallbackF Callback;
 };
 
-
+void laSetAudioCallback(laAudioCallbackF Callback);
 int laget_SynthPlaying(laSynth* ss);
 void* laget_FirstAudioDevice(void* unused1,void* unused2);
 void* laget_FirstSynth(void* unused1,void* unused2);

+ 28 - 6
la_kernel.c

@@ -8468,7 +8468,7 @@ static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *eve
     __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "123 input");
     if(!MAIN.AppEnabled){return 0;}
     //laRedrawAllWindows();
-
+    static int prev_button_state=0;
     int type = AInputEvent_getType(event);
     if(type == AINPUT_EVENT_TYPE_KEY){
         int32_t keycode = AKeyEvent_getKeyCode(event);
@@ -8519,10 +8519,18 @@ static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *eve
         int32_t action = AMotionEvent_getAction(event);
         unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
         int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+        real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
 
         if(pcount){
-            real rx=AMotionEvent_getX(event, 0), ry=AMotionEvent_getY(event, 0);
             x=rx; y=ry;
+            int tool_type=AMotionEvent_getToolType(event,0);
+            real pressure = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_PRESSURE,0);
+            if(tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS || tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER){
+                MAIN.StylusPressure = MAIN.EraserPressure = pressure; MAIN.IsPen = 1; 
+                MAIN.PointerIsEraser = (tool_type==AMOTION_EVENT_TOOL_TYPE_ERASER);
+            }else{
+                MAIN.IsPen = 0;
+            }
             if(pcount>=2 && (flags!=AMOTION_EVENT_ACTION_UP) && (flags!=AMOTION_EVENT_ACTION_CANCEL)
                 && (flags!=AMOTION_EVENT_ACTION_POINTER_UP)){
                 real x2=AMotionEvent_getX(event, 1), y2=AMotionEvent_getY(event, 1);
@@ -8560,14 +8568,28 @@ static int32_t la_AndroidInputCallback(struct android_app *app, AInputEvent *eve
             }else{
                 temp_distance = 0; cx=0; cy=0;
             }
+            if(flags==AMOTION_EVENT_ACTION_HOVER_MOVE){
+                la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
+            }
+        }else{
+            la_SendMouseEvent(0, LA_MOUSEMOVE, rx,ry);
         }
         if(!gesture_handled){
-            if (flags == AMOTION_EVENT_ACTION_DOWN){
+            if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_BUTTON_PRESS){
                 la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);
-                la_SendMouseEvent(0,LA_L_MOUSE_DOWN,x,y);
+                int btn=AMotionEvent_getButtonState(event);
+                int evtype=LA_L_MOUSE_DOWN;
+                if(btn & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_DOWN; }
+                elif(btn & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_DOWN; }
+                la_SendMouseEvent(0,evtype,x,y);
+                prev_button_state = btn;
             }
-            else if (flags == AMOTION_EVENT_ACTION_UP){
-                la_SendMouseEvent(0,LA_L_MOUSE_UP,x,y);
+            else if (flags == AMOTION_EVENT_ACTION_UP || flags == AMOTION_EVENT_ACTION_BUTTON_RELEASE){
+                int btn=AMotionEvent_getButtonState(event); int changed = (~btn)&prev_button_state; 
+                int evtype=LA_L_MOUSE_UP;
+                if(changed & AMOTION_EVENT_BUTTON_STYLUS_PRIMARY){ evtype=LA_M_MOUSE_UP; }
+                elif(changed & AMOTION_EVENT_BUTTON_STYLUS_SECONDARY){ evtype=LA_R_MOUSE_UP; }
+                la_SendMouseEvent(0,evtype,x,y);
             }
             else if (flags == AMOTION_EVENT_ACTION_MOVE){
                 la_SendMouseEvent(0,LA_MOUSEMOVE,x,y);