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
38#include "chuck_errmsg.h"38#include "chuck_errmsg.h"
39#include "chuck_otf.h"39#include "chuck_otf.h"
40#include "ulib_machine.h"40#include "ulib_machine.h"
41#include "util_network.h"
41#include "util_string.h"42#include "util_string.h"
42 43
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
43 54
44 55
45 56
@@ -49,10 +60,12 @@ · 3 unmodified lines
49#define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"60#define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"
50#define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"61#define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"
51#define CHUCK_PARAM_VM_HALT_DEFAULT "0"62#define CHUCK_PARAM_VM_HALT_DEFAULT "0"
63#define CHUCK_PARAM_OTF_ENABLE_DEFAULT "0"
52#define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"64#define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"
53#define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"65#define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"
54#define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"66#define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"
55#define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""67#define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""
68#define CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT "1"
56#define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""69#define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""
57 70
58 71
@@ -155,22 +168,26 @@ void ChucK::initDefaultParams() · 96 unmodified lines
155 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;168 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;
156 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;169 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;
157 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;170 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;
171 m_params[CHUCK_PARAM_OTF_ENABLE] = CHUCK_PARAM_OTF_ENABLE_DEFAULT;
158 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;172 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;
159 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;173 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;
160 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;174 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;
161 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;175 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;
162 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;176 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;
177 m_params[CHUCK_PARAM_CHUGIN_ENABLE] = CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT;
163 178
164 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;179 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;
165 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;180 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;
166 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;181 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;
167 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;182 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;
168 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;183 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;
184 ck_param_types[CHUCK_PARAM_OTF_ENABLE] = ck_param_int;
169 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;185 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;
170 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;186 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;
171 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;187 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;
172 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;188 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;
173 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;189 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;
190 ck_param_types[CHUCK_PARAM_CHUGIN_ENABLE] = ck_param_int;
174}191}
175 192
176 193
@@ -300,6 +317,11 @@ std::string ChucK::getParamString( const std::string & key ) · 123 unmodified lines
300//-----------------------------------------------------------------------------317//-----------------------------------------------------------------------------
301bool ChucK::init()318bool ChucK::init()
302{319{
320 Chuck_VM_Code * code = NULL;
321 Chuck_VM_Shred * shred = NULL;
322 std::string cwd;
323 char cstr_cwd[MAXPATHLEN];
324
303 // sanity check325 // sanity check
304 if( m_carrier->vm != NULL )326 if( m_carrier->vm != NULL )
305 {327 {
@@ -320,7 +342,7 @@ bool ChucK::init() · 14 unmodified lines
320 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );342 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );
321 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );343 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );
322 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );344 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );
323 // TODO: chugin load option345
324 // list of search pathes (added 1.3.0.0)346 // list of search pathes (added 1.3.0.0)
325 std::list<std::string> dl_search_path;347 std::list<std::string> dl_search_path;
326 if( workingDir != std::string("") )348 if( workingDir != std::string("") )
@@ -333,8 +355,7 @@ bool ChucK::init() · 6 unmodified lines
333 }355 }
334 // list of individually named chug-ins (added 1.3.0.0)356 // list of individually named chug-ins (added 1.3.0.0)
335 std::list<std::string> named_dls;357 std::list<std::string> named_dls;
336 358
337
338 // instantiate VM359 // instantiate VM
339 m_carrier->vm = new Chuck_VM();360 m_carrier->vm = new Chuck_VM();
340 // reference back to carrier361 // reference back to carrier
@@ -345,6 +366,14 @@ bool ChucK::init() · 4 unmodified lines
345 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );366 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );
346 goto cleanup;367 goto cleanup;
347 }368 }
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 }
348 377
349 // instantiate compiler378 // instantiate compiler
350 m_carrier->compiler = new Chuck_Compiler();379 m_carrier->compiler = new Chuck_Compiler();
@@ -371,11 +400,105 @@ bool ChucK::init() · 20 unmodified lines
371 goto cleanup;400 goto cleanup;
372 }401 }
373 402
374 // TODO: load chugins403 // 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 }
375 464
376 // load user namespace465 // load user namespace
377 m_carrier->env->load_user_namespace();466 m_carrier->env->load_user_namespace();
378 467
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
379 // did user init?502 // did user init?
380 m_init = TRUE;503 m_init = TRUE;
381 504
@@ -495,6 +618,9 @@ bool ChucK::compileFile( const std::string & path, const std::string & argsToget · 113 unmodified lines
495 // pop indent618 // pop indent
496 EM_poplog();619 EM_poplog();
497 620
621 // reset the parser
622 reset_parse();
623
498 return true;624 return true;
499}625}
500 626
@@ -567,7 +693,10 @@ bool ChucK::compileCode( const std::string & code, const std::string & argsToget · 66 unmodified lines
567 693
568 // pop indent694 // pop indent
569 EM_poplog();695 EM_poplog();
570 696
697 // reset the parser
698 reset_parse();
699
571 return true;700 return true;
572}701}
573 702
@@ -758,6 +887,28 @@ void ChucK::finalCleanup() · 184 unmodified lines
758 887
759 888
760 889
890//-----------------------------------------------------------------------------
891// set log level -- this should eventually be per-VM?
892//-----------------------------------------------------------------------------
893void ChucK::setLogLevel( t_CKINT level )
894{
895 EM_setlog( level );
896}
897
898
899
900
901//-----------------------------------------------------------------------------
902// get log level -- also per-VM?
903//-----------------------------------------------------------------------------
904t_CKINT ChucK::getLogLevel()
905{
906 return g_loglevel;
907}
908
909
910
911
761//-----------------------------------------------------------------------------912//-----------------------------------------------------------------------------
762// name: poop()913// name: poop()
763// desc: --poop914// desc: --poop
src/core/chuck.h+7−1
@@ -45,6 +45,7 @@ · 44 unmodified lines
45#include "ulib_machine.h"45#include "ulib_machine.h"
46#include "util_math.h"46#include "util_math.h"
47#include "util_string.h"47#include "util_string.h"
48#include "hidio_sdl.h"
48#include "midiio_rtmidi.h"49#include "midiio_rtmidi.h"
49#include <string>50#include <string>
50#include <map>51#include <map>
@@ -58,12 +59,13 @@ · 7 unmodified lines
58#define CHUCK_PARAM_OUTPUT_CHANNELS "OUTPUT_CHANNELS"59#define CHUCK_PARAM_OUTPUT_CHANNELS "OUTPUT_CHANNELS"
59#define CHUCK_PARAM_VM_ADAPTIVE "VM_ADAPTIVE"60#define CHUCK_PARAM_VM_ADAPTIVE "VM_ADAPTIVE"
60#define CHUCK_PARAM_VM_HALT "VM_HALT"61#define CHUCK_PARAM_VM_HALT "VM_HALT"
62#define CHUCK_PARAM_OTF_ENABLE "OTF_ENABLE"
61#define CHUCK_PARAM_OTF_PORT "OTF_PORT"63#define CHUCK_PARAM_OTF_PORT "OTF_PORT"
62#define CHUCK_PARAM_LOG_LEVEL "LOG_LEVEL"
63#define CHUCK_PARAM_DUMP_INSTRUCTIONS "DUMP_INSTRUCTIONS"64#define CHUCK_PARAM_DUMP_INSTRUCTIONS "DUMP_INSTRUCTIONS"
64#define CHUCK_PARAM_AUTO_DEPEND "AUTO_DEPEND"65#define CHUCK_PARAM_AUTO_DEPEND "AUTO_DEPEND"
65#define CHUCK_PARAM_DEPRECATE_LEVEL "DEPRECATE_LEVEL"66#define CHUCK_PARAM_DEPRECATE_LEVEL "DEPRECATE_LEVEL"
66#define CHUCK_PARAM_WORKING_DIRECTORY "WORKING_DIRECTORY"67#define CHUCK_PARAM_WORKING_DIRECTORY "WORKING_DIRECTORY"
68#define CHUCK_PARAM_CHUGIN_ENABLE "CHUGIN_ENABLE"
67#define CHUCK_PARAM_CHUGIN_DIRECTORY "CHUGIN_DIRECTORY"69#define CHUCK_PARAM_CHUGIN_DIRECTORY "CHUGIN_DIRECTORY"
68 70
69 71
@@ -151,6 +153,10 @@ public: // static functions · 81 unmodified lines
151 static t_CKUINT numVMs() { return o_numVMs; };153 static t_CKUINT numVMs() { return o_numVMs; };
152 // --poop compatibilty154 // --poop compatibilty
153 static void poop();155 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();
154 160
155protected:161protected:
156 // chuck version162 // chuck version
src/core/chuck_errmsg.cpp+5−5
@@ -55,8 +55,8 @@ static const size_t LASTERROR_SIZE = 1024; · 54 unmodified lines
55static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)";55static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)";
56static size_t g_lasterrorIndex = strlen(g_lasterror);56static size_t g_lasterrorIndex = strlen(g_lasterror);
57// log globals57// log globals
58int g_loglevel = CK_LOG_CORE;58t_CKINT g_loglevel = CK_LOG_CORE;
59int g_logstack = 0;59t_CKINT g_logstack = 0;
60XMutex g_logmutex;60XMutex g_logmutex;
61 61
62// more local globals62// more local globals
@@ -553,7 +553,7 @@ void EM_error3( const char * message, ... ) · 490 unmodified lines
553 553
554 554
555// log555// log
556void EM_log( int level, const char * message, ... )556void EM_log( t_CKINT level, const char * message, ... )
557{557{
558 va_list ap;558 va_list ap;
559 559
@@ -582,14 +582,14 @@ void EM_log( int level, const char * message, ... ) · 22 unmodified lines
582 582
583 583
584// set log level584// set log level
585void EM_setlog( int level )585void EM_setlog( t_CKINT level )
586{586{
587 if( level > CK_LOG_CRAZY ) level = CK_LOG_CRAZY;587 if( level > CK_LOG_CRAZY ) level = CK_LOG_CRAZY;
588 else if( level < CK_LOG_NONE ) level = CK_LOG_NONE;588 else if( level < CK_LOG_NONE ) level = CK_LOG_NONE;
589 g_loglevel = level;589 g_loglevel = level;
590 590
591 // log this591 // 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] );
593}593}
594 594
595// push log595// push log
src/core/chuck_errmsg.h+3−3
@@ -146,13 +146,13 @@ extern ChuckOutStream g_ck_stderrstream; · 145 unmodified lines
146 146
147 147
148 148
149void EM_log( int, c_constr, ... );149void EM_log( t_CKINT, c_constr, ... );
150void EM_setlog( int );150void EM_setlog( t_CKINT );
151void EM_pushlog();151void EM_pushlog();
152void EM_poplog();152void EM_poplog();
153 153
154// actual level154// actual level
155extern int g_loglevel;155extern t_CKINT g_loglevel;
156// macro to compare156// macro to compare
157#define DO_LOG(x) ( x <= g_loglevel )157#define DO_LOG(x) ( x <= g_loglevel )
158 158
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
53 53
54// C functions54// C functions
55extern "C" void signal_int( int sig_num );55extern "C" void signal_int( int sig_num );
56 56extern "C" void signal_pipe( int sig_num );
57 57
58 58
59 59
@@ -67,7 +67,7 @@ CHUCK_THREAD g_tid_shell = 0; · 7 unmodified lines
67// default destination host name67// default destination host name
68char g_otf_dest[256] = "127.0.0.1";68char g_otf_dest[256] = "127.0.0.1";
69// otf listener port69// otf listener port
70t_CKUINT g_otf_port = 8888;70t_CKINT g_otf_port = 8888;
71 71
72// the shell72// the shell
73Chuck_Shell * g_shell = NULL;73Chuck_Shell * g_shell = NULL;
@@ -254,6 +254,27 @@ extern "C" void signal_int( int sig_num ) · 180 unmodified lines
254 254
255 255
256 256
257
258
259
260
261//-----------------------------------------------------------------------------
262// name: signal_pipe()
263// desc: ...
264//-----------------------------------------------------------------------------
265extern "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
257//-----------------------------------------------------------------------------278//-----------------------------------------------------------------------------
258// name: global_cleanup()279// name: global_cleanup()
259// desc: ...280// desc: ...
@@ -364,6 +385,8 @@ bool go( int argc, const char ** argv ) · 104 unmodified lines
364 t_CKBOOL update_otf_vm = TRUE;385 t_CKBOOL update_otf_vm = TRUE;
365 string filename = "";386 string filename = "";
366 vector<string> args;387 vector<string> args;
388 Chuck_VM_Code * code = NULL;
389 Chuck_VM_Shred * shred = NULL;
367 390
368 // list of search pathes (added 1.3.0.0)391 // list of search pathes (added 1.3.0.0)
369 std::list<std::string> dl_search_path;392 std::list<std::string> dl_search_path;
@@ -791,132 +814,52 @@ bool go( int argc, const char ** argv ) · 421 unmodified lines
791 the_chuck->setParam( CHUCK_PARAM_VM_ADAPTIVE, adaptive_size );814 the_chuck->setParam( CHUCK_PARAM_VM_ADAPTIVE, adaptive_size );
792 the_chuck->setParam( CHUCK_PARAM_VM_HALT, (t_CKINT)(vm_halt) );815 the_chuck->setParam( CHUCK_PARAM_VM_HALT, (t_CKINT)(vm_halt) );
793 the_chuck->setParam( CHUCK_PARAM_OTF_PORT, g_otf_port );816 the_chuck->setParam( CHUCK_PARAM_OTF_PORT, g_otf_port );
794 the_chuck->setParam( CHUCK_PARAM_LOG_LEVEL, g_loglevel );817 the_chuck->setParam( CHUCK_PARAM_DUMP_INSTRUCTIONS, (t_CKINT)dump );
795 the_chuck->setParam( CHUCK_PARAM_, );818 the_chuck->setParam( CHUCK_PARAM_AUTO_DEPEND, (t_CKINT)auto_depend );
796 the_chuck->setParam( CHUCK_PARAM_, );819 the_chuck->setParam( CHUCK_PARAM_DEPRECATE_LEVEL, deprecate_level );
797 the_chuck->setParam( CHUCK_PARAM_, );820 the_chuck->setLogLevel( log_level );
798 the_chuck->setParam( CHUCK_PARAM_, );
799 821
800 // initialize822 // initialize
801 823 the_chuck->init();
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
822 824
823 //--------------------------- AUDIO I/O SETUP ---------------------------------825 //--------------------------- 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
824 // initialize audio system833 // initialize audio system
825 t_CKBOOL retval = ChuckAudio::initialize( numInChannels, numOutChannels,834 t_CKBOOL retval = ChuckAudio::initialize( adc_chans, dac_chans,
826 srate, bufferSize, numBuffers, cb, NULL, FALSE );835 srate, buffer_size, num_buffers, cb, (void *)the_chuck, force_srate );
827 // check836 // check
828 if( !retval )837 if( !retval )
829 {838 {
830 // BADDDD839 EM_log( CK_LOG_SYSTEM,
831 }840 "cannot initialize audio device (use --silent/-s for non-realtime)" );
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
876 // pop841 // pop
877 EM_poplog();842 EM_poplog();
878 } else {843 // done
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" );
900 exit( 1 );844 exit( 1 );
901 }845 }
902 // enable dump
903 compiler->emitter->dump = dump;
904 // set auto depend
905 compiler->set_auto_depend( auto_depend );
906 846
907 if( update_otf_vm )847 // log
908 {848 EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" );
909 // also update otf compiler849 EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" );
910 set_otf_compiler( compiler );850 EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate );
911 }851 EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size );
912 852 if( g_enable_realtime_audio )
913 // vm synthesis subsystem - needs the type system
914 if( !vm->initialize_synthesis( ) )
915 {853 {
916 CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );854 EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers );
917 exit( 1 );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 );
918 }857 }
858 EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans );
919 859
860 // pop
861 EM_poplog();
862
920#ifndef __ALTER_HID__863#ifndef __ALTER_HID__
921 // pre-load hid864 // pre-load hid
922 if( load_hid ) HidInManager::init();865 if( load_hid ) HidInManager::init();
@@ -935,82 +878,13 @@ bool go( int argc, const char ** argv ) · 12 unmodified lines
935 // instantiate878 // instantiate
936 g_shell = new Chuck_Shell;879 g_shell = new Chuck_Shell;
937 // initialize880 // initialize
938 if( !init_shell( g_shell, new Chuck_Console, vm ) )881 if( !init_shell( g_shell, new Chuck_Console(), the_chuck->vm() ) )
939 exit( 1 );882 exit( 1 );
940 }883 }
941 884
942 // set deprecate
943 compiler->env()->deprecate_level = deprecate_level;
944
945 // reset count885 // reset count
946 count = 1;886 count = 1;
947 887
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
1014 // log888 // log
1015 EM_log( CK_LOG_SEVERE, "starting compilation..." );889 EM_log( CK_LOG_SEVERE, "starting compilation..." );
1016 // push indent890 // push indent
@@ -1026,9 +900,9 @@ bool go( int argc, const char ** argv ) · 9 unmodified lines
1026 if( argv[i][0] == '-' || argv[i][0] == '+' )900 if( argv[i][0] == '-' || argv[i][0] == '+' )
1027 {901 {
1028 if( !strcmp(argv[i], "--dump") || !strcmp(argv[i], "+d" ) )902 if( !strcmp(argv[i], "--dump") || !strcmp(argv[i], "+d" ) )
1029 compiler->emitter->dump = TRUE;903 the_chuck->compiler()->emitter->dump = TRUE;
1030 else if( !strcmp(argv[i], "--nodump") || !strcmp(argv[i], "-d" ) )904 else if( !strcmp(argv[i], "--nodump") || !strcmp(argv[i], "-d" ) )
1031 compiler->emitter->dump = FALSE;905 the_chuck->compiler()->emitter->dump = FALSE;
1032 else906 else
1033 get_count( argv[i], &count );907 get_count( argv[i], &count );
1034 908
@@ -1036,7 +910,7 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1036 }910 }
1037 911
1038 // compile it!912 // compile it!
1039 compileFile( argv[i], "", count );913 the_chuck->compileFile( argv[i], "", count );
1040 914
1041 // reset count915 // reset count
1042 count = 1;916 count = 1;
@@ -1045,56 +919,22 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1045 // pop indent919 // pop indent
1046 EM_poplog();920 EM_poplog();
1047 921
1048 // reset the parser
1049 reset_parse();
1050
1051 // boost priority922 // boost priority
1052 if( Chuck_VM::our_priority != 0x7fffffff )923 if( XThreadUtil::our_priority != 0x7fffffff )
1053 {924 {
1054 // try925 // try
1055 if( !Chuck_VM::set_priority( Chuck_VM::our_priority, vm ) )926 if( !XThreadUtil::set_priority( XThreadUtil::our_priority ) )
1056 {927 {
1057 // error928 // error
1058 CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );929 CK_FPRINTF_STDERR( "[chuck]: error setting thread priority...\n" );
1059 exit( 1 );930 exit( 1 );
1060 }931 }
1061 }932 }
1062 933
1063 934
1064 //----------------------- ON-THE-FLY SERVER SETUP -----------------------------935 //----------------------- SHELL 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 }
1096 936
1097 // start shell on separate thread937 // start shell on separate thread | REFACTOR-2017: per-VM?!?
1098 if( g_enable_shell )938 if( g_enable_shell )
1099 {939 {
1100#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)940#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
@@ -1104,7 +944,6 @@ bool go( int argc, const char ** argv ) · 3 unmodified lines
1104#endif944#endif
1105 }945 }
1106 946
1107
1108 //-------------------------- MAIN CHUCK LOOP!!! -----------------------------947 //-------------------------- MAIN CHUCK LOOP!!! -----------------------------
1109 948
1110 // log949 // log
@@ -1112,65 +951,14 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1112 // push indent951 // push indent
1113 EM_pushlog();952 EM_pushlog();
1114 953
1115 // set run state954 // start it!
1116 vm->start();955 the_chuck->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( );
1128 956
1129 // log957 // log
1130 EM_log( CK_LOG_SEVERE, "virtual machine running..." );958 EM_log( CK_LOG_SEVERE, "virtual machine running..." );
1131 // pop indent959 // pop indent
1132 EM_poplog();960 EM_poplog();
1133 961
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
1174 // silent mode buffers962 // silent mode buffers
1175 SAMPLE * input = new SAMPLE[buffer_size*adc_chans];963 SAMPLE * input = new SAMPLE[buffer_size*adc_chans];
1176 SAMPLE * output = new SAMPLE[buffer_size*dac_chans];964 SAMPLE * output = new SAMPLE[buffer_size*dac_chans];
@@ -1179,25 +967,20 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1179 memset( output, 0, sizeof(SAMPLE)*buffer_size*dac_chans );967 memset( output, 0, sizeof(SAMPLE)*buffer_size*dac_chans );
1180 968
1181 // wait969 // wait
1182 while( vm->running() )970 while( the_chuck->vm()->running() )
1183 {971 {
1184 // real-time audio972 // real-time audio
1185 if( g_enable_realtime_audio )973 if( g_enable_realtime_audio )
1186 {974 {
1187 if( g_main_thread_hook && g_main_thread_quit )975 usleep( 10000 );
1188 g_main_thread_hook( g_main_thread_bindle );
1189 else
1190 usleep( 1000 );
1191 }976 }
1192 else // silent mode977 else // silent mode
1193 {978 {
1194 // keep running as fast as possible979 // keep running as fast as possible
1195 this->run( input, output, buffer_size );980 the_chuck->run( input, output, buffer_size );
1196 }981 }
1197 }982 }
1198 983
1199 // shutdown
1200 clientShutdown();
1201
1202 return TRUE;984 return TRUE;
1203}985}
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