History

will it compile?

Ge Wang committed 9 years ago

Commit bb2ec141 parent a61578a5 files · +242 −302Browse files

Unified · Split

5 files
  1. src/core/chuck.cpp +156 −5
  2. src/core/chuck.h +7 −1
  3. src/core/chuck_errmsg.cpp +5 −5
  4. src/core/chuck_errmsg.h +3 −3
  5. src/host/chuck_main.cpp +71 −288
src/core/chuck.cpp+156−5
@@ -38,8 +38,19 @@ · 37 unmodified lines
3838 #include "chuck_errmsg.h"
3939 #include "chuck_otf.h"
4040 #include "ulib_machine.h"
41+#include "util_network.h"
4142 #include "util_string.h"
4243
44+#ifndef __PLATFORM_WIN32__
45+#include <unistd.h>
46+#include <netinet/in.h>
47+#include <arpa/inet.h>
48+#include <sys/param.h> // added 1.3.0.0
49+#else
50+#include <direct.h> // added 1.3.0.0
51+#define MAXPATHLEN (255) // addec 1.3.0.0
52+#endif // #ifndef __PLATFORM_WIN32__
53+
4354
4455
4556
@@ -49,10 +60,12 @@ · 3 unmodified lines
4960 #define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"
5061 #define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"
5162 #define CHUCK_PARAM_VM_HALT_DEFAULT "0"
63+#define CHUCK_PARAM_OTF_ENABLE_DEFAULT "0"
5264 #define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"
5365 #define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"
5466 #define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"
5567 #define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""
68+#define CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT "1"
5669 #define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""
5770
5871
@@ -155,22 +168,26 @@ void ChucK::initDefaultParams() · 96 unmodified lines
155168 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;
156169 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;
157170 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;
171+ m_params[CHUCK_PARAM_OTF_ENABLE] = CHUCK_PARAM_OTF_ENABLE_DEFAULT;
158172 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;
159173 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;
160174 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;
161175 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;
162176 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;
177+ m_params[CHUCK_PARAM_CHUGIN_ENABLE] = CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT;
163178
164179 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;
165180 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;
166181 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;
167182 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;
168183 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;
184+ ck_param_types[CHUCK_PARAM_OTF_ENABLE] = ck_param_int;
169185 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;
170186 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;
171187 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;
172188 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;
173189 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;
190+ ck_param_types[CHUCK_PARAM_CHUGIN_ENABLE] = ck_param_int;
174191 }
175192
176193
@@ -300,6 +317,11 @@ std::string ChucK::getParamString( const std::string & key ) · 123 unmodified lines
300317 //-----------------------------------------------------------------------------
301318 bool ChucK::init()
302319 {
320+ Chuck_VM_Code * code = NULL;
321+ Chuck_VM_Shred * shred = NULL;
322+ std::string cwd;
323+ char cstr_cwd[MAXPATHLEN];
324+
303325 // sanity check
304326 if( m_carrier->vm != NULL )
305327 {
@@ -320,7 +342,7 @@ bool ChucK::init() · 14 unmodified lines
320342 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );
321343 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );
322344 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );
323− // TODO: chugin load option
345+
324346 // list of search pathes (added 1.3.0.0)
325347 std::list<std::string> dl_search_path;
326348 if( workingDir != std::string("") )
@@ -333,8 +355,7 @@ bool ChucK::init() · 6 unmodified lines
333355 }
334356 // list of individually named chug-ins (added 1.3.0.0)
335357 std::list<std::string> named_dls;
336−
337−
358+
338359 // instantiate VM
339360 m_carrier->vm = new Chuck_VM();
340361 // reference back to carrier
@@ -345,6 +366,14 @@ bool ChucK::init() · 4 unmodified lines
345366 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );
346367 goto cleanup;
347368 }
369+
370+ // if chugin load is off, then clear the lists (added 1.3.0.0 -- TODO: refactor)
371+ if( getParamInt( CHUCK_PARAM_CHUGIN_ENABLE ) == 0 )
372+ {
373+ // turn off chugin load
374+ dl_search_path.clear();
375+ named_dls.clear();
376+ }
348377
349378 // instantiate compiler
350379 m_carrier->compiler = new Chuck_Compiler();
@@ -371,11 +400,105 @@ bool ChucK::init() · 20 unmodified lines
371400 goto cleanup;
372401 }
373402
374− // TODO: load chugins
403+ // figure out current working directory (added 1.3.0.0)
404+ // is this needed for current path to work correctly?!
405+ if( getcwd(cstr_cwd, MAXPATHLEN) == NULL )
406+ {
407+ // uh...
408+ EM_log( CK_LOG_SEVERE, "error: unable to determine current working directory!" );
409+ }
410+ else
411+ {
412+ cwd = std::string(cstr_cwd);
413+ cwd = normalize_directory_separator(cwd) + "/";
414+ }
415+
416+ // whether or not chug should be enabled (added 1.3.0.0)
417+ if( getParamInt( CHUCK_PARAM_CHUGIN_ENABLE ) != 0 )
418+ {
419+ // log
420+ EM_log( CK_LOG_SEVERE, "pre-loading ChucK libs..." );
421+ EM_pushlog();
422+
423+ // iterate over list of ck files that the compiler found
424+ for( std::list<std::string>::iterator j =
425+ compiler()->m_cklibs_to_preload.begin();
426+ j != compiler()->m_cklibs_to_preload.end(); j++)
427+ {
428+ // the filename
429+ std::string filename = *j;
430+
431+ // log
432+ EM_log( CK_LOG_SEVERE, "preloading '%s'...", filename.c_str() );
433+ // push indent
434+ EM_pushlog();
435+
436+ // SPENCERTODO: what to do for full path
437+ std::string full_path = filename;
438+
439+ // parse, type-check, and emit
440+ if( compiler()->go( filename, NULL, NULL, full_path ) )
441+ {
442+ // TODO: how to compilation handle?
443+ //return 1;
444+
445+ // get the code
446+ code = compiler()->output();
447+ // name it - TODO?
448+ // code->name += string(argv[i]);
449+
450+ // spork it
451+ shred = vm()->spork( code, NULL, TRUE );
452+ }
453+
454+ // pop indent
455+ EM_poplog();
456+ }
457+
458+ // clear the list of chuck files to preload
459+ compiler()->m_cklibs_to_preload.clear();
460+
461+ // pop log
462+ EM_poplog();
463+ }
375464
376465 // load user namespace
377466 m_carrier->env->load_user_namespace();
378467
468+ // server
469+ if( getParamInt( CHUCK_PARAM_OTF_ENABLE ) != 0 )
470+ {
471+ m_carrier->otf_port = getParamInt( CHUCK_PARAM_OTF_PORT );
472+ // log
473+ EM_log( CK_LOG_SYSTEM, "starting listener on port: %d...",
474+ m_carrier->otf_port );
475+
476+ // start tcp server
477+ m_carrier->otf_socket = ck_tcp_create( 1 );
478+ if( !m_carrier->otf_socket ||
479+ !ck_bind( m_carrier->otf_socket, m_carrier->otf_port ) ||
480+ !ck_listen( m_carrier->otf_socket, 10 ) )
481+ {
482+ CK_FPRINTF_STDERR( "[chuck]: cannot bind to tcp port %li...\n", m_carrier->otf_port );
483+ ck_close( m_carrier->otf_socket );
484+ m_carrier->otf_socket = NULL;
485+ }
486+ else
487+ {
488+#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
489+ pthread_create( &m_carrier->otf_thread, NULL, otf_cb, NULL );
490+#else
491+ m_carrier->otf_thread = CreateThread( NULL, 0,
492+ (LPTHREAD_START_ROUTINE)otf_cb, NULL, 0, 0 );
493+#endif
494+ }
495+ }
496+ else
497+ {
498+ // log
499+ EM_log( CK_LOG_SYSTEM, "OTF server/listener: OFF" );
500+ }
501+
379502 // did user init?
380503 m_init = TRUE;
381504
@@ -495,6 +618,9 @@ bool ChucK::compileFile( const std::string & path, const std::string & argsToget · 113 unmodified lines
495618 // pop indent
496619 EM_poplog();
497620
621+ // reset the parser
622+ reset_parse();
623+
498624 return true;
499625 }
500626
@@ -567,7 +693,10 @@ bool ChucK::compileCode( const std::string & code, const std::string & argsToget · 66 unmodified lines
567693
568694 // pop indent
569695 EM_poplog();
570−
696+
697+ // reset the parser
698+ reset_parse();
699+
571700 return true;
572701 }
573702
@@ -758,6 +887,28 @@ void ChucK::finalCleanup() · 184 unmodified lines
758887
759888
760889
890+//-----------------------------------------------------------------------------
891+// set log level -- this should eventually be per-VM?
892+//-----------------------------------------------------------------------------
893+void ChucK::setLogLevel( t_CKINT level )
894+{
895+ EM_setlog( level );
896+}
897+
898+
899+
900+
901+//-----------------------------------------------------------------------------
902+// get log level -- also per-VM?
903+//-----------------------------------------------------------------------------
904+t_CKINT ChucK::getLogLevel()
905+{
906+ return g_loglevel;
907+}
908+
909+
910+
911+
761912 //-----------------------------------------------------------------------------
762913 // name: poop()
763914 // desc: --poop
src/core/chuck.h+7−1
@@ -45,6 +45,7 @@ · 44 unmodified lines
4545 #include "ulib_machine.h"
4646 #include "util_math.h"
4747 #include "util_string.h"
48+#include "hidio_sdl.h"
4849 #include "midiio_rtmidi.h"
4950 #include <string>
5051 #include <map>
@@ -58,12 +59,13 @@ · 7 unmodified lines
5859 #define CHUCK_PARAM_OUTPUT_CHANNELS "OUTPUT_CHANNELS"
5960 #define CHUCK_PARAM_VM_ADAPTIVE "VM_ADAPTIVE"
6061 #define CHUCK_PARAM_VM_HALT "VM_HALT"
62+#define CHUCK_PARAM_OTF_ENABLE "OTF_ENABLE"
6163 #define CHUCK_PARAM_OTF_PORT "OTF_PORT"
62−#define CHUCK_PARAM_LOG_LEVEL "LOG_LEVEL"
6364 #define CHUCK_PARAM_DUMP_INSTRUCTIONS "DUMP_INSTRUCTIONS"
6465 #define CHUCK_PARAM_AUTO_DEPEND "AUTO_DEPEND"
6566 #define CHUCK_PARAM_DEPRECATE_LEVEL "DEPRECATE_LEVEL"
6667 #define CHUCK_PARAM_WORKING_DIRECTORY "WORKING_DIRECTORY"
68+#define CHUCK_PARAM_CHUGIN_ENABLE "CHUGIN_ENABLE"
6769 #define CHUCK_PARAM_CHUGIN_DIRECTORY "CHUGIN_DIRECTORY"
6870
6971
@@ -151,6 +153,10 @@ public: // static functions · 81 unmodified lines
151153 static t_CKUINT numVMs() { return o_numVMs; };
152154 // --poop compatibilty
153155 static void poop();
156+ // set log level -- this should eventually be per-VM?
157+ static void setLogLevel( t_CKINT level );
158+ // get log level -- also per-VM?
159+ static t_CKINT getLogLevel();
154160
155161 protected:
156162 // chuck version
src/core/chuck_errmsg.cpp+5−5
@@ -55,8 +55,8 @@ static const size_t LASTERROR_SIZE = 1024; · 54 unmodified lines
5555 static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)";
5656 static size_t g_lasterrorIndex = strlen(g_lasterror);
5757 // log globals
58−int g_loglevel = CK_LOG_CORE;
59−int g_logstack = 0;
58+t_CKINT g_loglevel = CK_LOG_CORE;
59+t_CKINT g_logstack = 0;
6060 XMutex g_logmutex;
6161
6262 // more local globals
@@ -553,7 +553,7 @@ void EM_error3( const char * message, ... ) · 490 unmodified lines
553553
554554
555555 // log
556−void EM_log( int level, const char * message, ... )
556+void EM_log( t_CKINT level, const char * message, ... )
557557 {
558558 va_list ap;
559559
@@ -582,14 +582,14 @@ void EM_log( int level, const char * message, ... ) · 22 unmodified lines
582582
583583
584584 // set log level
585−void EM_setlog( int level )
585+void EM_setlog( t_CKINT level )
586586 {
587587 if( level > CK_LOG_CRAZY ) level = CK_LOG_CRAZY;
588588 else if( level < CK_LOG_NONE ) level = CK_LOG_NONE;
589589 g_loglevel = level;
590590
591591 // log this
592− EM_log( CK_LOG_SYSTEM, "setting log level to: %i (%s)...", level, g_str[level] );
592+ EM_log( CK_LOG_SYSTEM, "setting log level to: %li (%s)...", level, g_str[level] );
593593 }
594594
595595 // push log
src/core/chuck_errmsg.h+3−3
@@ -146,13 +146,13 @@ extern ChuckOutStream g_ck_stderrstream; · 145 unmodified lines
146146
147147
148148
149−void EM_log( int, c_constr, ... );
150−void EM_setlog( int );
149+void EM_log( t_CKINT, c_constr, ... );
150+void EM_setlog( t_CKINT );
151151 void EM_pushlog();
152152 void EM_poplog();
153153
154154 // actual level
155−extern int g_loglevel;
155+extern t_CKINT g_loglevel;
156156 // macro to compare
157157 #define DO_LOG(x) ( x <= g_loglevel )
158158
src/host/chuck_main.cpp+71−288
@@ -53,7 +53,7 @@ void cb( t_CKSAMPLE * in, t_CKSAMPLE * out, t_CKUINT numFrames, · 52 unmodified lines
5353
5454 // C functions
5555 extern "C" void signal_int( int sig_num );
56−
56+extern "C" void signal_pipe( int sig_num );
5757
5858
5959
@@ -67,7 +67,7 @@ CHUCK_THREAD g_tid_shell = 0; · 7 unmodified lines
6767 // default destination host name
6868 char g_otf_dest[256] = "127.0.0.1";
6969 // otf listener port
70−t_CKUINT g_otf_port = 8888;
70+t_CKINT g_otf_port = 8888;
7171
7272 // the shell
7373 Chuck_Shell * g_shell = NULL;
@@ -254,6 +254,27 @@ extern "C" void signal_int( int sig_num ) · 180 unmodified lines
254254
255255
256256
257+
258+
259+
260+
261+//-----------------------------------------------------------------------------
262+// name: signal_pipe()
263+// desc: ...
264+//-----------------------------------------------------------------------------
265+extern "C" void signal_pipe( int sig_num )
266+{
267+ fprintf( stderr, "[chuck]: sigpipe handled - broken pipe (no connection)...\n" );
268+ if( g_sigpipe_mode )
269+ {
270+ all_detach();
271+ // exit( 2 );
272+ }
273+}
274+
275+
276+
277+
257278 //-----------------------------------------------------------------------------
258279 // name: global_cleanup()
259280 // desc: ...
@@ -364,6 +385,8 @@ bool go( int argc, const char ** argv ) · 104 unmodified lines
364385 t_CKBOOL update_otf_vm = TRUE;
365386 string filename = "";
366387 vector<string> args;
388+ Chuck_VM_Code * code = NULL;
389+ Chuck_VM_Shred * shred = NULL;
367390
368391 // list of search pathes (added 1.3.0.0)
369392 std::list<std::string> dl_search_path;
@@ -791,132 +814,52 @@ bool go( int argc, const char ** argv ) · 421 unmodified lines
791814 the_chuck->setParam( CHUCK_PARAM_VM_ADAPTIVE, adaptive_size );
792815 the_chuck->setParam( CHUCK_PARAM_VM_HALT, (t_CKINT)(vm_halt) );
793816 the_chuck->setParam( CHUCK_PARAM_OTF_PORT, g_otf_port );
794− the_chuck->setParam( CHUCK_PARAM_LOG_LEVEL, g_loglevel );
795− the_chuck->setParam( CHUCK_PARAM_, );
796− the_chuck->setParam( CHUCK_PARAM_, );
797− the_chuck->setParam( CHUCK_PARAM_, );
798− the_chuck->setParam( CHUCK_PARAM_, );
817+ the_chuck->setParam( CHUCK_PARAM_DUMP_INSTRUCTIONS, (t_CKINT)dump );
818+ the_chuck->setParam( CHUCK_PARAM_AUTO_DEPEND, (t_CKINT)auto_depend );
819+ the_chuck->setParam( CHUCK_PARAM_DEPRECATE_LEVEL, deprecate_level );
820+ the_chuck->setLogLevel( log_level );
799821
800822 // initialize
801−
802−
803−
804− //------------------------- VIRTUAL MACHINE SETUP -----------------------------
805−
806− // allocate the vm - needs the type system
807− vm = m_carrier.vm = m_vmRef = new Chuck_VM;
808− m_carrier.vm->setCarrier( &m_carrier );
809−
810− // ge: refactor 2015: initialize VM
811− if( !vm->initialize( srate, dac_chans, adc_chans, adaptive_size, vm_halt ) )
812− {
813− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
814− exit( 1 );
815− }
816−
817− if( update_otf_vm )
818− {
819− set_otf_vm( vm );
820− }
821−
823+ the_chuck->init();
822824
823825 //--------------------------- AUDIO I/O SETUP ---------------------------------
826+ // log
827+ EM_log( CK_LOG_SYSTEM, "initializing audio I/O..." );
828+ // push
829+ EM_pushlog();
830+ // log
831+ EM_log( CK_LOG_SYSTEM, "probing '%s' audio subsystem...", g_enable_realtime_audio ? "real-time" : "fake-time" );
832+
824833 // initialize audio system
825− t_CKBOOL retval = ChuckAudio::initialize( numInChannels, numOutChannels,
826− srate, bufferSize, numBuffers, cb, NULL, FALSE );
834+ t_CKBOOL retval = ChuckAudio::initialize( adc_chans, dac_chans,
835+ srate, buffer_size, num_buffers, cb, (void *)the_chuck, force_srate );
827836 // check
828837 if( !retval )
829838 {
830− // BADDDD
831− }
832−
833− // ge: 1.3.5.3
834− if( g_bbq == NULL ) {
835− bbq = g_bbq = new BBQ;
836− // set some parameters
837− bbq->set_srate( srate );
838− bbq->set_bufsize( buffer_size );
839− bbq->set_numbufs( num_buffers );
840− bbq->set_inouts( adc, dac );
841− bbq->set_chans( adc_chans, dac_chans );
842−
843− // log
844− EM_log( CK_LOG_SYSTEM, "initializing audio I/O..." );
845− // push
846− EM_pushlog();
847− // log
848− EM_log( CK_LOG_SYSTEM, "probing '%s' audio subsystem...", g_enable_realtime_audio ? "real-time" : "fake-time" );
849−
850− // probe / init (this shouldn't start audio yet...
851− // moved here 1.3.1.2; to main ge: 1.3.5.3)
852− if( !bbq->initialize( dac_chans, adc_chans, srate, 16, buffer_size, num_buffers,
853− dac, adc, block, vm, g_enable_realtime_audio, NULL, NULL, force_srate ) )
854− {
855− EM_log( CK_LOG_SYSTEM,
856− "cannot initialize audio device (use --silent/-s for non-realtime)" );
857− // pop
858− EM_poplog();
859− // done
860− exit( 1 );
861− }
862−
863− // log
864− EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" );
865− EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" );
866− EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate );
867− EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size );
868− if( g_enable_realtime_audio )
869− {
870− EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers );
871− EM_log( CK_LOG_SYSTEM, "adc: %ld dac: %d", adc, dac );
872− EM_log( CK_LOG_SYSTEM, "adaptive block processing: %ld", adaptive_size > 1 ? adaptive_size : 0 );
873− }
874− EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans );
875−
839+ EM_log( CK_LOG_SYSTEM,
840+ "cannot initialize audio device (use --silent/-s for non-realtime)" );
876841 // pop
877842 EM_poplog();
878− } else {
879− bbq = g_bbq;
880− }
881−
882− //------------------------- CHUCK COMPILER SETUP -----------------------------
883−
884− // if chugin load is off, then clear the lists (added 1.3.0.0 -- TODO: refactor)
885− if( chugin_load == 0 )
886− {
887− // turn off chugin load
888− dl_search_path.clear();
889− named_dls.clear();
890− }
891−
892− // allocate the compiler
893− compiler = m_carrier.compiler = m_compilerRef = new Chuck_Compiler;
894− m_carrier.compiler->setCarrier( &m_carrier );
895−
896− // initialize the compiler (search_apth and named_dls added 1.3.0.0 -- TODO: refactor)
897− if( !compiler->initialize( dl_search_path, named_dls ) )
898− {
899− CK_FPRINTF_STDERR( "[chuck]: error initializing compiler...\n" );
843+ // done
900844 exit( 1 );
901845 }
902− // enable dump
903− compiler->emitter->dump = dump;
904− // set auto depend
905− compiler->set_auto_depend( auto_depend );
906846
907− if( update_otf_vm )
908− {
909− // also update otf compiler
910− set_otf_compiler( compiler );
911− }
912−
913− // vm synthesis subsystem - needs the type system
914− if( !vm->initialize_synthesis( ) )
847+ // log
848+ EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" );
849+ EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" );
850+ EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate );
851+ EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size );
852+ if( g_enable_realtime_audio )
915853 {
916− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
917− exit( 1 );
854+ EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers );
855+ EM_log( CK_LOG_SYSTEM, "adc: %ld dac: %d", adc, dac );
856+ EM_log( CK_LOG_SYSTEM, "adaptive block processing: %ld", adaptive_size > 1 ? adaptive_size : 0 );
918857 }
858+ EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans );
919859
860+ // pop
861+ EM_poplog();
862+
920863 #ifndef __ALTER_HID__
921864 // pre-load hid
922865 if( load_hid ) HidInManager::init();
@@ -935,82 +878,13 @@ bool go( int argc, const char ** argv ) · 12 unmodified lines
935878 // instantiate
936879 g_shell = new Chuck_Shell;
937880 // initialize
938− if( !init_shell( g_shell, new Chuck_Console, vm ) )
881+ if( !init_shell( g_shell, new Chuck_Console(), the_chuck->vm() ) )
939882 exit( 1 );
940883 }
941−
942− // set deprecate
943− compiler->env()->deprecate_level = deprecate_level;
944−
884+
945885 // reset count
946886 count = 1;
947887
948− // figure out current working directory (added 1.3.0.0)
949− std::string cwd;
950− {
951− char cstr_cwd[MAXPATHLEN];
952− if( getcwd(cstr_cwd, MAXPATHLEN) == NULL )
953− {
954− // uh...
955− EM_log( CK_LOG_SEVERE, "error: unable to determine current working directory!" );
956− }
957− else
958− {
959− cwd = std::string(cstr_cwd);
960− cwd = normalize_directory_separator(cwd) + "/";
961− }
962− }
963−
964− // whether or not chug should be enabled (added 1.3.0.0)
965− if( chugin_load )
966− {
967− // log
968− EM_log( CK_LOG_SEVERE, "pre-loading ChucK libs..." );
969− EM_pushlog();
970−
971− // iterate over list of ck files that the compiler found
972− for( std::list<std::string>::iterator j = compiler->m_cklibs_to_preload.begin();
973− j != compiler->m_cklibs_to_preload.end(); j++)
974− {
975− // the filename
976− std::string filename = *j;
977−
978− // log
979− EM_log( CK_LOG_SEVERE, "preloading '%s'...", filename.c_str() );
980− // push indent
981− EM_pushlog();
982−
983− // SPENCERTODO: what to do for full path
984− std::string full_path = filename;
985−
986− // parse, type-check, and emit
987− if( compiler->go( filename, NULL, NULL, full_path ) )
988− {
989− // TODO: how to compilation handle?
990− //return 1;
991−
992− // get the code
993− code = compiler->output();
994− // name it - TODO?
995− // code->name += string(argv[i]);
996−
997− // spork it
998− shred = vm->spork( code, NULL, TRUE );
999− }
1000−
1001− // pop indent
1002− EM_poplog();
1003− }
1004−
1005− // clear the list of chuck files to preload
1006− compiler->m_cklibs_to_preload.clear();
1007−
1008− // pop log
1009− EM_poplog();
1010− }
1011−
1012− compiler->env()->load_user_namespace();
1013−
1014888 // log
1015889 EM_log( CK_LOG_SEVERE, "starting compilation..." );
1016890 // push indent
@@ -1026,9 +900,9 @@ bool go( int argc, const char ** argv ) · 9 unmodified lines
1026900 if( argv[i][0] == '-' || argv[i][0] == '+' )
1027901 {
1028902 if( !strcmp(argv[i], "--dump") || !strcmp(argv[i], "+d" ) )
1029− compiler->emitter->dump = TRUE;
903+ the_chuck->compiler()->emitter->dump = TRUE;
1030904 else if( !strcmp(argv[i], "--nodump") || !strcmp(argv[i], "-d" ) )
1031− compiler->emitter->dump = FALSE;
905+ the_chuck->compiler()->emitter->dump = FALSE;
1032906 else
1033907 get_count( argv[i], &count );
1034908
@@ -1036,7 +910,7 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1036910 }
1037911
1038912 // compile it!
1039− compileFile( argv[i], "", count );
913+ the_chuck->compileFile( argv[i], "", count );
1040914
1041915 // reset count
1042916 count = 1;
@@ -1045,56 +919,22 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1045919 // pop indent
1046920 EM_poplog();
1047921
1048− // reset the parser
1049− reset_parse();
1050−
1051922 // boost priority
1052− if( Chuck_VM::our_priority != 0x7fffffff )
923+ if( XThreadUtil::our_priority != 0x7fffffff )
1053924 {
1054925 // try
1055− if( !Chuck_VM::set_priority( Chuck_VM::our_priority, vm ) )
926+ if( !XThreadUtil::set_priority( XThreadUtil::our_priority ) )
1056927 {
1057928 // error
1058− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
929+ CK_FPRINTF_STDERR( "[chuck]: error setting thread priority...\n" );
1059930 exit( 1 );
1060931 }
1061932 }
1062933
1063934
1064− //----------------------- ON-THE-FLY SERVER SETUP -----------------------------
1065−
1066− // server
1067− if( enable_server )
1068− {
1069−#ifndef __DISABLE_OTF_SERVER__
1070− // log
1071− EM_log( CK_LOG_SYSTEM, "starting listener on port: %d...", g_port );
1072−
1073− // start tcp server
1074− g_sock = ck_tcp_create( 1 );
1075− if( !g_sock || !ck_bind( g_sock, g_port ) || !ck_listen( g_sock, 10 ) )
1076− {
1077− CK_FPRINTF_STDERR( "[chuck]: cannot bind to tcp port %li...\n", g_port );
1078− ck_close( g_sock );
1079− g_sock = NULL;
1080− }
1081− else
1082− {
1083−#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
1084− pthread_create( &g_tid_otf, NULL, otf_cb, NULL );
1085−#else
1086− g_tid_otf = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)otf_cb, NULL, 0, 0 );
1087−#endif
1088− }
1089−#endif // __DISABLE_OTF_SERVER__
1090− }
1091− else
1092− {
1093− // log
1094− EM_log( CK_LOG_SYSTEM, "OTF server/listener: OFF" );
1095− }
935+ //----------------------- SHELL SETUP -----------------------------
1096936
1097− // start shell on separate thread
937+ // start shell on separate thread | REFACTOR-2017: per-VM?!?
1098938 if( g_enable_shell )
1099939 {
1100940 #if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
@@ -1104,7 +944,6 @@ bool go( int argc, const char ** argv ) · 3 unmodified lines
1104944 #endif
1105945 }
1106946
1107−
1108947 //-------------------------- MAIN CHUCK LOOP!!! -----------------------------
1109948
1110949 // log
@@ -1112,65 +951,14 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1112951 // push indent
1113952 EM_pushlog();
1114953
1115− // set run state
1116− vm->start();
1117−
1118− EM_log( CK_LOG_SEVERE, "initializing audio buffers..." );
1119− if( !bbq->digi_out()->initialize( ) )
1120− {
1121− EM_log( CK_LOG_SYSTEM,
1122− "cannot open audio output (use --silent/-s)" );
1123− exit(1);
1124− }
1125−
1126− // initialize input
1127− bbq->digi_in()->initialize( );
954+ // start it!
955+ the_chuck->start();
1128956
1129957 // log
1130958 EM_log( CK_LOG_SEVERE, "virtual machine running..." );
1131959 // pop indent
1132960 EM_poplog();
1133961
1134− // NOTE: non-blocking callback only, ge: 1.3.5.3
1135−
1136− // compute shreds before first sample
1137− if( !vm->compute() )
1138− {
1139− // done, 1.3.5.3
1140− vm->stop();
1141− // log
1142− EM_log( CK_LOG_SYSTEM, "virtual machine stopped..." );
1143− }
1144−
1145− // check client mode
1146− if( clientMode )
1147− {
1148− // done!
1149− return TRUE;
1150− }
1151−
1152− // start audio
1153− if( !audio_started )
1154− {
1155− // audio
1156− if( !audio_started && g_enable_realtime_audio )
1157− {
1158− EM_log( CK_LOG_SEVERE, "starting real-time audio..." );
1159− bbq->digi_out()->start();
1160− bbq->digi_in()->start();
1161− }
1162−
1163− // set the flag to true to avoid entering this function
1164− audio_started = TRUE;
1165− }
1166−
1167−
1168− // Don't run audio callback and shut down if we only wanted to init here
1169− if( m_initOnly ) {
1170− return TRUE;
1171− }
1172−
1173−
1174962 // silent mode buffers
1175963 SAMPLE * input = new SAMPLE[buffer_size*adc_chans];
1176964 SAMPLE * output = new SAMPLE[buffer_size*dac_chans];
@@ -1179,25 +967,20 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1179967 memset( output, 0, sizeof(SAMPLE)*buffer_size*dac_chans );
1180968
1181969 // wait
1182− while( vm->running() )
970+ while( the_chuck->vm()->running() )
1183971 {
1184972 // real-time audio
1185973 if( g_enable_realtime_audio )
1186974 {
1187− if( g_main_thread_hook && g_main_thread_quit )
1188− g_main_thread_hook( g_main_thread_bindle );
1189− else
1190− usleep( 1000 );
975+ usleep( 10000 );
1191976 }
1192977 else // silent mode
1193978 {
1194979 // keep running as fast as possible
1195− this->run( input, output, buffer_size );
980+ the_chuck->run( input, output, buffer_size );
1196981 }
1197982 }
1198983
1199− // shutdown
1200− clientShutdown();
1201−
1202984 return TRUE;
1203985 }
986+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t