diff --git a/.clang-format b/.clang-format index ecaad8c..d72017b 100644 --- a/.clang-format +++ b/.clang-format @@ -20,7 +20,7 @@ SpacesInContainerLiterals: 'true' SpacesInParentheses: 'true' SpacesInSquareBrackets: 'true' TabWidth: '4' -UseTab: Always +UseTab: AlignWithSpaces FixNamespaceComments: 'true' IndentCaseLabels: 'true' diff --git a/colorchord2/main.c b/colorchord2/main.c index b409b09..d0def45 100644 --- a/colorchord2/main.c +++ b/colorchord2/main.c @@ -58,18 +58,18 @@ void HandleDestroy() #define GENLINEWIDTH 89 -#define GENLINES 67 +#define GENLINES 67 char genlog[ ( GENLINEWIDTH + 1 ) * ( GENLINES + 1 ) + 2 ] = "log"; int genloglen; int genloglines; -int genlinelen = 0; +int genlinelen = 0; int firstnewline = -1; void example_log_function( int readSize, char *buf ) { static og_mutex_t *mt; - if ( !mt ) mt = OGCreateMutex(); + if ( !mt ) mt = OGCreateMutex(); OGLockMutex( mt ); for ( int i = 0; readSize && i <= readSize && buf[ i ]; i++ ) { @@ -80,15 +80,15 @@ void example_log_function( int readSize, char *buf ) genloglines++; if ( genloglines >= GENLINES ) { - genloglen -= firstnewline + 1; - int offset = firstnewline; + genloglen -= firstnewline + 1; + int offset = firstnewline; firstnewline = -1; int k; for ( k = 0; k < genloglen; k++ ) { if ( ( genlog[ k ] = genlog[ k + offset + 1 ] ) == '\n' && firstnewline < 0 ) firstnewline = k; - } + } genlog[ k ] = 0; genloglines--; } @@ -96,12 +96,12 @@ void example_log_function( int readSize, char *buf ) if ( c != '\n' ) { genlog[ genloglen + 1 ] = 0; - genlog[ genloglen++ ] = '\n'; + genlog[ genloglen++ ] = '\n'; } if ( firstnewline < 0 ) firstnewline = genloglen; } genlog[ genloglen + 1 ] = 0; - genlog[ genloglen++ ] = c; + genlog[ genloglen++ ] = c; if ( c != '\n' ) genlinelen++; } @@ -129,14 +129,14 @@ int lastfps; short screenx, screeny; struct DriverInstances *outdriver[ MAX_OUT_DRIVERS ]; -int headless = 0; REGISTER_PARAM( headless, PAINT ); -int set_screenx = 640; REGISTER_PARAM( set_screenx, PAINT ); -int set_screeny = 480; REGISTER_PARAM( set_screeny, PAINT ); -char sound_source[ 16 ]; REGISTER_PARAM( sound_source, PABUFFER ); -int cpu_autolimit = 1; REGISTER_PARAM( cpu_autolimit, PAINT ); -float cpu_autolimit_interval = 0.016; REGISTER_PARAM( cpu_autolimit_interval, PAFLOAT ); -int sample_channel = -1; REGISTER_PARAM( sample_channel, PAINT ); -int showfps = 1; REGISTER_PARAM( showfps, PAINT ); +int headless = 0; REGISTER_PARAM( headless, PAINT ); +int set_screenx = 640; REGISTER_PARAM( set_screenx, PAINT ); +int set_screeny = 480; REGISTER_PARAM( set_screeny, PAINT ); +char sound_source[ 16 ]; REGISTER_PARAM( sound_source, PABUFFER ); +int cpu_autolimit = 1; REGISTER_PARAM( cpu_autolimit, PAINT ); +float cpu_autolimit_interval = 0.016; REGISTER_PARAM( cpu_autolimit_interval, PAFLOAT ); +int sample_channel = -1; REGISTER_PARAM( sample_channel, PAINT ); +int showfps = 1; REGISTER_PARAM( showfps, PAINT ); #if defined( ANDROID ) || defined( __android__ ) float in_amplitude = 2; @@ -148,13 +148,13 @@ REGISTER_PARAM( in_amplitude, PAFLOAT ); struct NoteFinder *nf; // Sound circular buffer -#define SOUNDCBSIZE 8096 +#define SOUNDCBSIZE 8096 #define MAX_CHANNELS 2 double VisTimeEnd, VisTimeStart; float sound[ SOUNDCBSIZE ]; -int soundhead = 0; -int show_debug = 0; +int soundhead = 0; +int show_debug = 0; int show_debug_basic = 1; int gKey = 0; @@ -178,14 +178,14 @@ void HandleKey( int keycode, int bDown ) return; } #endif - if( keycode == ESCAPE_KEY ) exit( 0 ); - if( c == 'W' ) force_white = bDown; - if( c == 'D' && bDown ) show_debug = !show_debug; - if( c == '9' && bDown ) { gKey--; RecalcBaseHz(); } - if( c == '-' && bDown ) { gKey++; RecalcBaseHz(); } - if( c == '0' && bDown ) { gKey = 0; RecalcBaseHz(); } - if( c == 'E' && bDown ) show_debug_basic = !show_debug_basic; - if( c == 'K' && bDown ) DumpParameters(); + if( keycode == ESCAPE_KEY ) exit( 0 ); + if( c == 'W' ) force_white = bDown; + if( c == 'D' && bDown ) show_debug = !show_debug; + if( c == '9' && bDown ) { gKey--; RecalcBaseHz(); } + if( c == '-' && bDown ) { gKey++; RecalcBaseHz(); } + if( c == '0' && bDown ) { gKey = 0; RecalcBaseHz(); } + if( c == 'E' && bDown ) show_debug_basic = !show_debug_basic; + if( c == 'K' && bDown ) DumpParameters(); printf( "Key: %d -> %d\n", keycode, bDown ); KeyHappened( keycode, bDown ); } @@ -237,14 +237,14 @@ void SoundCB( struct CNFADriver *sd, short *out, short *in, int framesp, int fra } fo /= channelin; sound[ soundhead ] = fo * in_amplitude; - soundhead = ( soundhead + 1 ) % SOUNDCBSIZE; + soundhead = ( soundhead + 1 ) % SOUNDCBSIZE; } else { float f = in[ i * channelin + sample_channel ] / 32767.; if ( f > 1 || f < -1 ) f = ( f > 0 ) ? 1 : -1; sound[ soundhead ] = f * in_amplitude; - soundhead = ( soundhead + 1 ) % SOUNDCBSIZE; + soundhead = ( soundhead + 1 ) % SOUNDCBSIZE; } } SoundEventHappened( framesr, in, 0, channelin ); @@ -329,7 +329,7 @@ int main( int argc, char **argv ) WSADATA wsaData; WSAStartup( 0x202, &wsaData ); #elif defined( ANDROID ) - int hasperm = AndroidHasPermissions( "READ_EXTERNAL_STORAGE" ); + int hasperm = AndroidHasPermissions( "READ_EXTERNAL_STORAGE" ); int haspermInternet = AndroidHasPermissions( "INTERNET" ); if ( !hasperm ) AndroidRequestAppPermissions( "READ_EXTERNAL_STORAGE" ); if ( !haspermInternet ) AndroidRequestAppPermissions( "INTERNET" ); @@ -346,10 +346,10 @@ int main( int argc, char **argv ) int frames = 0; double ThisTime; double SecToWait; - double LastFPSTime = OGGetAbsoluteTime(); - double LastFrameTime = OGGetAbsoluteTime(); - CNFGBGColor = 0x800000; - CNFGDialogColor = 0x444444; + double LastFPSTime = OGGetAbsoluteTime(); + double LastFrameTime = OGGetAbsoluteTime(); + CNFGBGColor = 0x800000; + CNFGDialogColor = 0x444444; // Generate the window title char title[ 1024 ]; @@ -453,9 +453,9 @@ int main( int argc, char **argv ) if ( !headless ) { // Handle outputs. - int freqbins = nf->freqbins; + int freqbins = nf->freqbins; int note_peaks = freqbins / 2; - int freqs = freqbins * nf->octaves; + int freqs = freqbins * nf->octaves; // Do a bunch of debugging. if ( show_debug_basic && !is_suspended ) @@ -473,11 +473,11 @@ int main( int argc, char **argv ) // Draw the folded bins for ( int bin = 0; bin < freqbins; bin++ ) { - const float x0 = bin / ( float )freqbins * ( float )screenx; - const float x1 = ( bin + 1 ) / ( float )freqbins * ( float )screenx; - const float amp = nf->folded_bins[ bin ] * 250.0; + const float x0 = bin / ( float )freqbins * ( float )screenx; + const float x1 = ( bin + 1 ) / ( float )freqbins * ( float )screenx; + const float amp = nf->folded_bins[ bin ] * 250.0; const float note = ( float )( bin + 0.5 ) / freqbins; - CNFGDialogColor = CCtoHEX( note, 1.0, 1.0 ); + CNFGDialogColor = CCtoHEX( note, 1.0, 1.0 ); CNFGDrawBox( x0, 400 - amp, x1, 400 ); } CNFGDialogColor = 0xf0f000; @@ -486,12 +486,12 @@ int main( int argc, char **argv ) for ( int peak = 0; peak < note_peaks; peak++ ) { if ( nf->note_amplitudes_out[ peak ] < 0 ) continue; - float note = ( float )nf->note_positions[ peak ] / freqbins; + float note = ( float )nf->note_positions[ peak ] / freqbins; CNFGDialogColor = CCtoHEX( note, 1.0, 1.0 ); - const int x1 = ( ( float )peak / note_peaks ) * screenx; - const int x2 = ( ( float )( peak + 1 ) / note_peaks ) * screenx; - const int y1 = 480 - nf->note_amplitudes_out[ peak ] * 100; - const int y2 = 480; + const int x1 = ( ( float )peak / note_peaks ) * screenx; + const int x2 = ( ( float )( peak + 1 ) / note_peaks ) * screenx; + const int y1 = 480 - nf->note_amplitudes_out[ peak ] * 100; + const int y2 = 480; CNFGDrawBox( x1, y1, x2, y2 ); CNFGPenX = ( ( float )( peak + .4 ) / note_peaks ) * screenx; @@ -503,16 +503,16 @@ int main( int argc, char **argv ) // Let's draw the o-scope. int thissoundhead = soundhead; - thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; - int lasty = sound[ thissoundhead ] * 128 + 128; - thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; - int thisy = sound[ thissoundhead ] * 128 + 128; - thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; + thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; + int lasty = sound[ thissoundhead ] * 128 + 128; + thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; + int thisy = sound[ thissoundhead ] * 128 + 128; + thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; for ( int i = 0; i < screenx; i++ ) { CNFGTackSegment( i, lasty, i + 1, thisy ); - lasty = thisy; - thisy = sound[ thissoundhead ] * 128 + 128; + lasty = thisy; + thisy = sound[ thissoundhead ] * 128 + 128; thissoundhead = ( thissoundhead - 1 + SOUNDCBSIZE ) % SOUNDCBSIZE; } } @@ -542,10 +542,10 @@ int main( int argc, char **argv ) // Draw the bins for ( int bin = 0; bin < freqs; bin++ ) { - float x0 = bin / ( float )freqs * ( float )screenx; - float x1 = ( bin + 1 ) / ( float )freqs * ( float )screenx; - float amp = nf->outbins[ bin ] * 250.0; - float note = ( float )bin / freqbins; + float x0 = bin / ( float )freqs * ( float )screenx; + float x1 = ( bin + 1 ) / ( float )freqs * ( float )screenx; + float amp = nf->outbins[ bin ] * 250.0; + float note = ( float )bin / freqbins; CNFGDialogColor = CCtoHEX( note, 1.0, 1.0 ); CNFGDrawBox( x0, 0, x1, amp ); } @@ -606,7 +606,7 @@ int main( int argc, char **argv ) printf( "FPS: %d\n", frames ); #endif lastfps = frames; - frames = 0; + frames = 0; LastFPSTime += 1; }