Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 2 contributors
18  src/compiler.c
@@ -161,11 +161,19 @@ static const char pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
161 161
 	"video_a"
162 162
 };
163 163
 
164  
-static int pfv_from_name(const char *name)
  164
+static int pfv_from_name(struct compiler_sc *sc, const char *name)
165 165
 {
166 166
 	int i;
167  
-	for(i=0;i<COMP_PFV_COUNT;i++)
168  
-		if(strcmp(pfv_names[i], name) == 0) return i;
  167
+	for(i=0;i<COMP_PFV_COUNT;i++) {
  168
+		if(strcmp(pfv_names[i], name) == 0) {
  169
+			if(i >= pfv_dmx1 && i <= pfv_idmx8)	sc->p->require |= REQUIRE_DMX;
  170
+			if(i >= pfv_osc1 && i <= pfv_osc4)	sc->p->require |= REQUIRE_OSC;
  171
+			if(i >= pfv_midi1 && i <= pfv_midi8)	sc->p->require |= REQUIRE_MIDI;
  172
+			if(i == pfv_video_a)			sc->p->require |= REQUIRE_VIDEO;
  173
+			return i;
  174
+		}
  175
+	}
  176
+
169 177
 	if(strcmp(name, "fDecay") == 0) return pfv_decay;
170 178
 	if(strcmp(name, "nWaveMode") == 0) return pfv_wave_mode;
171 179
 	if(strcmp(name, "fWaveScale") == 0) return pfv_wave_scale;
@@ -181,6 +189,8 @@ static void load_defaults(struct compiler_sc *sc)
181 189
 {
182 190
 	int i;
183 191
 
  192
+	sc->p->require = 0;
  193
+
184 194
 	for(i=0;i<COMP_PFV_COUNT;i++)
185 195
 		sc->p->pfv_initial[i] = 0.0;
186 196
 	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)
552 562
 	while(*right == ' ') right++;
553 563
 	if(*right == 0) return true;
554 564
 
555  
-	pfv = pfv_from_name(left);
  565
+	pfv = pfv_from_name(sc, left);
556 566
 	if(pfv >= 0) {
557 567
 		/* patch initial condition or global parameter */
558 568
 		set_initial(sc, pfv, atof(right));
7  src/compiler.h
@@ -192,7 +192,13 @@ enum {
192 192
 	COMP_PVV_COUNT /* must be last */
193 193
 };
194 194
 
  195
+#define REQUIRE_DMX	(1 << 0)
  196
+#define REQUIRE_OSC	(1 << 1)
  197
+#define REQUIRE_MIDI	(1 << 2)
  198
+#define REQUIRE_VIDEO	(1 << 3)
  199
+
195 200
 struct patch {
  201
+	unsigned int require;				/* < bitmask: dmx, osc, midi, video */
196 202
 	/* per-frame */
197 203
 	float pfv_initial[COMP_PFV_COUNT]; 		/* < patch initial conditions */
198 204
 	int pfv_allocation[COMP_PFV_COUNT];		/* < where per-frame variables are mapped in PFPU regf, -1 if unmapped */
@@ -212,4 +218,3 @@ struct patch *patch_compile(const char *patch_code, report_message rmc);
212 218
 void patch_free(struct patch *p);
213 219
 
214 220
 #endif /* __COMPILER_H */
215  
-
59  src/performance.c
@@ -20,9 +20,13 @@
20 20
 #include <stdio.h>
21 21
 #include <string.h>
22 22
 #include <dirent.h>
  23
+#include <fcntl.h>
  24
+#include <unistd.h>
23 25
 #include <sys/stat.h>
  26
+#include <sys/ioctl.h>
24 27
 #include <mtklib.h>
25 28
 #include <mtkeycodes.h>
  29
+#include <bsp/milkymist_video.h>
26 30
 
27 31
 #include "input.h"
28 32
 #include "fb.h"
@@ -49,6 +53,7 @@ static struct patch_info patches[MAX_PATCHES];
49 53
 static int simple_mode;
50 54
 static int dt_mode;
51 55
 static int as_mode;
  56
+static int input_video;
52 57
 
53 58
 static int add_patch(const char *filename)
54 59
 {
@@ -354,12 +359,25 @@ static int keycode_to_index(int keycode)
354 359
 static rtems_interval next_as_time;
355 360
 #define AUTOSWITCH_PERIOD 3000
356 361
 
  362
+static int suitable_for_simple(struct patch *p)
  363
+{
  364
+	int suitable;
  365
+	
  366
+	suitable = 1;
  367
+	if(p->require & REQUIRE_DMX) suitable = 0;
  368
+	if(p->require & REQUIRE_OSC) suitable = 0;
  369
+	if(p->require & REQUIRE_MIDI) suitable = 0;
  370
+	if((p->require & REQUIRE_VIDEO) && !input_video) suitable = 0;
  371
+	return suitable;
  372
+}
  373
+
357 374
 static void event_callback(mtk_event *e, int count)
358 375
 {
359 376
 	int i;
360 377
 	int index;
361 378
 	int next;
362 379
 	rtems_interval t;
  380
+	int looped;
363 381
 
364 382
 	index = -1;
365 383
 	if(simple_mode) {
@@ -380,11 +398,14 @@ static void event_callback(mtk_event *e, int count)
380 398
 			}
381 399
 		}
382 400
 		if(next) {
383  
-			current_patch += next;
384  
-			if(current_patch == npatches)
385  
-				current_patch = 0;
386  
-			if(current_patch < 0)
387  
-				current_patch = npatches - 1;
  401
+			looped = current_patch;
  402
+			do {
  403
+				current_patch += next;
  404
+				if(current_patch == npatches)
  405
+					current_patch = 0;
  406
+				if(current_patch < 0)
  407
+					current_patch = npatches - 1;
  408
+			} while(!suitable_for_simple(patches[current_patch].p) && (looped != current_patch));
388 409
 			index = current_patch;
389 410
 		}
390 411
 		if(dt_mode && (index != -1))
@@ -430,6 +451,7 @@ static void stop_callback()
430 451
 static void refresh_callback(mtk_event *e, int count)
431 452
 {
432 453
 	rtems_interval t;
  454
+	int looped;
433 455
 	
434 456
 	t = rtems_clock_get_ticks_since_boot();
435 457
 	if(t >= next_update) {
@@ -441,6 +463,16 @@ static void refresh_callback(mtk_event *e, int count)
441 463
 				next_as_time = t + AUTOSWITCH_PERIOD;
442 464
 				input_add_callback(event_callback);
443 465
 				mtk_cmd(appid, "l_status.set(-text \"Ready.\")");
  466
+
  467
+				looped = current_patch;
  468
+				while(!suitable_for_simple(patches[current_patch].p)) {
  469
+					current_patch++;
  470
+					if(current_patch == npatches)
  471
+						current_patch = 0;
  472
+					if(looped == current_patch)
  473
+						break;
  474
+				}
  475
+
444 476
 				if(!guirender(appid, patches[current_patch].p, stop_callback))
445 477
 					stop_callback();
446 478
 				return;
@@ -468,6 +500,22 @@ void open_performance_window()
468 500
 
469 501
 static rtems_id comp_task_id;
470 502
 
  503
+static int check_input_video()
  504
+{
  505
+	int fd;
  506
+	unsigned int status;
  507
+
  508
+	fd = open("/dev/video", O_RDWR);
  509
+	if(fd == -1) {
  510
+		perror("Unable to open video device");
  511
+		return 0;
  512
+	}
  513
+	ioctl(fd, VIDEO_GET_SIGNAL, &status);
  514
+	status &= 0x01;
  515
+	close(fd);
  516
+	return status;
  517
+}
  518
+
471 519
 void start_performance(int simple, int dt, int as)
472 520
 {
473 521
 	rtems_status_code sc;
@@ -478,6 +526,7 @@ void start_performance(int simple, int dt, int as)
478 526
 	simple_mode = simple;
479 527
 	dt_mode = dt;
480 528
 	as_mode = as;
  529
+	input_video = check_input_video();
481 530
 	open_performance_window();
482 531
 
483 532
 	/* build patch list */

No commit comments for this range

Something went wrong with that request. Please try again.