Skip to content

Commit

Permalink
Simple performance working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed May 7, 2011
1 parent dc31fa5 commit 339fec4
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 51 deletions.
34 changes: 25 additions & 9 deletions src/cp.c
Expand Up @@ -15,12 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <rtems.h>
#include <stdio.h>
#include <mtklib.h>

#include "performance.h"
#include "keyboard.h"
#include "ir.h"
#include "fb.h"
#include "audio.h"
#include "midi.h"
#include "oscsettings.h"
Expand Down Expand Up @@ -176,10 +178,10 @@ static void cp_callback(mtk_event *e, void *arg)
open_firstpatch_window();
break;
case CP_ITEM_START:
start_performance();
start_performance(false);
break;
case CP_ITEM_STARTSIMPLE:
printf("TODO\n");
start_performance(true);
break;

case CP_ITEM_FILEMANAGER:
Expand Down Expand Up @@ -371,12 +373,26 @@ void cp_autostart()
{
char autostart[256];

sysconfig_get_autostart(autostart);
if(autostart[0] == 0) return;
if(!config_load(autostart)) {
messagebox("Autostart failed", "Unable to load the specified performance file.\nCheck the 'Autostart' section in the 'System settings' dialog box.");
return;
switch(sysconfig_get_autostart_mode()) {
case SC_AUTOSTART_NONE:
break;
case SC_AUTOSTART_SIMPLE:
start_performance(true);
break;
case SC_AUTOSTART_FILE:
sysconfig_get_autostart(autostart);
if(autostart[0] == 0) {
messagebox("Autostart failed", "No performance file specified.");
fb_unblank();
return;
}
if(!config_load(autostart)) {
messagebox("Autostart failed", "Unable to load the specified performance file.\nCheck the 'Autostart' section in the 'System settings' dialog box.");
fb_unblank();
return;
}
on_config_change();
start_performance(false);
break;
}
on_config_change();
start_performance();
}
10 changes: 1 addition & 9 deletions src/main.c
Expand Up @@ -78,17 +78,9 @@
#include "flash.h"
#include "filedialog.h"

static int has_autostart()
{
char autostart[256];

sysconfig_get_autostart(autostart);
return autostart[0] != 0;
}

static rtems_task gui_task(rtems_task_argument argument)
{
init_fb_mtk(has_autostart());
init_fb_mtk(sysconfig_get_autostart_mode() != SC_AUTOSTART_NONE);
sysconfig_set_mtk_wallpaper();
sysconfig_set_mtk_keyboard_layout();
init_input();
Expand Down
117 changes: 86 additions & 31 deletions src/performance.c
Expand Up @@ -16,9 +16,11 @@
*/

#include <assert.h>
#include <rtems.h>
#include <stdio.h>
#include <string.h>
#include <rtems.h>
#include <dirent.h>
#include <sys/stat.h>
#include <mtklib.h>
#include <keycodes.h>

Expand All @@ -42,6 +44,8 @@ struct patch_info {

static int npatches;
static struct patch_info patches[MAX_PATCHES];
static bool simple_mode;
static int simple_current;

static int add_patch(const char *filename)
{
Expand Down Expand Up @@ -141,6 +145,33 @@ static void add_osc_patches()
}
}

#define SIMPLE_PATCHES_FOLDER "/flash/"

static void add_simple_patches()
{
DIR *d;
struct dirent *entry;
struct stat s;
char fullname[384];
char *c;

d = opendir(SIMPLE_PATCHES_FOLDER);
if(!d)
return;
while((entry = readdir(d))) {
if(entry->d_name[0] == '.') continue;
strncpy(fullname, SIMPLE_PATCHES_FOLDER, sizeof(fullname));
strncat(fullname, entry->d_name, sizeof(fullname));
lstat(fullname, &s);
if(!S_ISDIR(s.st_mode)) {
c = strrchr(entry->d_name, '.');
if((c != NULL) && (strcmp(c, ".fnp") == 0))
add_patch(fullname);
}
}
closedir(d);
}

static int appid;
static int started;

Expand Down Expand Up @@ -260,27 +291,38 @@ static void event_callback(mtk_event *e, int count)
int i;
int index;

for(i=0;i<count;i++) {
index = -1;
if(e[i].type == EVENT_TYPE_PRESS) {
index = keycode_to_index(e[i].press.code);
if(index != -1)
index = keyboard_patches[index];
} else if(e[i].type == EVENT_TYPE_IR) {
index = e[i].press.code;
index = ir_patches[index];
} else if(e[i].type == EVENT_TYPE_MIDI) {
if(((e[i].press.code & 0x0f00) >> 8) == midi_channel) {
index = e[i].press.code & 0x7f;
index = midi_patches[index];
index = -1;
if(simple_mode) {
for(i=0;i<count;i++) {
if((e[i].type == EVENT_TYPE_PRESS) && (e[i].press.code == MTK_KEY_F11)) {
simple_current++;
if(simple_current == npatches)
simple_current = 0;
index = simple_current;
}
}
} else {
for(i=0;i<count;i++) {
if(e[i].type == EVENT_TYPE_PRESS) {
index = keycode_to_index(e[i].press.code);
if(index != -1)
index = keyboard_patches[index];
} else if(e[i].type == EVENT_TYPE_IR) {
index = e[i].press.code;
index = ir_patches[index];
} else if(e[i].type == EVENT_TYPE_MIDI) {
if(((e[i].press.code & 0x0f00) >> 8) == midi_channel) {
index = e[i].press.code & 0x7f;
index = midi_patches[index];
}
} else if(e[i].type == EVENT_TYPE_OSC) {
index = e[i].press.code & 0x3f;
index = osc_patches[index];
}
} else if(e[i].type == EVENT_TYPE_OSC) {
index = e[i].press.code & 0x3f;
index = osc_patches[index];
}
if(index != -1)
renderer_set_patch(patches[index].p);
}
if(index != -1)
renderer_set_patch(patches[index].p);
}

static void stop_callback()
Expand All @@ -303,7 +345,8 @@ static void refresh_callback(mtk_event *e, int count)
input_delete_callback(refresh_callback);
input_add_callback(event_callback);
mtk_cmd(appid, "l_text.set(-text \"Done.\")");
if(!guirender(appid, patches[firstpatch].p, stop_callback))
if(!guirender(appid, patches[simple_mode ? simple_current : firstpatch].p,
stop_callback))
stop_callback();
return;
}
Expand All @@ -324,26 +367,38 @@ static void refresh_callback(mtk_event *e, int count)

static rtems_id comp_task_id;

void start_performance()
void start_performance(bool simple)
{
rtems_status_code sc;

if(started) return;
started = 1;

/* build patch list */
simple_mode = simple;
npatches = 0;
add_firstpatch();
if(npatches < 1) {
messagebox("Error", "No first patch defined!\n");
started = 0;
fb_unblank();
return;
simple_current = 0;
if(simple) {
add_simple_patches();
if(npatches < 1) {
messagebox("Error", "No patches found!\n");
started = 0;
fb_unblank();
return;
}
} else {
add_firstpatch();
if(npatches < 1) {
messagebox("Error", "No first patch defined!\n");
started = 0;
fb_unblank();
return;
}
add_keyboard_patches();
add_ir_patches();
add_midi_patches();
add_osc_patches();
}
add_keyboard_patches();
add_ir_patches();
add_midi_patches();
add_osc_patches();

/* start patch compilation task */
compiled_patches = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/performance.h
@@ -1,6 +1,6 @@
/*
* Flickernoise
* Copyright (C) 2010 Sebastien Bourdeauducq
* Copyright (C) 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,6 @@
#define __PERFORMANCE_H

void init_performance();
void start_performance();
void start_performance(bool simple);

#endif /* __PERFORMANCE_H */

0 comments on commit 339fec4

Please sign in to comment.