Signed-off-by: Xiangfu Liu <[email protected]>
---
 src/compiler.c    |   18 ++++++++++++++----
 src/compiler.h    |    6 ++++++
 src/performance.c |   31 +++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/src/compiler.c b/src/compiler.c
index e6599fa..8de071b 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -161,11 +161,19 @@ static const char 
pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
        "video_a"
 };
 
-static int pfv_from_name(const char *name)
+static int pfv_from_name(struct compiler_sc *sc, const char *name)
 {
        int i;
-       for(i=0;i<COMP_PFV_COUNT;i++)
-               if(strcmp(pfv_names[i], name) == 0) return i;
+       for(i=0;i<COMP_PFV_COUNT;i++) {
+               if(strcmp(pfv_names[i], name) == 0) {
+                       if(i >= pfv_dmx1 && i <= pfv_idmx8)     sc->p->require 
|= REQUIRE_DMX;
+                       if(i >= pfv_osc1 && i <= pfv_osc4)      sc->p->require 
|= REQUIRE_OSC;
+                       if(i >= pfv_midi1 && i <= pfv_midi8)    sc->p->require 
|= REQUIRE_MIDI;
+                       if(i == pfv_video_a)                    sc->p->require 
|= REQUIRE_VIDEO;
+                       return i;
+               }
+       }
+
        if(strcmp(name, "fDecay") == 0) return pfv_decay;
        if(strcmp(name, "nWaveMode") == 0) return pfv_wave_mode;
        if(strcmp(name, "fWaveScale") == 0) return pfv_wave_scale;
@@ -181,6 +189,8 @@ static void load_defaults(struct compiler_sc *sc)
 {
        int i;
 
+       sc->p->require = 0;
+
        for(i=0;i<COMP_PFV_COUNT;i++)
                sc->p->pfv_initial[i] = 0.0;
        sc->p->pfv_initial[pfv_sx] = 1.0;
@@ -552,7 +562,7 @@ static bool process_top_assign(struct compiler_sc *sc, char 
*left, char *right)
        while(*right == ' ') right++;
        if(*right == 0) return true;
 
-       pfv = pfv_from_name(left);
+       pfv = pfv_from_name(sc, left);
        if(pfv >= 0) {
                /* patch initial condition or global parameter */
                set_initial(sc, pfv, atof(right));
diff --git a/src/compiler.h b/src/compiler.h
index c3ee771..e139566 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -192,7 +192,13 @@ enum {
        COMP_PVV_COUNT /* must be last */
 };
 
+#define  REQUIRE_DMX   (1 << 3)
+#define  REQUIRE_OSC   (1 << 2)
+#define  REQUIRE_MIDI  (1 << 1)
+#define  REQUIRE_VIDEO (1 << 0)
+
 struct patch {
+       unsigned int require;                           /* bit: dmx, osc, midi, 
video */
        /* per-frame */
        float pfv_initial[COMP_PFV_COUNT];              /* < patch initial 
conditions */
        int pfv_allocation[COMP_PFV_COUNT];             /* < where per-frame 
variables are mapped in PFPU regf, -1 if unmapped */
diff --git a/src/performance.c b/src/performance.c
index ef5b9c6..ed04307 100644
--- a/src/performance.c
+++ b/src/performance.c
@@ -20,9 +20,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <dirent.h>
+#include <fcntl.h>
 #include <sys/stat.h>
+#include <sys/ioctl.h>
 #include <mtklib.h>
 #include <mtkeycodes.h>
+#include <bsp/milkymist_video.h>
 
 #include "input.h"
 #include "fb.h"
@@ -49,6 +52,7 @@ static struct patch_info patches[MAX_PATCHES];
 static int simple_mode;
 static int dt_mode;
 static int as_mode;
+static int input_video;
 
 static int add_patch(const char *filename)
 {
@@ -351,6 +355,23 @@ static int keycode_to_index(int keycode)
        }
 }
 
+static int check_input_require()
+{
+       int video_fd;
+       unsigned int status;
+
+       video_fd = open("/dev/video", O_RDWR);
+       if(video_fd == -1) {
+               perror("Unable to open video device");
+               return 1;
+       }
+
+       ioctl(video_fd, VIDEO_GET_SIGNAL, &status);
+       if(!(status & 0x01)) input_video = 0;
+
+       return 0;
+}
+
 static rtems_interval next_as_time;
 #define AUTOSWITCH_PERIOD 3000
 
@@ -441,6 +462,13 @@ static void refresh_callback(mtk_event *e, int count)
                                next_as_time = t + AUTOSWITCH_PERIOD;
                                input_add_callback(event_callback);
                                mtk_cmd(appid, "l_status.set(-text 
\"Ready.\")");
+
+                               if(!input_video && 
(patches[current_patch].p->require & REQUIRE_VIDEO)) {
+                                       current_patch++;
+                                       if(current_patch == npatches)
+                                               current_patch = 0;
+                               }
+
                                if(!guirender(appid, patches[current_patch].p, 
stop_callback))
                                        stop_callback();
                                return;
@@ -475,6 +503,8 @@ void start_performance(int simple, int dt, int as)
        if(started) return;
        started = 1;
 
+       input_video = 1;
+
        simple_mode = simple;
        dt_mode = dt;
        as_mode = as;
@@ -484,6 +514,7 @@ void start_performance(int simple, int dt, int as)
        npatches = 0;
        current_patch = 0;
        if(simple) {
+               check_input_require();
                add_simple_patches();
                if(npatches < 1) {
                        messagebox("Error", "No patches found!");
-- 
1.7.4.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to