⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midifns.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************                            midifns.c* Copyright 1989 Carnegie Mellon University*  Date | Change*-----------+-----------------------------------------------------------------* 29-Mar-88 | Created from IBM PC version of mpu.c*           | Added settime()* 02-May-88 | AMIGA  2000 version. portable version.* 12-Oct-88 | JCD : Exclusive AMIGA Version.* 13-Apr-89 | JCD : New portable version.* 19-Apr-89 | JCD : Amiga CAMD Version added.*  5-Apr-91 | JDW : Further modification* 17-Feb-92 | GWL : incorporate JMN's new mpu.c*  8-Jun-92 | JDZ : add support for ITC midi interface* 16-Dec-92 | RBD : replace JMN's mpu.c with LMS's mpu.c* 11-Mar-94 | PLu : port to  IRIX* 25-Apr-97 | RBD : it looks like SGI changed their interface.  I*	        |       made it compile again, but MIDI does not work, so*	        |       took out calls to actually send/recv MIDI data* 28-Apr-03 | DM  : Renamed random -> cmtrand, true->TRUE, false->FALSE*           |       Use features rather than system names in #ifdef's*****************************************************************************/#include "switches.h"#ifdef UNIX#include <sys/param.h>#ifndef OPEN_MAX/* this is here for compiling the UNIX version under AIX. This is a BSDism */#define OPEN_MAX 2000#endif /* OPEN_MAX */#endif /* UNIX */#ifdef UNIX_MACH#include "machmidi.h"#endif#ifdef AMIGA#ifdef AZTEC#include "functions.h"#endif /* AZTEC */#include "midi/camd.h"#include "clib/camd_protos.h"/* note: azt_camd_pragmas.h was produced by running MAPFD on the * lib/camd_lib.fd file included in the CAMD disk from Commodore. * The "CamdClient" calls are manually removed from  */#ifdef AZTEC#include "pragmas/azt_camd_pragmas.h"#else /* !AZTEC */#include "pragmas/lat_camd_pragmas.h"#endif /* AZTEC */#include "camdmidi.h"#include "ctype.h"#endif /* AMIGA */#ifdef UNIX_IRIX/* #define UNIX_IRIX_MIDIFNS -- this would enable actual midi I/O * if the actual midi I/O code worked *//* IRIX changed the MIDI interface, * retain this for older systems: */#ifdef UNIX_IRIX_MIDIFNS#include <dmedia/midi.h>#endif#endif#include "stdio.h"#include "cext.h"#include "midicode.h"#include "cmdline.h"#include "pitch.h"#include "midifns.h"#include "userio.h"#ifdef MACINTOSH_OR_DOS#ifndef WINDOWS#include "midibuff.h"#endif#endif#ifdef UNIX_ITC /* was ITC */#include "sys/param.h"/* since boolean is defined, block its definition in midistruct.h. * CMT defines boolean as ushort, but midistruct.h uses int.   * This is not a problem on RS/6000s, but beware! *//* the following would be included if we had the BSD switch set.  I think   we should try to avoid BSDisms; when fixed, the following should be   removed */#define NBBY 8#include "sys/select.h" /* defines fd_set */#define MIDI_HAS_BOOLEAN#include "midistruct.h"#include "cmtio.h"#endif /* UNIX_ITC */#ifdef  DOS#ifndef WINDOWS#include "timer.h"#include "mpu.h"#endif /* ifndef WINDOWS */#endif /* ifdef DOS */#ifndef BREAKTEST#define BREAKTEST#endif#ifdef UNIX#ifndef UNIX_IRIX#include "sys/time.h"#include "sys/timeb.h"#include "cmtio.h"#else#include <sys/types.h>#include <sys/time.h>#include <errno.h>#ifdef UNIX_IRIX_MIDIFNS#include <midi.h>#include <midiio.h>#endif /* UNIX_IRIX_MIDIFNS */#endif  /* UNIX_IRIX */#endif /* UNIX */#ifdef ITCstatic int ignore_realtime = 0;#endif /* ITC */#ifdef MACINTOSH/* added for ThinkC 7: */#include <OSUtils.h>/* port numbers are in the range 0..MAX_PORTS-1 */#define CHANNELS_PER_PORT 16#define MAX_PORTS ((MAX_CHANNELS + CHANNELS_PER_PORT - 1) / CHANNELS_PER_PORT)/* here are some MIDIMGR specific definitions */#ifdef MIDIMGR#include "MIDI.h"#include "midimgr.h"#define TICKS_TO_MS(t) t#define MS_TO_TICKS(t) t#else/* here are some non-MIDIMGR definitions for the Mac *//******************************************************************************       DMH: constants from macmidi.c*****************************************************************************//* the modem port, also called port A */#define portA 0/* the printer port, also called port B */#define portB 1/* a tick is 1/60 of a second * * the following tables and routines are used to convert * between ticks and milliseconds */#define TICKS_TO_MS(t)  (((t) * 50) / 3)#define MS_TO_TICKS(t)  (((t) * 3) / 50)#endif  /* def MIDIMGR */#endif  /* def MACINTOSH */#ifdef WINDOWS#define huge#endif/****************************************************************************** exported flags*****************************************************************************/boolean miditrace = FALSE;      /* enables printed trace of MIDI output */boolean musictrace = FALSE;     /* enables printed trace of commands */#ifdef MACINTOSH_OR_DOSboolean ctrlFilter = TRUE;    /* suppress continuous controller data */boolean exclFilter = TRUE;    /* suppress exclusive messages */boolean realFilter = TRUE;    /* suppress realtime messages */#endif/****************************************************************************** exported variables*****************************************************************************/public int keyloud;    /* set to velocity of last getkey event *//* public long error; */public short midi_error_flags = 0;/* The following midifns_syntax lists command line switches and options.   Since these are machine dependent, use conditional compilation.   Conditional compilation within a string is a bit tricky: you want to   write "\" for line continuation within the string, but "\" gets eaten   by the macro preprocessor.   That's why we define macros like AMIGAINPORT.   Regretably it doesn't work for all compilers. */ /* Lattice and RT/Unix aren't happy expanding the embedded macros below, so   I made a separate declaration of midifns_syntax for Unix */#ifdef UNIXpublic char *midifns_syntax = "block<s>Turn off midi THRU;\    miditrace<s>Trace low-level midi functions;\    noalloff<s>Do not send alloff message when done;\    trace<s>Trace music operations;\    tune<o>Load a tuning file";#else#ifdef MACINTOSH#ifdef MIDIMGRpublic char *midifns_syntax = "miditrace<s>Trace low-level midi functions;\    noalloff<s>Do not send alloff message when done;\    patch<s>Remember/reuse Midi Mgr patches;\    trace<s>Trace music operations;\    keep<s>Keep other processes running;\    tune<o>Load a tuning file";#else /* no MIDIMGR */public char *midifns_syntax = "miditrace<s>Trace low-level midi functions;\    noalloff<s>Do not send alloff message when done;\    patch<s>Remember/reuse Midi Mgr patches;\    trace<s>Trace music operations;\    tune<o>Load a tuning file";		#endif /* MIDIMGR */#else #ifdef AMIGApublic char *midifns_syntax = "block<s>Turn off midi THRU;\    inport<o>Inpur port number;\    miditrace<s>Trace low-level midi functions;\    noalloff<s>Do not send alloff message when done;\    outport<o>Output port number;\    trace<s>Trace music operations;\    tune<o>Load a tuning file";#else /* not UNIX or MACINTOSH or MIDIMGR or AMIGA */#ifdef DOSpublic char *midifns_syntax = "miditrace<s>Trace low-level midi functions;\    noalloff<s>Do not send alloff message when done;\    trace<s>Trace music operations;\    tune<o>Load a tuning file";#endif /* DOS */#endif /* AMIGA */#endif /* MACINTOSH */#endif /* UNIX */#ifdef MACINTOSHboolean do_midi_thru = FALSE; /* exported: copy midi in to midi out */#endif/****************************************************************************** local module variables*****************************************************************************/private int initialized = FALSE;   /* set by musicinit, cleared by musicterm */private boolean tune_flag = FALSE; /* set by musicinit, never cleared */#ifdef DOSprivate boolean metroflag = FALSE; /* flag to turn on metronome */#endifprivate int user_scale = FALSE;    /* TRUE if user-defined scale */private int bend[MAX_CHANNELS];    /* current pitch bend on channel */short cur_midi_prgm[MAX_CHANNELS];private pitch_table pit_tab[128];  /* scale definition */#ifdef DOSprivate ulong timeoffset = 0;public boolean exclerr = FALSE;public byte xcodemask; /* mask (00 or FF) */public byte xcode; /* mfr code */#endif#ifdef MACINTOSH_OR_DOSboolean sysex_pending = FALSE;#endif#ifdef AMIGA#define CONTCONT ((CMF_Ctrl & ~CMF_CtrlSwitch) | CMF_PitchBend | \        CMF_ChanPress)#endif  /* def AMIGA */#ifdef UNIXprivate ulong timeoffset = 0;#endif#ifdef UNIX_IRIX_MIDIFNSstatic MIport *miport;static int ignore_realtime = 0;private byte *sysex_p;private int sysex_n;#endif #ifdef ITCmi_id midiconn;#endif#ifdef MACINTOSHprivate ulong ticksAtStart = 0L;    /* clock ticks at time of last musicinit or timereset     * ASSUME: tick clock never wraps.  this is a good assumption, since     * the tick clock is set to zero when the power is turned on and the     * tick counter is 32 bits.  the Macintosh would need to be on for     * 828.5 days for the tick counter to wrap around! */#endif  /* def MACINTOSH *//****************************************************************************** functions declared in this module*****************************************************************************/private void fixup();private void midi_init();extern boolean check_ascii(); /*userio.c*/private void musicterm();/*****************************************************************************                alloff* Inputs:*    none* Effect: *    Sends MIDI all notes off command on every channel.****************************************************************************/#define ALL_NOTES_OFF 0x7B /*DMH: from macmidi.c*/void alloff(){    int c;    if (!initialized) fixup();    if (musictrace)    gprintf(TRANS,"alloff()\n");    for (c = 1; c <= MAX_CHANNELS; c++) {    midi_write(3, MIDI_PORT(c), (byte) (0xb0 | MIDI_CHANNEL(c)), ALL_NOTES_OFF, 0);    }}/****************************************************************                           eventwait** Input : wakeup time, -1 means forever* Output : none* Return: none* Effect: waits until ascii or midi input or timeout***************************************************************/#ifdef UNIX_ITCvoid eventwait(timeout)  long timeout;{    struct timeval unix_timeout;    struct timeval *waitspec = NULL;    fd_set readfds;    FD_ZERO(&readfds);    FD_SET(MI_CONNECTION(midiconn), &readfds);    FD_SET(fileno(stdin), &readfds);    if (timeout >= 0) {    timeout -= gettime();   /* convert to millisecond delay */    unix_timeout.tv_sec = timeout / 1000;    /* remainder become microsecs: */    unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000;    waitspec = &unix_timeout;    }    select(NOFILE+1, &readfds, 0, 0, waitspec);    return;}#else /* !UNIX_ITC */#ifdef UNIX/* see machmidi.c for UNIX_MACH implementation */#ifndef UNIX_MACH#ifdef UNIX_IRIX_MIDIFNSvoid eventwait(timeout)  long timeout;{    struct timeval unix_timeout;    struct timeval *waitspec = NULL;    fd_set readfds;    FD_ZERO(&readfds);    FD_SET(mdGetFd(miport), &readfds);    FD_SET(fileno(stdin), &readfds);    if (timeout >= 0) {              timeout -= gettime();   /* convert to millisecond delay */        unix_timeout.tv_sec = timeout / 1000;        /* remainder become microsecs: */        unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000;        waitspec = &unix_timeout;    }     select(FD_SETSIZE, &readfds, 0, 0, waitspec);    return;}#else#ifdef BUFFERED_SYNCHRONOUS_INPUTvoid eventwait(timeout)  long timeout;{    struct timeval unix_timeout;    struct timeval *waitspec = NULL;    if (timeout >= 0) {    timeout -= gettime();   /* convert to millisecond delay */    unix_timeout.tv_sec = timeout / 1000;    /* remainder become microsecs: */    unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000;    waitspec = &unix_timeout;    select(NOFILE+1, 0, 0, 0, waitspec);    } else {    int c = getc(stdin);    ungetc(c, stdin);    }    return;}#elsevoid eventwait(timeout)  long timeout;{    struct timeval unix_timeout;    struct timeval *waitspec = NULL;    int readfds = 1 << IOinputfd;    if (timeout >= 0) {    timeout -= gettime();   /* convert to millisecond delay */    unix_timeout.tv_sec = timeout / 1000;    /* remainder become microsecs: */    unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000;    waitspec = &unix_timeout;    }    select(NOFILE+1, &readfds, 0, 0, waitspec);    return;}#endif /* BUFFERED_SYNCHRONOUS_INPUT */#endif /* UNIX_IRIX */#endif /* UNIX_MACH */#endif /* UNIX */ /* I wanted to put an else here, but this confused a Unix C compiler */#endif /* UNIX_ITC */#ifdef AMIGA/* see camdmidi.c for Amiga implementation */#else#ifndef UNIX /* since I couldn't use an else above, have to check UNIX here */#ifdef WINDOWSvoid eventwait(timeout)  long timeout;{    if (timeout >= 0) {    gprintf(TRANS, "eventwait: not implemented\n");    return;    } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -