From f428df2deeb54c4a646a2e242b48c1f84999499e Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sun, 30 Oct 2016 12:46:07 +0100 Subject: [PATCH] port of ChucK A Strongly-timed, Concurrent, and On-the-fly Music Programming Language http://chuck.cs.princeton.edu/ Fix #47 --- ports/chuck.hash | 1 + ports/chuck.port | 35 +++ src/app/chuck/README | 23 ++ src/app/chuck/component.cc | 401 +++++++++++++++++++++++++++++ src/app/chuck/dummies.cc | 35 +++ src/app/chuck/patch | 501 +++++++++++++++++++++++++++++++++++++ src/app/chuck/target.mk | 41 +++ 7 files changed, 1037 insertions(+) create mode 100644 ports/chuck.hash create mode 100644 ports/chuck.port create mode 100644 src/app/chuck/README create mode 100644 src/app/chuck/component.cc create mode 100644 src/app/chuck/dummies.cc create mode 100644 src/app/chuck/patch create mode 100644 src/app/chuck/target.mk diff --git a/ports/chuck.hash b/ports/chuck.hash new file mode 100644 index 0000000..c66b6ed --- /dev/null +++ b/ports/chuck.hash @@ -0,0 +1 @@ +416a1ffb4a3df426721b3b9397f79b77b966dee4 diff --git a/ports/chuck.port b/ports/chuck.port new file mode 100644 index 0000000..e071b14 --- /dev/null +++ b/ports/chuck.port @@ -0,0 +1,35 @@ +LICENSE := GPL2 +VERSION := 1.3.5.2 +DOWNLOADS := chuck.archive + +# +# Check for tools +# +$(call check_tool,lex) +$(call check_tool,bison) + +OWNER := ccrma +REPO := chuck +REV := 53f99be5498c6b1deb59aa2c223e75326820a30b +URL(chuck) := https://github.com/$(OWNER)/$(REPO)/archive/$(REV).tar.gz +SHA(chuck) := 1ecea44425eb9048a6ae9f2f37a3c21376511a13 +DIR(chuck) := src/app/chuck + +DIRS := include/chuck +DIR_CONTENT(include/chuck) := src/app/chuck/src/*.h + +PATCHES := src/app/chuck/patch +PATCH_OPT := -p1 -d src/app/chuck + +CHUCK_TAB = src/app/chuck/src/chuck.tab.c src/app/chuck/src/chuck.tab.h + +_dirs: $(DOWNLOADS) $(CHUCK_TAB) src/app/chuck/src/chuck.yy.c + $(VERBOSE) find src/app/chuck -name RtAudio.h -delete + +$(CHUCK_TAB): src/app/chuck/src/chuck.y $(DOWNLOADS) + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)$(YACC) -dv -b src/app/chuck/src/chuck $< + +src/app/chuck/src/chuck.yy.c: src/app/chuck/src/chuck.lex $(DOWNLOADS) + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)$(LEX) -o$@ $< diff --git a/src/app/chuck/README b/src/app/chuck/README new file mode 100644 index 0000000..ef104df --- /dev/null +++ b/src/app/chuck/README @@ -0,0 +1,23 @@ +ChucK is a strongly-timed concurrent music programming language. +This directory contains an initial non-interactive frontend. + +Configuration +~~~~~~~~~~~~~ + +The following configuration compiles and runs seven files: + +! +! +! +! +! +! +! +! +! +! +! +! +! +! +! diff --git a/src/app/chuck/component.cc b/src/app/chuck/component.cc new file mode 100644 index 0000000..a313fe7 --- /dev/null +++ b/src/app/chuck/component.cc @@ -0,0 +1,401 @@ +/*---------------------------------------------------------------------------- + ChucK Concurrent, On-the-fly Audio Programming Language + Compiler and Virtual Machine + + Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved. + http://chuck.stanford.edu/ + http://chuck.cs.princeton.edu/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + U.S.A. +-----------------------------------------------------------------------------*/ + +//----------------------------------------------------------------------------- +// file: component.cpp +// desc: chuck entry point for Genode +//----------------------------------------------------------------------------- + +/* Genode includes */ +#include +#include +#include +#include +#include + +/* ChucK includes */ +#include "chuck_compile.h" +#include "chuck_vm.h" +#include "chuck_bbq.h" +#include "chuck_errmsg.h" +#include "chuck_lang.h" +#include "chuck_console.h" +#include "chuck_globals.h" + +#include "util_math.h" +#include "util_string.h" +#include "util_thread.h" +#include "ulib_machine.h" +#include "chuck_system.h" + +using namespace Genode; + +struct Main : Chuck_System +{ + Genode::Env &env; + + Attached_rom_dataspace config_rom { env, "config" }; + + Timer::Connection timer; + + void load_config() + { + /* compile the config in sequence */ + config_rom.xml().for_each_sub_node([&] (Xml_node const node) { + if (node.has_type("file")) + try { + Xml_attribute path_attr = node.attribute("path"); + std::string path(path_attr.value_base(), path_attr.value_size()); + std::string args; + if (node.has_attribute("args")) { + Xml_attribute args_attr = node.attribute("args"); + args = std::string(args_attr.value_base(), args_attr.value_size()); + } + if (!compileFile(path, args)) + error("failed to compile ", path.c_str()); + else + log("compiled ", path.c_str()); + } catch (...) { + error("failed to parse file node"); + } + + else if (node.has_type("code")) + try { + Xml_attribute path_attr = node.attribute("path"); + std::string code(node.content_base(), node.content_size()); + std::string args; + if (node.has_attribute("args")) { + Xml_attribute args_attr = node.attribute("args"); + args = std::string(args_attr.value_base(), args_attr.value_size()); + } + if (!compileCode(code, args)) + error("compilation failed"); + else + log("compiled ", code.c_str()); + } catch (...) { + error("failed to parse code node"); + } + }); + } + + void handle_config() + { + config_rom.update(); + load_config(); + } + + //Signal_handler
config_handler + // { env.ep(), *this, &Main::handle_config }; + + void handle_timeout() + { + if (!g_vm->running()) { + env.parent().exit(0); + timer.trigger_periodic(0); + } else if( g_main_thread_hook && g_main_thread_quit ) { + log("bindling something"); + g_main_thread_hook( g_main_thread_bindle ); + } + } + + Signal_handler
timeout_handler + { env.ep(), *this, &Main::handle_timeout }; + + Main(Genode::Env &env); +}; + +Main::Main(Genode::Env &env) : env(env) +{ + Genode::Xml_node config_node = config_rom.xml(); + + Chuck_Compiler * compiler = NULL; + Chuck_VM * vm = NULL; + Chuck_VM_Code * code = NULL; + Chuck_VM_Shred * shred = NULL; + // ge: refactor 2015 + BBQ * bbq = NULL; + t_CKBOOL audio_started = FALSE; + + t_CKBOOL vm_halt = TRUE; + t_CKUINT srate = Audio_out::SAMPLE_RATE; + t_CKBOOL force_srate = FALSE; // added 1.3.1.2 + t_CKUINT buffer_size = BUFFER_SIZE_DEFAULT; + t_CKUINT num_buffers = NUM_BUFFERS_DEFAULT; + t_CKUINT dac = 0; + t_CKUINT adc = 0; + std::string dac_name = ""; // added 1.3.0.0 + std::string adc_name = ""; // added 1.3.0.0 + + t_CKUINT dac_chans = config_node.attribute_value("dac_channels", 2UL); + t_CKUINT adc_chans = config_node.attribute_value("adc_channels", 0UL); + + t_CKBOOL dump = FALSE; + t_CKBOOL probe = FALSE; + t_CKBOOL set_priority = FALSE; + t_CKBOOL auto_depend = FALSE; + t_CKBOOL block = FALSE; + t_CKBOOL no_vm = FALSE; + t_CKBOOL load_hid = FALSE; + t_CKBOOL enable_server = FALSE; + t_CKBOOL do_watchdog = TRUE; + t_CKINT adaptive_size = 0; + t_CKINT log_level = CK_LOG_INFO; + t_CKINT deprecate_level = 1; // 1 == warn + t_CKINT chugin_load = 1; // 1 == auto (variable added 1.3.0.0) + string filename = ""; + vector args; + + // list of search pathes (added 1.3.0.0) + std::list dl_search_path; + // initial chug-in path (added 1.3.0.0) + std::string initial_chugin_path; + + // default it + initial_chugin_path = g_default_chugin_path; + + // parse the colon list into STL list (added 1.3.0.0) + parse_path_list( initial_chugin_path, dl_search_path ); + // list of individually named chug-ins (added 1.3.0.0) + std::list named_dls; + +#if defined(__DISABLE_WATCHDOG__) + do_watchdog = FALSE; +#elif defined(__MACOSX_CORE__) + do_watchdog = TRUE; +#elif defined(__PLATFORM_WIN32__) && !defined(__WINDOWS_PTHREAD__) + do_watchdog = TRUE; +#else + do_watchdog = FALSE; +#endif + + t_CKUINT files = 0; + t_CKUINT count = 1; + t_CKINT i; + + // set log level + EM_setlog( log_level ); + + g_enable_realtime_audio = TRUE; + + // set adaptive size + if( adaptive_size < 0 ) adaptive_size = buffer_size; + + +//------------------------- VIRTUAL MACHINE SETUP ----------------------------- + + // allocate the vm - needs the type system + vm = m_vmRef = g_vm = new Chuck_VM; + // ge: refactor 2015: initialize VM + if( !vm->initialize( srate, dac_chans, adc_chans, adaptive_size, vm_halt ) ) + { + fprintf( stderr, "[chuck]: %s\n", vm->last_error() ); + env.parent().exit( 1 ); + } + + +//--------------------------- AUDIO I/O SETUP --------------------------------- + + // ge: 1.3.5.3 + bbq = g_bbq = new BBQ; + // set some parameters + bbq->set_srate( srate ); + bbq->set_bufsize( buffer_size ); + bbq->set_numbufs( num_buffers ); + bbq->set_inouts( adc, dac ); + bbq->set_chans( adc_chans, dac_chans ); + + // log + EM_log( CK_LOG_SYSTEM, "initializing audio I/O..." ); + // push + EM_pushlog(); + // log + EM_log( CK_LOG_SYSTEM, "probing '%s' audio subsystem...", g_enable_realtime_audio ? "real-time" : "fake-time" ); + + // probe / init (this shouldn't start audio yet... + // moved here 1.3.1.2; to main ge: 1.3.5.3) + if( !bbq->initialize( dac_chans, adc_chans, srate, 16, buffer_size, num_buffers, + dac, adc, block, vm, g_enable_realtime_audio, NULL, NULL, force_srate ) ) + { + EM_log( CK_LOG_SYSTEM, + "cannot initialize audio device" ); + // pop + EM_poplog(); + // done + env.parent().exit( 1 ); + } + + // log + EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" ); + EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" ); + EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate ); + EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size ); + if( g_enable_realtime_audio ) + { + EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers ); + EM_log( CK_LOG_SYSTEM, "adc: %ld dac: %d", adc, dac ); + EM_log( CK_LOG_SYSTEM, "adaptive block processing: %ld", adaptive_size > 1 ? adaptive_size : 0 ); + } + EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans ); + + // pop + EM_poplog(); + + +//------------------------- CHUCK COMPILER SETUP ----------------------------- + + // if chugin load is off, then clear the lists (added 1.3.0.0 -- TODO: refactor) + if( chugin_load == 0 ) + { + // turn off chugin load + dl_search_path.clear(); + named_dls.clear(); + } + + // allocate the compiler + compiler = m_compilerRef= g_compiler = new Chuck_Compiler; + // initialize the compiler (search_apth and named_dls added 1.3.0.0 -- TODO: refactor) + if( !compiler->initialize( vm, dl_search_path, named_dls ) ) + { + fprintf( stderr, "[chuck]: error initializing compiler...\n" ); + env.parent().exit( 1 ); + } + // enable dump + compiler->emitter->dump = dump; + // set auto depend + compiler->set_auto_depend( auto_depend ); + + // vm synthesis subsystem - needs the type system + if( !vm->initialize_synthesis( ) ) + { + fprintf( stderr, "[chuck]: %s\n", vm->last_error() ); + env.parent().exit( 1 ); + } + + + // set deprecate + compiler->env->deprecate_level = deprecate_level; + + // reset count + count = 1; + + compiler->env->load_user_namespace(); + + // log + EM_log( CK_LOG_SEVERE, "starting compilation..." ); + // push indent + EM_pushlog(); + + +//------------------------- SOURCE COMPILATION -------------------------------- + + // loop through and process each file + load_config(); + + // pop indent + EM_poplog(); + + // reset the parser + reset_parse(); + + // boost priority + if( Chuck_VM::our_priority != 0x7fffffff ) + { + // try + if( !Chuck_VM::set_priority( Chuck_VM::our_priority, vm ) ) + { + // error + fprintf( stderr, "[chuck]: %s\n", vm->last_error() ); + env.parent().exit( 1 ); + } + } + +//-------------------------- MAIN CHUCK LOOP!!! ----------------------------- + + // log + EM_log( CK_LOG_SYSTEM, "running main loop..." ); + // push indent + EM_pushlog(); + + // set run state + vm->start(); + + EM_log( CK_LOG_SEVERE, "initializing audio buffers..." ); + if( !bbq->digi_out()->initialize( ) ) + { + EM_log( CK_LOG_SYSTEM, + "cannot open audio output (use --silent/-s)" ); + env.parent().exit(1); + } + + // initialize input + bbq->digi_in()->initialize( ); + + // log + EM_log( CK_LOG_SEVERE, "virtual machine running..." ); + // pop indent + EM_poplog(); + + // NOTE: non-blocking callback only, ge: 1.3.5.3 + + // compute shreds before first sample + if( !vm->compute() ) + { + // done, 1.3.5.3 + vm->stop(); + // log + EM_log( CK_LOG_SYSTEM, "virtual machine stopped..." ); + } + + // start audio + if( !audio_started ) + { + // audio + if( !audio_started && g_enable_realtime_audio ) + { + EM_log( CK_LOG_SEVERE, "starting real-time audio..." ); + bbq->digi_out()->start(); + bbq->digi_in()->start(); + } + + // set the flag to true to avoid entering this function + audio_started = TRUE; + } + + + // silent mode buffers + SAMPLE * input = new SAMPLE[buffer_size*adc_chans]; + SAMPLE * output = new SAMPLE[buffer_size*dac_chans]; + // zero out + Genode::memset( input, 0, sizeof(SAMPLE)*buffer_size*adc_chans ); + Genode::memset( output, 0, sizeof(SAMPLE)*buffer_size*dac_chans ); + + //timer.sigh(timeout_handler); + //timer.trigger_periodic(100000); +}; + + +void Component::construct(Genode::Env &env) +{ + static Main inst(env); +} diff --git a/src/app/chuck/dummies.cc b/src/app/chuck/dummies.cc new file mode 100644 index 0000000..bb048fe --- /dev/null +++ b/src/app/chuck/dummies.cc @@ -0,0 +1,35 @@ +#include "util_console.h" + + +char * io_readline( const char * prompt ) +{ + return ""; +} + +void io_addhistory( const char * addme ) +{ } + +t_CKBOOL kb_initscr() +{ + return TRUE; +} + +void kb_endwin() +{ } + +t_CKINT kb_hit() +{ + return 0; +} + +t_CKINT kb_getch() +{ + return 0; +} + +// ready +t_CKBOOL kb_ready() +{ + return TRUE; +} + diff --git a/src/app/chuck/patch b/src/app/chuck/patch new file mode 100644 index 0000000..c4fb77f --- /dev/null +++ b/src/app/chuck/patch @@ -0,0 +1,501 @@ +diff --git a/src/chuck_bbq.h b/src/chuck_bbq.h +index 0cd059f..9cc0664 100644 +--- a/src/chuck_bbq.h ++++ b/src/chuck_bbq.h +@@ -44,9 +44,10 @@ + #elif defined(__MACOSX_CORE__) + #elif defined(__WINDOWS_DS__) + #elif defined(__WINDOWS_ASIO__) ++#elif defined(__GENODE_AUDIO__) + #else + #error "must define one:\ +-__LINUX_ALSA__ __UNIX_JACK__ __LINUX_JACK__ __LINUX_PULSE__ __MACOSX_CORE__ __WINDOWS_DS__" ++__LINUX_ALSA__ __UNIX_JACK__ __LINUX_JACK__ __LINUX_PULSE__ __MACOSX_CORE__ __WINDOWS_DS__ __GENODE_AUDIO__" + #endif + + struct Chuck_VM; +diff --git a/src/chuck_shell.cpp b/src/chuck_shell.cpp +index 726afa4..506f886 100644 +--- a/src/chuck_shell.cpp ++++ b/src/chuck_shell.cpp +@@ -45,6 +45,10 @@ + #include + #endif + ++#ifdef __PLATFORM_GENODE__ ++#include ++#endif ++ + using namespace std; + + // global shell pointer (lives in chuck_main) +@@ -630,7 +634,7 @@ void Chuck_Shell::do_code( string & code, string & out, string command ) + prompt = variables["COMMAND_PROMPT"]; + return; + } +-#else ++#elif defined(__PLATFORM_WIN32__) + char tmp_filepath1[MAX_PATH]; + win32_tmpnam(tmp_filepath1); + +@@ -650,6 +654,19 @@ void Chuck_Shell::do_code( string & code, string & out, string command ) + prompt = variables["COMMAND_PROMPT"]; + return; + } ++#elif defined(__PLATFORM_GENODE__) ++ char tmp_filepath[32]; ++ snprintf(tmp_filepath, sizeof(tmp_filepath), "/tmp/chuck_file.%x", Genode::Trace::Timestamp()&0xFFFFU); ++ ++ FILE * tmp_file = fopen( tmp_filepath, "w" ); ++ if( tmp_file == NULL ) ++ { ++ out += string( "shell: error: unable to open tmpfile '" ) + tmp_filepath + "'\n"; ++ prompt = variables["COMMAND_PROMPT"]; ++ return; ++ } ++#else ++#error Missing platform code for temporary files + #endif + + // write the code to the temp file +diff --git a/src/chuck_vm.cpp b/src/chuck_vm.cpp +index d907347..3ceafb2 100644 +--- a/src/chuck_vm.cpp ++++ b/src/chuck_vm.cpp +@@ -176,8 +176,16 @@ t_CKINT Chuck_VM::our_priority = 85; + t_CKINT Chuck_VM::our_priority = 0x7fffffff; + #endif + +- +-#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__) ++#if defined(__PLATFORM_GENODE__) ++//----------------------------------------------------------------------------- ++// name: set_priority() ++// desc: ... ++//----------------------------------------------------------------------------- ++t_CKBOOL Chuck_VM::set_priority( t_CKINT priority, Chuck_VM * vm ) ++{ ++ return FALSE; ++} ++#elif !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__) + //----------------------------------------------------------------------------- + // name: set_priority() + // desc: ... +@@ -244,7 +252,6 @@ t_CKBOOL Chuck_VM::set_priority( t_CKINT priority, Chuck_VM * vm ) + #endif + + +- + + //----------------------------------------------------------------------------- + // name: initialize() +diff --git a/src/digiio_rtaudio.cpp b/src/digiio_rtaudio.cpp +index e78b19d..ea349e8 100644 +--- a/src/digiio_rtaudio.cpp ++++ b/src/digiio_rtaudio.cpp +@@ -151,7 +151,7 @@ void Digitalio::probe() + + // allocate RtAudio + try { rta = new RtAudio( ); } +- catch( RtError err ) ++ catch( RtAudioError err ) + { + // problem finding audio devices, most likely + EM_error2b( 0, "%s", err.getMessage().c_str() ); +@@ -169,7 +169,7 @@ void Digitalio::probe() + for( int i = 0; i < devices; i++ ) + { + try { info = rta->getDeviceInfo(i); } +- catch( RtError & error ) ++ catch( RtAudioError & error ) + { + error.printMessage(); + break; +@@ -205,7 +205,7 @@ DWORD__ Digitalio::device_named( const std::string & name, t_CKBOOL needs_dac, t + + // allocate RtAudio + try { rta = new RtAudio( ); } +- catch( RtError err ) ++ catch( RtAudioError err ) + { + // problem finding audio devices, most likely + EM_error2b( 0, "%s", err.getMessage().c_str() ); +@@ -220,7 +220,7 @@ DWORD__ Digitalio::device_named( const std::string & name, t_CKBOOL needs_dac, t + for( int i = 0; i < devices; i++ ) + { + try { info = rta->getDeviceInfo(i); } +- catch( RtError & error ) ++ catch( RtAudioError & error ) + { + error.printMessage(); + break; +@@ -239,7 +239,7 @@ DWORD__ Digitalio::device_named( const std::string & name, t_CKBOOL needs_dac, t + for( int i = 0; i < devices; i++ ) + { + try { info = rta->getDeviceInfo(i); } +- catch( RtError & error ) ++ catch( RtAudioError & error ) + { + error.printMessage(); + break; +@@ -269,7 +269,16 @@ DWORD__ Digitalio::device_named( const std::string & name, t_CKBOOL needs_dac, t + + + +-#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__) ++#if defined(__PLATFORM_GENODE__) ++//----------------------------------------------------------------------------- ++// name: set_priority() ++// desc: ... ++//----------------------------------------------------------------------------- ++static t_CKBOOL set_priority( CHUCK_THREAD tid, t_CKINT priority ) ++{ ++ return FALSE; ++} ++#elif !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__) + //----------------------------------------------------------------------------- + // name: set_priority() + // desc: ... +@@ -515,7 +524,7 @@ BOOL__ Digitalio::initialize( DWORD__ num_dac_channels, + { + // allocate RtAudio + try { m_rtaudio = new RtAudio( ); } +- catch( RtError err ) ++ catch( RtAudioError err ) + { + // problem finding audio devices, most likely + EM_error2( 0, "%s", err.getMessage().c_str() ); +@@ -584,13 +593,13 @@ BOOL__ Digitalio::initialize( DWORD__ num_dac_channels, + { + // difference + long diff = device_info.sampleRates[i] - sampling_rate; +- // check // ge: changed from abs to labs, 2015.11 +- if( ::labs(diff) < closestDiff ) ++ // check ++ if( ::abs(diff) < closestDiff ) + { + // remember index + closestIndex = i; + // update diff +- closestDiff = ::labs(diff); ++ closestDiff = ::abs(diff); + } + + // for next highest +@@ -711,7 +720,7 @@ BOOL__ Digitalio::initialize( DWORD__ num_dac_channels, + CK_RTAUDIO_FORMAT, sampling_rate, &bufsize, + m_use_cb ? ( block ? &cb : &cb2 ) : NULL, vm_ref, + &stream_options ); +- } catch( RtError err ) { ++ } catch( RtAudioError err ) { + // log + EM_log( CK_LOG_INFO, "exception caught: '%s'...", err.getMessage().c_str() ); + EM_error2( 0, "%s", err.getMessage().c_str() ); +@@ -956,7 +965,7 @@ BOOL__ Digitalio::start( ) + try{ if( !m_start ) + m_rtaudio->startStream(); + m_start = TRUE; +- } catch( RtError err ){ return FALSE; } ++ } catch( RtAudioError err ){ return FALSE; } + #endif // __DISABLE_RTAUDIO__ + + #if defined(__CHIP_MODE__) +@@ -980,7 +989,7 @@ BOOL__ Digitalio::stop( ) + try{ if( m_start ) + m_rtaudio->stopStream(); + m_start = FALSE; +- } catch( RtError err ){ return FALSE; } ++ } catch( RtAudioError err ){ return FALSE; } + #endif // __DISABLE_RTAUDIO__ + + #if defined(__CHIP_MODE__) +@@ -1013,7 +1022,7 @@ BOOL__ Digitalio::stop( ) + // } + // + // return TRUE; +-// } catch( RtError err ){ return FALSE; } ++// } catch( RtAudioError err ){ return FALSE; } + //#endif // __DISABLE_RTAUDIO__ + // + // return FALSE; +diff --git a/src/util_hid.cpp b/src/util_hid.cpp +index 9c26e2d..b66e87a 100644 +--- a/src/util_hid.cpp ++++ b/src/util_hid.cpp +@@ -3725,7 +3725,7 @@ t_CKINT WiiRemote::disconnect() + msg.device_type = CK_HID_DEV_WIIREMOTE; + msg.type = CK_HID_DEVICE_DISCONNECTED; + +- HidInManager::push_message( msg ); ++ HidInManager::push_message( msg ); + + return 0; + } +@@ -7679,6 +7679,122 @@ const char * Keyboard_name( int k ) + return keyboards->at( k )->name; + } + ++#elif defined(__PLATFORM_GENODE__) ++ ++#include ++ ++static Genode::Signal_context g_input_sig_ctx; ++static Genode::Signal_receiver g_input_sig_rec; ++ ++static Input::Connection *g_input_session; ++ ++static int g_input_count = 0; ++ ++void Genode_input_init() ++{ ++ if( g_input_session == nullptr ) try { ++ g_input_session = new Input::Connection; ++ g_input_session->sigh(g_input_sig_rec.manage(&g_input_sig_ctx)); ++ g_input_count = g_input_count < 1 ? 1 : g_input_count+1; ++ } catch ( ... ) { } ++} ++ ++void Genode_input_quit() ++{ ++ if( --g_input_count > 0 ) { ++ delete g_input_session; ++ g_input_sig_rec.dissolve(&g_input_sig_ctx); ++ g_input_session = nullptr; ++ } ++} ++ ++void Genode_input_poll() ++{ ++ if ( !g_input_sig_rec.pending() ) ++ return; ++ do { g_input_sig_rec.wait_for_signal(); } ++ while ( g_input_sig_rec.pending() ); ++ ++ g_input_session->for_each_event( [&] ( Input::Event const &ev ) { ++ HidMsg msg; ++ ++ switch (ev.type()) { ++ case Input::Event::MOTION: ++ msg.device_type = CK_HID_DEV_MOUSE; ++ msg.type = CK_HID_MOUSE_MOTION; ++ msg.idata[0] = ev.ax(); ++ msg.idata[1] = ev.ay(); ++ break; ++ ++ case Input::Event::WHEEL: ++ msg.device_type = CK_HID_DEV_MOUSE; ++ msg.type = CK_HID_MOUSE_WHEEL; ++ msg.idata[1] = ev.ry(); ++ break; ++ ++ case Input::Event::PRESS: ++ case Input::Event::RELEASE: ++ case Input::Event::FOCUS: ++ case Input::Event::LEAVE: ++ case Input::Event::TOUCH: ++ case Input::Event::INVALID: return; ++ } ++ ++ HidInManager::push_message( msg ); ++ }); ++} ++ ++void Hid_init() { } ++void Hid_poll() { } ++void Hid_quit() { } ++ ++void Joystick_init() { } ++void Joystick_poll() { } ++void Joystick_quit() { } ++void Joystick_probe() { } ++int Joystick_count() { return -1; } ++int Joystick_open( int js ) { return -1; } ++int Joystick_open_async( int js ) { return -1; } ++int Joystick_open( const char * name ) { return -1; } ++int Joystick_close( int js ) { return -1; }; ++int Joystick_send( int js, const HidMsg * msg ) { return -1; } ++const char * Joystick_name( int js ) { return ""; } ++ ++void Mouse_init() { Genode_input_init(); } ++ ++void Mouse_poll() { Genode_input_poll(); } ++ ++void Mouse_quit() { Genode_input_quit(); } ++ ++void Mouse_probe() { } ++int Mouse_count() { return ( g_input_session == nullptr ) ? 1 : -1; } ++int Mouse_open( int m ) { return ( g_input_session == nullptr ) ? 1 : -1; } ++int Mouse_open( const char * name ) { return ( g_input_session == nullptr ) ? 1 : -1; } ++int Mouse_close( int m ) { return 0; } ++int Mouse_send( int m, const HidMsg * msg ) { return -1; } ++const char * Mouse_name( int m ) { return ""; } ++int Mouse_buttons( int m ) { return 0; } ++ ++void Keyboard_init() { } ++void Keyboard_poll() { } ++void Keyboard_quit() { } ++void Keyboard_probe() { } ++int Keyboard_count() { return -1; } ++int Keyboard_open( int kb ) { return -1; } ++int Keyboard_open( const char * name ) { return -1; } ++int Keyboard_close( int kb ) { return -1; } ++const char * Keyboard_name( int kb ) { return ""; } ++ ++t_CKINT TiltSensor_setPollRate( t_CKINT usec ) ++{ ++ return -1; ++} ++ ++t_CKINT TiltSensor_getPollRate( ) ++{ ++ return -1; ++} ++ + #endif + + +diff --git a/src/util_sndfile.h b/src/util_sndfile.h +index 2a62fd7..a4f4f3b 100644 +--- a/src/util_sndfile.h ++++ b/src/util_sndfile.h +@@ -184,6 +184,18 @@ + #define HAVE_LRINT 1 + #endif + ++#if defined(__PLATFORM_GENODE__) ++#define TYPEOF_SF_COUNT_T long ++#define CPU_CLIPS_POSITIVE 0 ++#define CPU_IS_BIG_ENDIAN 0 ++#define CPU_IS_LITTLE_ENDIAN 1 ++#define HAVE_PREAD 1 ++#define HAVE_PWRITE 1 ++#define OS_IS_MACOSX 0 ++#define OS_IS_WIN32 0 ++#define HAVE_LRINTF 1 ++#define HAVE_LRINT 1 ++#endif + + + // XXX 'inline' is necessary for C compilation +diff --git a/src/util_string.cpp b/src/util_string.cpp +index ff1770e..774d43c 100644 +--- a/src/util_string.cpp ++++ b/src/util_string.cpp +@@ -40,6 +40,10 @@ + #include + #endif // __PLATFORM_LINUX__ + ++#ifdef __PLATFORM_GENODE__ ++#define PATH_MAX 512 ++#endif // __PLATFORM_GENODE__ ++ + #include + using namespace std; + +diff --git a/src/util_thread.cpp b/src/util_thread.cpp +index 5e32ade..a4095a5 100644 +--- a/src/util_thread.cpp ++++ b/src/util_thread.cpp +@@ -69,7 +69,7 @@ XThread::~XThread( ) + { + if( thread != 0 ) + { +-#if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + pthread_cancel(thread); + pthread_join(thread, NULL); + #elif defined(__PLATFORM_WIN32__) +@@ -89,7 +89,7 @@ bool XThread::start( THREAD_FUNCTION routine, void * ptr ) + { + bool result = false; + +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + if( pthread_create( &thread, NULL, *routine, ptr ) == 0 ) + result = true; + #elif defined(__PLATFORM_WIN32__) +@@ -111,7 +111,7 @@ bool XThread::wait( long milliseconds, bool cancel ) + { + bool result = false; + +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + if(cancel) pthread_cancel(thread); + pthread_join(thread, NULL); + #elif defined(__PLATFORM_WIN32__) +@@ -138,7 +138,7 @@ bool XThread::wait( long milliseconds, bool cancel ) + //----------------------------------------------------------------------------- + void XThread :: test( ) + { +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + pthread_testcancel(); + #endif + } +@@ -152,7 +152,7 @@ void XThread :: test( ) + //----------------------------------------------------------------------------- + XMutex::XMutex( ) + { +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__)) + pthread_mutex_init(&mutex, NULL); + #elif defined(__PLATFORM_WIN32__) + InitializeCriticalSection(&mutex); +@@ -168,7 +168,7 @@ XMutex::XMutex( ) + //----------------------------------------------------------------------------- + XMutex::~XMutex( ) + { +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + pthread_mutex_destroy( &mutex ); + #elif defined(__PLATFORM_WIN32__) + DeleteCriticalSection(&mutex); +@@ -184,7 +184,7 @@ XMutex::~XMutex( ) + //----------------------------------------------------------------------------- + void XMutex::acquire( ) + { +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + pthread_mutex_lock(&mutex); + #elif defined(__PLATFORM_WIN32__) + EnterCriticalSection(&mutex); +@@ -200,7 +200,7 @@ void XMutex::acquire( ) + //----------------------------------------------------------------------------- + void XMutex::release( ) + { +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + pthread_mutex_unlock(&mutex); + #elif defined(__PLATFORM_WIN32__) + LeaveCriticalSection(&mutex); +@@ -389,7 +389,7 @@ void XWriteThread::flush_data_buffer() + // name: write_cb() + // desc: thread function + //----------------------------------------------------------------------------- +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + void * XWriteThread::write_cb(void * _thiss) + #elif defined(__PLATFORM_WIN32__) + unsigned XWriteThread::write_cb(void * _thiss) +diff --git a/src/util_thread.h b/src/util_thread.h +index ebdd5dd..3703844 100644 +--- a/src/util_thread.h ++++ b/src/util_thread.h +@@ -43,7 +43,7 @@ class FastCircularBuffer; + template class CircularBuffer; + + +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) || defined(__PLATFORM_GENODE__)) + #include + #define THREAD_TYPE + typedef pthread_t THREAD_HANDLE; +@@ -154,7 +154,7 @@ private: + void flush_data_buffer(); + + // callback +-#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) ++#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_GENODE__) ) + static void * write_cb( void * _thiss ); + #elif defined(__PLATFORM_WIN32__) + static unsigned THREAD_TYPE write_cb( void * _thiss ); diff --git a/src/app/chuck/target.mk b/src/app/chuck/target.mk new file mode 100644 index 0000000..f4cf9f0 --- /dev/null +++ b/src/app/chuck/target.mk @@ -0,0 +1,41 @@ +TARGET := chuck + +LIBS = stdcxx libc pthread rtaudio rtmidi liblo libsndfile base libogg libvorbis libFLAC + +CHUCK_DIR = $(call select_from_ports,chuck)/src/app/chuck/src + +CC_OPT += \ + -D__PLATFORM_GENODE__ \ + -D__DISABLE_MIDI__ \ + +CC_WARN += -Wno-sign-compare + +INC_DIR += $(PRG_DIR) $(CHUCK_DIR) + +CHUCK_SRC_C := \ + chuck.tab.c chuck.yy.c util_math.c util_network.c util_raw.c \ + util_xforms.c + +CHUCK_SRC_CC := \ + chuck_absyn.cpp chuck_parse.cpp chuck_errmsg.cpp \ + chuck_frame.cpp chuck_symbol.cpp chuck_table.cpp chuck_utils.cpp \ + chuck_vm.cpp chuck_instr.cpp chuck_scan.cpp chuck_type.cpp chuck_emit.cpp \ + chuck_compile.cpp chuck_dl.cpp chuck_oo.cpp chuck_lang.cpp chuck_ugen.cpp \ + chuck_otf.cpp chuck_stats.cpp chuck_bbq.cpp chuck_shell.cpp \ + chuck_console.cpp chuck_globals.cpp chuck_io.cpp chuck_system.cpp \ + digiio_rtaudio.cpp hidio_sdl.cpp \ + midiio_rtmidi.cpp ugen_osc.cpp ugen_filter.cpp \ + ugen_stk.cpp ugen_xxx.cpp ulib_machine.cpp ulib_math.cpp ulib_std.cpp \ + ulib_opsc.cpp ulib_regex.cpp util_buffers.cpp util_console.cpp \ + util_string.cpp util_thread.cpp util_opsc.cpp util_serial.cpp \ + util_hid.cpp uana_xform.cpp uana_extract.cpp + +LO_SRC_C := \ + lo/address.c lo/blob.c lo/bundle.c lo/message.c lo/method.c \ + lo/pattern_match.c lo/send.c lo/server.c lo/server_thread.c lo/timetag.c + +SRC_C := $(CHUCK_SRC_C) $(util_sndfile.c) +SRC_CC := $(filter-out util_console.cpp,$(CHUCK_SRC_CC)) dummies.cc component.cc + +vpath %.c $(CHUCK_DIR) +vpath %.cpp $(CHUCK_DIR)