1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00
Leland Lucius 15b9bb96cd Update nyquist to SVN r331 (r3.16+)
------------------------------------------------------------------------
   r331 | rbd | 2020-10-13 12:40:12 -0500 (Tue, 13 Oct 2020) | 2 lines

   Also forgot to install NyquistWords.txt

   ------------------------------------------------------------------------
   r330 | rbd | 2020-10-13 12:34:06 -0500 (Tue, 13 Oct 2020) | 2 lines

   Forgot to move nyquistman.pdf from docsrc/s2h to release

   ------------------------------------------------------------------------
   r329 | rbd | 2020-10-13 11:32:33 -0500 (Tue, 13 Oct 2020) | 2 lines

   Updated some version numbers for 3.16.

   ------------------------------------------------------------------------
   r328 | rbd | 2020-10-13 11:20:52 -0500 (Tue, 13 Oct 2020) | 2 lines

   Fixed NyquistIDE antialiasing for plot text, fix format of message.

   ------------------------------------------------------------------------
   r327 | rbd | 2020-10-12 21:01:53 -0500 (Mon, 12 Oct 2020) | 2 lines

   Fixed a couple of format problems in manual. This version of Nyquist has been tested wtih macOS, Linux, 32&64-bit Windows.

   ------------------------------------------------------------------------
   r326 | rbd | 2020-10-12 20:21:38 -0500 (Mon, 12 Oct 2020) | 1 line

   Modified WIN32 32-bit XLisp to use 64-bit FIXNUMs. This allows XLisp and Nyquist to handle big sounds even on 32-bit machines. Probably at some cost, but inner loops are mostly float and int32, and the Nyquist release is 64-bit anyway. Maybe we'll have to run some benchmarks on Audacity, which is still 32-bit on Windows.
   ------------------------------------------------------------------------
   r325 | rbd | 2020-10-12 13:16:57 -0500 (Mon, 12 Oct 2020) | 1 line

   Win64 passes bigfiletest.lsp now. This version should work on all 64-bit systems now. These changes untested on Linux and macOS.
   ------------------------------------------------------------------------
   r324 | rbd | 2020-10-11 21:31:53 -0500 (Sun, 11 Oct 2020) | 2 lines

   I couldn't free enough space on my linux box, so I adjusted the bigfiletest to write 8-bit ulaw. It's still >4GB and >4G samples. Works on Linux.

   ------------------------------------------------------------------------
   r323 | rbd | 2020-10-11 19:41:25 -0500 (Sun, 11 Oct 2020) | 2 lines

   Missing file from last commit.

   ------------------------------------------------------------------------
   r322 | rbd | 2020-10-11 19:36:08 -0500 (Sun, 11 Oct 2020) | 1 line

   Found another case where WIN64 needs int64_t instead of long for sample count.
   ------------------------------------------------------------------------
   r321 | rbd | 2020-10-11 19:33:25 -0500 (Sun, 11 Oct 2020) | 3 lines

   Fixed s-save to	handle optional	and keyword parameters (which should never have	been mixed in the first	place).	Documentation cleanup - should be final for this version.

   ------------------------------------------------------------------------
   r320 | rbd | 2020-10-11 14:44:37 -0500 (Sun, 11 Oct 2020) | 2 lines

   Fixes to handle IRCAM sound format and tests for big file io working on macOS.

   ------------------------------------------------------------------------
   r319 | rbd | 2020-10-10 21:31:58 -0500 (Sat, 10 Oct 2020) | 2 lines

   Changes for linux and to avoid compiler warnings on linux.

   ------------------------------------------------------------------------
   r318 | rbd | 2020-10-10 20:50:23 -0500 (Sat, 10 Oct 2020) | 1 line

   This is the test used for Win64 version.
   ------------------------------------------------------------------------
   r317 | rbd | 2020-10-10 20:34:34 -0500 (Sat, 10 Oct 2020) | 1 line

   This version works on Win64. Need to test changes on macOS and linux.
   ------------------------------------------------------------------------
   r316 | rbd | 2020-10-10 19:59:15 -0500 (Sat, 10 Oct 2020) | 2 lines

   PWL changes to avoid compiler warning.

   ------------------------------------------------------------------------
   r315 | rbd | 2020-10-10 19:34:04 -0500 (Sat, 10 Oct 2020) | 2 lines

   A few more changes for 64-bit sample counts on Win64

   ------------------------------------------------------------------------
   r314 | rbd | 2020-10-10 13:19:42 -0500 (Sat, 10 Oct 2020) | 2 lines

   Fixed int64_t declaration in gate.alg

   ------------------------------------------------------------------------
   r313 | rbd | 2020-10-10 12:07:40 -0500 (Sat, 10 Oct 2020) | 2 lines

   Fixes to gate for long sounds

   ------------------------------------------------------------------------
   r312 | rbd | 2020-10-10 11:47:29 -0500 (Sat, 10 Oct 2020) | 2 lines

   Fixed sound_save types for intgen

   ------------------------------------------------------------------------
   r311 | rbd | 2020-10-10 11:09:01 -0500 (Sat, 10 Oct 2020) | 2 lines

   Fixed a 64-bit sample count problem in siosc.alg

   ------------------------------------------------------------------------
   r310 | rbd | 2020-10-10 11:03:12 -0500 (Sat, 10 Oct 2020) | 2 lines

   Fixed sndmax to handle 64-bit sample counts.

   ------------------------------------------------------------------------
   r309 | rbd | 2020-10-10 10:57:04 -0500 (Sat, 10 Oct 2020) | 2 lines

   Forgot to re-translate all tran/*.alg files with fix for int64 cast to int32. This version compiles on macOS and ready for test on Win64.

   ------------------------------------------------------------------------
   r308 | rbd | 2020-10-10 10:16:05 -0500 (Sat, 10 Oct 2020) | 2 lines

   Everything seems to compile and run on macOS now. Moving changes to Windows for test.

   ------------------------------------------------------------------------
   r307 | rbd | 2020-10-10 09:23:45 -0500 (Sat, 10 Oct 2020) | 1 line

   Added casts to avoid compiler warnings and to review changes to support 64-bit sample counts on Windows. Still not complete, and waiting to regenerate and compile tran directory code after updates to translation code that will insert more casts.
   ------------------------------------------------------------------------
   r306 | rbd | 2020-10-09 21:55:15 -0500 (Fri, 09 Oct 2020) | 2 lines

   Rebuilt seqfnint.c from header files.

   ------------------------------------------------------------------------
   r305 | rbd | 2020-10-09 21:53:33 -0500 (Fri, 09 Oct 2020) | 1 line

   Changed some FIXNUMS to LONG to avoid compiler warnings in seqfnint.c
   ------------------------------------------------------------------------
   r304 | rbd | 2020-10-09 21:44:03 -0500 (Fri, 09 Oct 2020) | 2 lines

   I discovered forgotten regression-test.lsp and added test that requires 64-bit sample counts to pass. Fixed a few bugs revealed by running the type-checking regression tests.

   ------------------------------------------------------------------------
   r303 | rbd | 2020-10-09 12:28:58 -0500 (Fri, 09 Oct 2020) | 2 lines

   Changes for 64-bit sample counts broke mult-channel s-save. Fixed in the commit for macOS.

   ------------------------------------------------------------------------
   r302 | rbd | 2020-10-09 10:03:39 -0500 (Fri, 09 Oct 2020) | 2 lines

   Changed snd-play to return samples computed and used that to make a test for computing long sounds that would overflow 32-bit length counts.

   ------------------------------------------------------------------------
   r301 | rbd | 2020-10-09 09:11:26 -0500 (Fri, 09 Oct 2020) | 2 lines

   corrected mistake in delaycv.alg and re-translated

   ------------------------------------------------------------------------
   r300 | rbd | 2020-10-09 09:09:06 -0500 (Fri, 09 Oct 2020) | 2 lines

   Fix to delaycv.alg -- "s" changed to "input" to avoid matching "s" in "sample_type".

   ------------------------------------------------------------------------
   r299 | rbd | 2020-10-09 09:03:33 -0500 (Fri, 09 Oct 2020) | 4 lines

   To avoid compiler warnings, XLisp interfaces to C int and long are now
   specified as LONG rather than FIXNUM, and the stubs that call the C
   functions cast FIXNUMs from XLisp into longs before calling C functions.

   ------------------------------------------------------------------------
   r298 | rbd | 2020-10-08 22:20:26 -0500 (Thu, 08 Oct 2020) | 2 lines

   This commit has many more fixes to handle long (64-bit) sounds, including a lot of fixes for warnings by Visual Studio assigning int64_t to long (works on macOS, doesn't work on VS). This was compiled and tested on macOS, and even computed a 27.1-hour sound using OSC, LP, SUM and MULT (haven't tested I/O yet).

   ------------------------------------------------------------------------
   r297 | rbd | 2020-10-07 13:04:02 -0500 (Wed, 07 Oct 2020) | 2 lines

   This is a major cleanup. It started with the goal of changing long to int64_t for sample counts so that on 64-bit windows, where long is only 32-bits, the sample counts would nevertheless be 64-bit allowing long sounds, which was a limitation for long recordings in Audacity. Since I was using compiler warnings to track possible loss-of-precision conversions from 64-bit sample counts, and there were *many* warnings, I started cleaning up *all* the warnings and ended up with a very large set of changes, including "modernizing" C declarations that date back to XLisp and CMU MIDI Toolkit code and were never changed. This version runs all the examples.sal code on macOS, but will surely have problems on Windows and Linux given the number of changes.

   ------------------------------------------------------------------------
   r296 | rbd | 2020-10-06 13:34:20 -0500 (Tue, 06 Oct 2020) | 2 lines

   More changes from long to int64_t for sample counts.

   ------------------------------------------------------------------------
   r295 | rbd | 2020-10-06 11:53:49 -0500 (Tue, 06 Oct 2020) | 2 lines

   More work on using 64-bit sample counts. Changed MAX_STOP from 32-bit to 64-bit limit.

   ------------------------------------------------------------------------
   r294 | rbd | 2020-10-06 11:48:05 -0500 (Tue, 06 Oct 2020) | 2 lines

   Made some changes so that sample counts are int64_t (for windows) instead of long to support sample counts above 31 bits.

   ------------------------------------------------------------------------
   r293 | rbd | 2020-10-04 21:30:55 -0500 (Sun, 04 Oct 2020) | 2 lines

   Fixed a few minor things for Linux and tested on Linux.

   ------------------------------------------------------------------------
   r292 | rbd | 2020-10-04 21:00:28 -0500 (Sun, 04 Oct 2020) | 2 lines

   Update extensions: all are minor changes.

   ------------------------------------------------------------------------
   r291 | rbd | 2020-09-24 13:59:31 -0500 (Thu, 24 Sep 2020) | 2 lines

   New implementation of seq and seqrep, added get-real-time, documented get-real-time, fixed examples.sal and examples.lsp which are now in lib rather than extensions (so they are now back in the basic installation), other cleanup.

   ------------------------------------------------------------------------
   r290 | rbd | 2020-08-16 16:24:52 -0500 (Sun, 16 Aug 2020) | 2 lines

   Fixed bug in snd-gate, revised GATE and NOISE-GATE to handle multi-channel sound. RMS now handles multi-channel input. S-AVG added to take multichannel input (but not used, because RMS could not be written without making SND-SRATE convert multichannel sound to vector of floats. That seems to be going toward a fully vectorized model. Not going there for now.

   ------------------------------------------------------------------------
   r289 | rbd | 2020-07-09 16:27:45 -0500 (Thu, 09 Jul 2020) | 2 lines

   Added GET-REAL-TIME function to XLISP. May not work yet on Windows. Various fixes for compiler warnings. I noticed FLAC doesn't work (I guess it never did) and I cannot figure out how this even links because flac_min seems to be undefined. Something to look at later.
2021-01-27 23:45:25 -06:00

668 lines
22 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* MOXC -- a C version of Collinge's MOXIE language */
/* Copyright 1989 Carnegie Mellon University */
/*****************************************************************************
* Change Log
* Date | Change
*-----------+-----------------------------------------------------------------
* 31-Dec-85 | Modified for use with midi
* 5-Feb-86 | Added m_rest and m_restuntil allowing rests at top level
* 28-May-86 | Added command line parsing
* 4-Jun-86 | changed keyevent to separate calls for each event type
* 10-Jul-86 | put loop in mainscore with prompt to play and replay
* 03-Jun-88 | modified for portability (AMIGA) -JCD
* 07-Jul-89 | time bases -RBD
* 31-Jan-90 | GWL : cleaned up for LATTICE
* 30-Jun-90 | RBD : further changes
* 2-Apr-91 | JDW : further changes
* 4-Mar-91 | GWL : DOS allows odd inst addrs
* 10-Oct-94 | nix : posicionador tridimensionale interface
* 28-Apr-03 | DM : true->TRUE, false->FALSE
* 18-May-15 | RBD : The varargs hack to allow arbitrary parameters (only
* | limited by total size) passed to cause() breaks down on ia64
* | where args are not passed uniformly on the stack. To fix this
* | the beautiful cause() that survived 30 years of ports, will
* | finally have to go. The new cause() will take only one
* | parameter to pass along to callees. It will be of type
* | call_args_node (the same type used by the scheduler to store
* | the args.) It will now be up to the caller to pack the real
* | args into call_args_node, and up to the callee to unpack.
* | (packing/unpacking were previously hidden in moxc.c)
*****************************************************************************/
#include "switches.h"
#ifdef AMIGA
#ifdef AZTEC
#include "functions.h"
#else
#include "amiga.h"
#endif
#include "exec/exec.h"
#include "cmtcmd.h"
extern long event_mask; /* imported from midifns.c */
#endif
extern int abort_flag; /*DMH: taken out of ifdef AMIGA for moxcrun*/
#include "stdio.h"
#include "cext.h"
#include "userio.h"
#include "midifns.h"
#include "cmdline.h"
#include "midicode.h"
#include "timebase.h"
#include "moxc.h"
#ifdef AMIGA /*DMH: only AMIGA cares about AMIGA's "proportional controllers"*/
#include "prop1.h"
#endif
#ifdef POSICIONADOR_3D
#include "pos3d.h"
#include "pos3dbuf.h"
#endif /* POSICIONADOR_3D */
extern char *app_syntax;
/***************************************************************************
*
* IMPORTS:
* asciievent(k) user-defined action for terminal input
* bendchange(ch, val) user-defined pitch bend handler
* ctrlchange(ch, c, val) user-defined control change handler
* keydown(ch, p, v) user-defined MIDI note on handler
* keyup(ch, p) user-defined MIDI note off handler
* mainscore() user-defined first action(s)
* musicfns lots of time and io functions
* peddown(ch) user-defined pedal down handler
* pedup(ch) user-defined pedal up handler
* touchchange(ch, val) user-defined aftertouch handler
* app_syntax string defining extra command line options
*
* EXPORTS:
*
* cause(delay, routine, packed_args)
* moxcdone -- set to TRUE to quit
* eventtime -- ideallized current time
*
*****************************************************************************/
#define SAFEMOXC TRUE
#define BREAKKEY 0x03
int moxcdone; /* flag to halt execution */
time_type eventtime; /* time of current call -- used to avoid */
/* timing errors due to finite execution speed */
time_type virttime; /* virtual time of current call */
timebase_type timebase; /* time base of current call */
int mididecode = TRUE; /* whether to decode messages or just call midievent */
int debug = FALSE;
int moxcdebug = FALSE;
time_type next_wakeup;
timebase_type default_base;
#ifdef AMIGA
int pub_port_signal;
struct MsgPort pub_port;
#endif
/*****************************************************************************
* Routines local to this module
*****************************************************************************/
private void callrun(void);
private void decode(void);
private void moxcterm(void);
/****************************************************************************
* callallcancel
* Inputs:
* timebase_queue
* Effect:
* return all calls to free list
* Implementation:
* If timebase_queue is not empty, there's a pending call. Remove the call
* (not necessarily the timebase) and repeat.
****************************************************************************/
void callallcancel(void)
{
if (moxcdebug) gprintf(GDEBUG, "cancel all calls\n");
while (timebase_queue) {
timebase = timebase_queue;
timebase_queue = timebase->next;
while (timebase->heap_size > 0) {
call_free(remove_call(timebase));
}
insert_base(timebase);
}
}
/* catchup -- bring current timebase up to date by running its calls */
/**/
void catchup(void)
{
register call_type call;
/* Remember where we're going in virtual time because setting the
* rate will also modify timebase->virt_base. We don't want catchup
* to stop short:
*/
time_type target_time = timebase->virt_base;
/* remember timebase here because it's possible that a call will do
* a timebase_use() and change it:
*/
register timebase_type my_base = timebase;
while (my_base->heap_size != 0 &&
(my_base->heap[1]->u.e.time < target_time)) {
/* eventtime is the real time at which something was scheduled */
eventtime = (my_base->next_time) >> 8;
call = remove_call(my_base);
virttime = call->u.e.time;
(*(call->u.e.routine))(&(call->u.e.p));
call_free(call);
}
/* now that we've possibly pulled events out of the timebase, adjust
* the position in the timebase queue (and possibly remove it).
*/
remove_base(my_base);
insert_base(my_base);
}
/****************************************************************************
* cause
* Inputs:
* delay_type (long) delay: time before this call should occur
* int (*routine)(): routine that implements the call
* int p1 through p8: parameters to pass to routine
* Effect:
* builds a call and puts it in pending queue for later scheduling
****************************************************************************/
#ifndef DOTS_FOR_ARGS
THIS CODE IS OBSOLETE
void cause(delay, routine, p)
delay_type delay;
int (*routine)();
call_args_node p;
#else
#include <stdarg.h>
void cause(delay_type delay, void (*routine)(call_args_type args), call_args_type p)
#endif
{
register call_type call = call_alloc();
if (!call) {
gprintf(ERROR, "cause: out of memory\n");
EXIT(1);
}
#ifdef DOTS_FOR_ARGS
call->u.e.time = virttime + delay;
call->u.e.priority = 128; /* default priority */
call->u.e.routine = routine;
call->u.e.p = *p;
#else
THIS CODE IS OBSOLETE
call->u.e.time = virttime + delay;
call->u.e.priority = 128; /* default priority */
call->u.e.routine = routine;
call->u.e.p = p;
#endif
#ifdef SAFEMOXC
if (call->u.e.routine == 0) {
gprintf(ERROR,"cause called with NULL routine\n");
EXIT(1);
/* Intel (x86 or x86_64) allows odd routine addresses;
* RISC architectures do not.
*/
#if (!defined(DOS) && __i386__ != 1 && __x86_64__ != 1)
} else if (((long) call->u.e.routine) & 1) {
gprintf(ERROR, "cause called with bad routine address: 0x%lx\n",
call->u.e.routine);
EXIT(1);
#endif
}
#endif
/* put call in default queue */
callinsert(timebase, call);
if (moxcdebug) {
gprintf(GDEBUG,"(cause) call is pending on timebase 0x%x:\n", timebase);
callshow(call);
}
}
/****************************************************************************
* causepri
* Inputs:
* int delay: time before this call should occur
* int pri: priority, lowest priority goes first
* int (*routine)(): routine that implements the call
* int p1 through p8: parameters to pass to routine
* Effect:
* builds a call and puts it in pending queue for later scheduling
****************************************************************************/
#ifndef DOTS_FOR_ARGS
THIS CODE IS OBSOLETE
void causepri(delay, pri, routine, p)
delay_type delay;
int pri;
int (*routine)();
call_args_node p;
#else
/* already included stdarg.h */
void causepri(delay_type delay, int pri, void (*routine)(call_args_type args), call_args_type args)
#endif
{
register call_type call = call_alloc();
if (!call) {
gprintf(ERROR, "cause: out of memory\n");
EXIT(1);
}
#ifdef DOTS_FOR_ARGS
call->u.e.time = virttime + delay;
call->u.e.priority = pri; /* default priority */
call->u.e.routine = routine;
call->u.e.p = *args;
#else
call->u.e.time = virttime + delay;
call->u.e.priority = pri; /* default priority */
call->u.e.routine = routine;
call->u.e.p = p;
#endif
#ifdef SAFEMOXC
if (call->u.e.routine == 0) {
gprintf(ERROR,"cause called with NULL routine\n");
EXIT(1);
/* Intel (x86 or x86_64) allows odd routine addresses;
* RISC architectures do not.
*/
#if (!defined(DOS) && __i386__ != 1 && __x86_64__ != 1)
} else if (((long) call->u.e.routine) & 1) {
gprintf(ERROR, "causepri called with bad routine address: 0x%lx\n",
call->u.e.routine);
EXIT(1);
#endif
}
#endif
/* put call in default queue */
callinsert(timebase, call);
if (moxcdebug) {
gprintf(GDEBUG,"(cause) call is pending:");
callshow(call);
}
}
/****************************************************************************
* callrun
* Inputs:
* call_type call: the call to execute
* Effect:
* executes the previously scheduled call call and deallocates it
****************************************************************************/
private void callrun(void)
{
call_type call;
if (moxcdebug) {
gprintf(GDEBUG,"(callrun) running a call: \n");
}
/* remove from head of queue */
while (!timebase_queue) gprintf(TRANS, "callrun fatal error\n");
timebase = timebase_queue;
timebase_queue = timebase->next;
if (debug) gprintf(TRANS, "callrun time %ld\n", timebase->next_time);
eventtime = (timebase->next_time) >> 8; /* real time of the call */
/* remove first call from timebase */
call = remove_call(timebase);
if (debug) gprintf(TRANS, "callrun call %p\n", call);
insert_base(timebase);
virttime = call->u.e.time; /* virtual time of the call */
if (moxcdebug) callshow(call);
(*(call->u.e.routine))(&(call->u.e.p));
call_free(call);
}
/****************************************************************************
* m_restuntil
* Inputs:
* int time: call time to rest until
* Effect:
* Waits until the specified time has been reached (absolute time).
* Other "caused" calls will take place during the rest provided
* this routine is called from "mainscore" (see m_rest description).
****************************************************************************/
void m_restuntil(time)
time_type time;
{
time = virt_to_real(timebase, time);
while(time > gettime()) {
moxcwait(time);
}
}
/****************************************************************************
* m_rest
* Inputs:
* int time: Amount of time to rest
* Effect:
* Waits until the amount of time specified has lapsed
* Assumes:
* Must not be called from a "caused" routine. Must only be called
* from "mainscore" or a routine called directly or indirectly from
* "mainscore" without using "cause".
****************************************************************************/
void m_rest(time)
time_type time;
{
m_restuntil(time + real_to_virt(timebase, gettime()));
}
/****************************************************************************
* moxcinit
* Inputs:
* int argc: number of command line arguments
* char * argv: command line argument array
* Effect: initializes moxc system
****************************************************************************/
boolean moxcinit(argc, argv)
int argc;
char * argv[];
{
meminit();
io_init();
#ifdef AMIGA
pub_port_signal = AllocSignal(-1L);
pub_port.mp_Node.ln_Type = NT_MSGPORT;
pub_port.mp_SigBit = pub_port_signal;
pub_port.mp_SigTask = FindTask(0L);
pub_port.mp_Flags = PA_SIGNAL;
pub_port.mp_Node.ln_Name = "CMTcmdport";
pub_port.mp_MsgList.lh_Head =
(struct Node *)&pub_port.mp_MsgList.lh_Tail;
pub_port.mp_MsgList.lh_TailPred =
(struct Node *)&pub_port.mp_MsgList.lh_Head;
event_mask |= (1L << pub_port_signal);
AddPort(&pub_port);
#endif
cu_register((cu_fn_type) moxcterm, NULL);
cl_syntax(midifns_syntax);
cl_syntax("debug<s>Enable verbose debugging;\
moxc<s>Enable moxc debug mode;");
cl_syntax(app_syntax);
if (!cl_init(argv, argc)) {
/* make sure user gets to read the error message(s): */
gprintf(TRANS, "Type anything to exit...");
#ifdef DOS
wait_ascii();
#else
ggetchar();
#endif
return FALSE;
}
debug = cl_switch("debug");
moxcdebug = cl_switch("moxc");
timebase = default_base = timebase_create(100);
default_base->rate = 2560L;
eventtime = 0L;
next_wakeup = MAXTIME;
musicinit();
#ifdef POSICIONADOR_3D
ptInit();
#endif
moxcdone = 0;
return TRUE;
}
/****************************************************************************
* moxcwait
* Input:
* -1 => wait for next keyboard or midi event or queued event
* 0 => don't wait
* T => wait up to T for next keyboard or midi event or queued event
* (this is used by m_restuntil)
* Assume: there is work to do (npending > 0 || evqueue) ??
* Effect: dispatch on user inputs, cause calls
****************************************************************************/
void moxcwait(dateoftimeout)
time_type dateoftimeout;
{
time_type maxtime = dateoftimeout;
if (timebase_queue) {
if ((timebase_queue->next_time >> 8) < maxtime)
maxtime = (timebase_queue->next_time) >> 8;
}
eventwait(maxtime);
decode();
}
/****************************************************************************
* decode
* Effect: dispatch on user inputs, cause calls
****************************************************************************/
private void decode(void)
{
/* It is important that midi_data is on a word boundary because we
copy to it by doing a word transfer.
*/
byte midi_data[4];
time_type now;
byte code;
char k;
#ifdef AMIGA
struct cmd_msg *cmd;
#endif
now = gettime();
timebase = default_base;
eventtime = now;
virttime = 0L;
/* gprintf(GDEBUG, "decode at time %ld\n", now); */
/**********************************************
* poll for and decode midi keyboard input
***********************************************/
while (getbuf(FALSE, midi_data)) {
/* only divide if necessary, divides take 100us on 8MHz 68000: */
if (virttime == 0)
virttime = real_to_virt(default_base, now);
/* short-circuit midi decoding */
if (!mididecode) {
midievent(midi_data);
continue;
}
code = midi_data[0] & MIDI_CODE_MASK;
if (code == MIDI_ON_NOTE) {
if (midi_data[2] == 0) { /* velocity 0 -> note off */
keyup(1+(midi_data[0] & MIDI_CHN_MASK), midi_data[1]);
} else {
keydown((midi_data[0] & MIDI_CHN_MASK)+1,
midi_data[1], midi_data[2]);
}
} else if (code == MIDI_OFF_NOTE) {
keyup((midi_data[0] & MIDI_CHN_MASK)+1, midi_data[1]);
} else if (code == MIDI_TOUCH) {
touchchange((midi_data[0] & MIDI_CHN_MASK)+1,midi_data[1]);
} else if (code == MIDI_BEND) {
bendchange((midi_data[0] & MIDI_CHN_MASK)+1,
midi_data[1] + (midi_data[2] << 7));
} else if (code == MIDI_CTRL && midi_data[1] == SUSTAIN) {
if (midi_data[2] == 0) pedup((midi_data[0] & MIDI_CHN_MASK) + 1);
else peddown((midi_data[0] & MIDI_CHN_MASK) + 1);
} else if (code == MIDI_CTRL) {
ctrlchange((midi_data[0] & MIDI_CHN_MASK) + 1,
midi_data[1], midi_data[2]);
} else if (code == MIDI_CH_PROGRAM) {
prgmchange((midi_data[0] & MIDI_CHN_MASK) + 1, midi_data[1] + 1);
/* think C midi driver doesn't handle sysex the way the Amiga drivers do (yet) */
#ifndef MACINTOSH
} else if (code == MIDI_SYSEX) {
sysex();
#endif
}
}
/**********************************************
* poll for ASCII keyboard input
***********************************************/
while (get_ascii(&k)) {
virttime = real_to_virt(default_base, now);
asciievent(k);
/* if user doesn't handle abort char in asciievent,
we should exit now to avoid an infinite loop */
if (abort_flag) EXIT(1);
}
#ifdef POSICIONADOR_3D
/**********************************************
* poll for posicionador tridimensionale input
**********************************************/
{
pt_value pt_data;
while (ptGetValue(&pt_data)) {
/* only divide if necessary, divides take 100us on 8MHz 68000: */
if (virttime == 0)
virttime = real_to_virt(default_base, now);
ptevent(&pt_data);
}
}
#endif /* POSICIONADOR_3D */
#ifdef AMIGA
/**********************************************
* poll for proportional controller port
**********************************************/
if (prop_1_events) {
int events;
Disable();
events = prop_1_events;
prop_1_events = 0;
Enable();
if (events & BUTTON_1_RIGHT_CHANGE)
buttonchange(3, prop_1_right_button);
if (events & BUTTON_1_LEFT_CHANGE)
buttonchange(2, prop_1_left_button);
if (events & PROP_1_LEFT_CHANGE)
propchange(2, prop_1_left_data);
if (events & PROP_1_RIGHT_CHANGE)
propchange(3, prop_1_right_data);
}
/**********************************************
* poll for input from public command port
***********************************************/
while (cmd = (struct cmd_msg *) GetMsg(&pub_port)) {
struct symb_descr *desc = &HASHENTRY(lookup(cmd->symbol_name));
/* gprintf(TRANS, "got %lx (%s) from pub_port\n", cmd, cmd->symbol_name); */
virttime = real_to_virt(default_base, now);
if (!desc) {
gprintf(TRANS, "Error, symbol %s undefined.\n", cmd->symbol_name);
} else if (desc->symb_type != cmd->symb_type) {
gprintf(TRANS, "Error, wrong type for symbol %s\n",
cmd->symbol_name);
} else if (cmd->symb_type == fn_symb_type) {
/* gprintf(TRANS, "Calling routine\n"); */
(*(desc->ptr.routine))(
(int) cmd->the_args[0], (int) cmd->the_args[1],
(int) cmd->the_args[2], (int) cmd->the_args[3],
(int) cmd->the_args[4], (int) cmd->the_args[5],
(int) cmd->the_args[6], (int) cmd->the_args[7]
);
} else if (cmd->symb_type == var_symb_type) {
*(desc->ptr.intptr) = (int) cmd->the_args[0];
} else if (cmd->symb_type == vec_symb_type) {
if (cmd->the_args[0] >= desc->size) {
gprintf(TRANS, "Error: Vector %s is of size %d\n",
cmd->symbol_name, desc->size);
} else {
(desc->ptr.intptr)[cmd->the_args[0]] = cmd->the_args[1];
/* gprintf(TRANS, "vec: setting %lx\n",
&(desc->ptr.intptr)[cmd->the_args[0]]); */
}
} else gprintf(TRANS, "Symbol Type Error\n");
ReplyMsg(&(cmd->msg));
}
#endif
/**********************************************
* poll for next call in queue
***********************************************/
now = (now + 1) << 8; /* shift because next_time is also scaled,
* add 256 because next_time has added priority */
if (debug)
gprintf(TRANS, "now %ld next_time %ld\n",
now, (timebase_queue ? timebase_queue->next_time : 1234));
/* give pending events priority, but every 100 events, loop to allow
input processing (user may want to give a "quit" command) */
for (k = 0;
k < 100 && timebase_queue && (now > timebase_queue->next_time);
k++) {
callrun();
}
/*******************
* flush text output
********************/
#ifdef MACINTOSH_OR_UNIX
gflush();
#endif
}
/****************************************************************************
* quit
* Effect: tells moxc to shut down
****************************************************************************/
void quit()
{
moxcdone = TRUE;
}
/* moxcrun -- schedule events until done */
/**/
void moxcrun()
{
moxcdone = FALSE;
while (!moxcdone && !abort_flag) { /* test for finish */
if (!timebase_queue) moxcdone = TRUE;
else moxcwait(MAXTIME); /* do work */
}
}
/* moxcterm -- clean up after moxcinit */
/**/
private void moxcterm(void)
{
#ifdef AMIGA
FreeSignal((long) pub_port_signal);
RemPort(&pub_port);
#endif
}