From 2776d11c50d88aa88f4372adabace3803004779e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 18 Sep 2011 14:32:30 +0200 Subject: [PATCH] performance: skip advanced patches and patches using unavailable video on patch switch --- src/compiler.h | 11 ++++---- src/performance.c | 70 +++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/compiler.h b/src/compiler.h index e139566..db0ba2e 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -192,13 +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) +#define REQUIRE_DMX (1 << 0) +#define REQUIRE_OSC (1 << 1) +#define REQUIRE_MIDI (1 << 2) +#define REQUIRE_VIDEO (1 << 3) struct patch { - unsigned int require; /* bit: dmx, osc, midi, video */ + unsigned int require; /* < bitmask: 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 */ @@ -218,4 +218,3 @@ struct patch *patch_compile(const char *patch_code, report_message rmc); void patch_free(struct patch *p); #endif /* __COMPILER_H */ - diff --git a/src/performance.c b/src/performance.c index ed04307..5deea4c 100644 --- a/src/performance.c +++ b/src/performance.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -355,32 +356,28 @@ 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 +static int suitable_for_simple(struct patch *p) +{ + int suitable; + + suitable = 1; + if(p->require & REQUIRE_DMX) suitable = 0; + if(p->require & REQUIRE_OSC) suitable = 0; + if(p->require & REQUIRE_MIDI) suitable = 0; + if((p->require & REQUIRE_VIDEO) && !input_video) suitable = 0; + return suitable; +} + static void event_callback(mtk_event *e, int count) { int i; int index; int next; rtems_interval t; + int looped; index = -1; if(simple_mode) { @@ -401,11 +398,14 @@ static void event_callback(mtk_event *e, int count) } } if(next) { - current_patch += next; - if(current_patch == npatches) - current_patch = 0; - if(current_patch < 0) - current_patch = npatches - 1; + looped = current_patch; + do { + current_patch += next; + if(current_patch == npatches) + current_patch = 0; + if(current_patch < 0) + current_patch = npatches - 1; + } while(!suitable_for_simple(patches[current_patch].p) && (looped != current_patch)); index = current_patch; } if(dt_mode && (index != -1)) @@ -451,6 +451,7 @@ static void stop_callback() static void refresh_callback(mtk_event *e, int count) { rtems_interval t; + int looped; t = rtems_clock_get_ticks_since_boot(); if(t >= next_update) { @@ -463,10 +464,13 @@ static void refresh_callback(mtk_event *e, int count) input_add_callback(event_callback); mtk_cmd(appid, "l_status.set(-text \"Ready.\")"); - if(!input_video && (patches[current_patch].p->require & REQUIRE_VIDEO)) { + looped = current_patch; + while(!suitable_for_simple(patches[current_patch].p)) { current_patch++; if(current_patch == npatches) current_patch = 0; + if(looped == current_patch) + break; } if(!guirender(appid, patches[current_patch].p, stop_callback)) @@ -496,6 +500,22 @@ void open_performance_window() static rtems_id comp_task_id; +static int check_input_video() +{ + int fd; + unsigned int status; + + fd = open("/dev/video", O_RDWR); + if(fd == -1) { + perror("Unable to open video device"); + return 0; + } + ioctl(fd, VIDEO_GET_SIGNAL, &status); + status &= 0x01; + close(fd); + return status; +} + void start_performance(int simple, int dt, int as) { rtems_status_code sc; @@ -503,18 +523,16 @@ 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; + input_video = check_input_video(); open_performance_window(); /* build patch list */ npatches = 0; current_patch = 0; if(simple) { - check_input_require(); add_simple_patches(); if(npatches < 1) { messagebox("Error", "No patches found!");