From 000261ace5b456585d3e116c6b14b714d51a2cde Mon Sep 17 00:00:00 2001 From: Laptop Date: Fri, 26 Jun 2015 17:00:04 -0400 Subject: [PATCH] update from Merge --- RecorderPlugin.c | 63 +++++++++++++++++++++++++++++++++++++++--------- hook.c | 4 ++- main.c | 21 +++++++++++++--- outdrivers.c | 2 +- outdrivers.h | 2 +- 5 files changed, 74 insertions(+), 18 deletions(-) diff --git a/RecorderPlugin.c b/RecorderPlugin.c index 0583ee8..5ae41fc 100644 --- a/RecorderPlugin.c +++ b/RecorderPlugin.c @@ -4,9 +4,16 @@ #include #include #include +#include +#include #include "parameters.h" #include "hook.h" + +extern unsigned char OutLEDs[MAX_LEDS*3]; +extern int UsedLEDs; + + struct RecorderPlugin { int is_recording; @@ -29,11 +36,12 @@ void StopRecording( struct RecorderPlugin * rp ) rp->TimeSinceStart = 0; rp->DunBoop = 0; - fclose( rp->fRec ); - fclose( rp->fPlay ); + if( rp->fRec ) fclose( rp->fRec ); + if( rp->fPlay) fclose( rp->fPlay ); rp->is_recording = 0; rp->fRec = 0; rp->fPlay = 0; + printf( "Stopped.\n" ); } void StartRecording( struct RecorderPlugin * rp ) @@ -44,6 +52,8 @@ void StartRecording( struct RecorderPlugin * rp ) rp->DunBoop = 0; rp->is_recording = 1; + printf( "Starting Recording: /%s/%s/\n", rp->In_Filename, rp->Out_Filename ); + if( rp->In_Filename[0] == 0 ) { //Nothing @@ -56,6 +66,7 @@ void StartRecording( struct RecorderPlugin * rp ) { fprintf( stderr, "Warning: Could not play filename: %s\n", rp->In_Filename ); } + printf( "Play file opened.\n" ); } if( rp->Out_Filename[0] == 0 ) @@ -65,10 +76,11 @@ void StartRecording( struct RecorderPlugin * rp ) } else { + struct stat buf; + char cts[1024]; int i; for( i = 0; i < 999; i++ ) { - char cts[1024]; if( i == 0 ) { snprintf( cts, 1023, "%s", rp->Out_Filename ); @@ -78,9 +90,17 @@ void StartRecording( struct RecorderPlugin * rp ) snprintf( cts, 1023, "%s.%03d", rp->Out_Filename, i ); } - rp->fRec = fopen( cts, "wb" ); - if( rp->fRec ) break; + if( stat( cts, &buf ) != 0 ) + break; } + printf( "Found rec file %s\n", cts ); + rp->fRec = fopen( cts, "wb" ); + if( !rp->fRec ) + { + fprintf( stderr, "Error: cannot start recording file \"%s\"\n", cts ); + return; + } + printf( "Recording...\n" ); } } @@ -88,6 +108,7 @@ void StartRecording( struct RecorderPlugin * rp ) static void RecordEvent(void * v, int samples, float * samps, int channel_ct) { struct RecorderPlugin * rp = (struct RecorderPlugin*)v; + if( !rp->fRec || !rp->is_recording ) return; if( rp->DunBoop || !rp->fPlay ) @@ -105,15 +126,20 @@ static void PlaybackEvent(void * v, int samples, float * samps, int channel_ct) struct RecorderPlugin * rp = (struct RecorderPlugin*)v; if( !rp->fPlay ) return; + int r = fread( samps, channel_ct * sizeof( float ), samples, rp->fPlay ); + if( r != samples ) + { + StopRecording( rp ); + } + rp->TimeSinceStart += samples; + if( rp->TimeSinceStart < rp->BypassLength ) { - int r = fread( samps, channel_ct * sizeof( float ), samples, rp->fPlay ); - if( r != samples ) - { - StopRecording( rp ); - } + if( rp->is_recording ) + force_white = 1; + else + force_white = 0; - rp->TimeSinceStart += samples; if( rp->TimeSinceStart > rp->BypassLength ) { rp->DunBoop = 1; @@ -127,6 +153,10 @@ static void PlaybackEvent(void * v, int samples, float * samps, int channel_ct) } } } + else + { + force_white = 0; + } } static void MKeyEvent( void * v, int keycode, int down ) @@ -146,7 +176,18 @@ static void DPOUpdate(void * id, struct NoteFinder*nf) static void DPOParams(void * id ) { struct RecorderPlugin * d = (struct RecorderPlugin*)id; + d->is_recording = 0; + d->fRec = 0; + d->fPlay = 0; + d->DunBoop = 0; + d->TimeSinceStart = 0; + + memset( d->In_Filename, 0, PARAM_BUFF ); RegisterValue( "player_filename", PABUFFER, d->In_Filename, PARAM_BUFF ); + memset( d->Out_Filename, 0, PARAM_BUFF ); RegisterValue( "recorder_filename", PABUFFER, d->Out_Filename, PARAM_BUFF ); + d->sps = 0; RegisterValue( "samplerate", PAINT, &d->sps, sizeof( d->sps ) ); + d->BypassLength = 0; RegisterValue( "recorder_bypass", PAINT, &d->BypassLength, sizeof( d->BypassLength ) ); + } static struct DriverInstances * RecorderPlugin(const char * parameters) diff --git a/hook.c b/hook.c index 97c2dbd..299759a 100644 --- a/hook.c +++ b/hook.c @@ -25,6 +25,7 @@ void HookKeyEvent( void (*KeyE)( void * v, int key, int down ), void * v ) { KeyEvents[i].KeyE = KeyE; KeyEvents[i].v = v; + break; } } } @@ -54,6 +55,7 @@ struct SoundEvent void (*SoundE)( void * v, int samples, float * samps, int channel_ct ); void * v; }; + struct SoundEvent SoundEvents[2][MAX_SOUND_EVENTS]; @@ -64,7 +66,6 @@ void SoundEventHappened( int samples, float * samps, int is_out, int channel_ct { if( SoundEvents[is_out][i].SoundE ) { - printf( "%d\n", i ); SoundEvents[is_out][i].SoundE( SoundEvents[is_out][i].v, samples, samps, channel_ct ); } } @@ -79,6 +80,7 @@ void HookSoundInEvent( void (*SoundE)( void * v, int samples, float * samps, int { SoundEvents[is_out][i].SoundE = SoundE; SoundEvents[is_out][i].v = v; + break; } } } diff --git a/main.c b/main.c index fd83569..75abcf9 100644 --- a/main.c +++ b/main.c @@ -123,11 +123,13 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun else { float f = in[i*channelin+sample_channel]; - if( f > -1 && f < 1 ) - { + + if( f > 1 || f < -1 ) + { f = (f>0)?1:-1; } + //printf( "Sound fault B %d/%d\n", i, samplesr ); sound[soundhead] = f; soundhead = (soundhead+1)%SOUNDCBSIZE; @@ -135,8 +137,8 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun } } - SoundEventHappened( samplesr, in, channelin, 0 ); - SoundEventHappened( samplesr, out, sd->channelsPlay, 1 ); + SoundEventHappened( samplesr, in, 0, channelin ); + SoundEventHappened( samplesr, out, 1, sd->channelsPlay ); *samplesp = samplesr; } @@ -334,13 +336,24 @@ int main(int argc, char ** argv) RunNoteFinder( nf, sound, (soundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE, SOUNDCBSIZE ); //Done all ColorChord work. + VisTimeStart = OGGetAbsoluteTime(); + for( i = 0; i < MAX_OUT_DRIVERS; i++ ) + { + + if( force_white ) + { + memset( OutLEDs, 0x7f, MAX_LEDS*3 ); + } + if( outdriver[i] ) outdriver[i]->Func( outdriver[i]->id, nf ); + } VisTimeEnd = OGGetAbsoluteTime(); + if( !headless ) { //Handle outputs. diff --git a/outdrivers.c b/outdrivers.c index 1e7a7e3..8bf9b77 100644 --- a/outdrivers.c +++ b/outdrivers.c @@ -5,7 +5,7 @@ #include #include - +int force_white = 0; unsigned char OutLEDs[MAX_LEDS*3]; int UsedLEDs; diff --git a/outdrivers.h b/outdrivers.h index 63a7ef4..106ea52 100644 --- a/outdrivers.h +++ b/outdrivers.h @@ -10,7 +10,7 @@ struct NoteFinder; #define MAX_LEDS 32678 - +extern int force_white; extern unsigned char OutLEDs[MAX_LEDS*3]; extern int UsedLEDs;