Skip to content

Commit

Permalink
performance: skip advanced patches and patches using unavailable vide…
Browse files Browse the repository at this point in the history
…o on patch switch
  • Loading branch information
Sebastien Bourdeauducq committed Sep 18, 2011
1 parent f8e9008 commit 2776d11
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
11 changes: 5 additions & 6 deletions src/compiler.h
Expand Up @@ -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 */
Expand All @@ -218,4 +218,3 @@ struct patch *patch_compile(const char *patch_code, report_message rmc);
void patch_free(struct patch *p);

#endif /* __COMPILER_H */

70 changes: 44 additions & 26 deletions src/performance.c
Expand Up @@ -21,6 +21,7 @@
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <mtklib.h>
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
Expand Down Expand Up @@ -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) {
Expand All @@ -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))
Expand Down Expand Up @@ -496,25 +500,39 @@ 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;

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!");
Expand Down

0 comments on commit 2776d11

Please sign in to comment.