/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2002 Masanao Izumo Copyright (C) 1995 Tuukka Toivonen 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 USA portmidisyn_c.c - PortMIDI synthesizer interface Copyright (c) 2003 Keishi Suenaga I referenced following sources. alsaseq_c.c - ALSA sequencer server interface Copyright (c) 2000 Takashi Iwai readmidi.c DESCRIPTION =========== This interface provides a Portmidi MIDI device interface which receives events and plays it in real-time. On this mode, TiMidity works purely as software (real-time) MIDI render. For invoking PrtMIDI synthesizer interface, run timidity as folows: % timidity -iP (interactively select an Input MIDI device) or % timidity -iP 2 (connect to MIDI device No. 2) TiMidity loads instruments dynamically at each time a PRM_CHANGE event is received. It sometimes causes a noise. If you are using a low power machine, invoke timidity as follows: % timidity -s 11025 -iP (set sampling freq. to 11025Hz) or % timidity -EFreverb=0 -iP (disable MIDI reverb effect control) TiMidity keeps all loaded instruments during executing. To use TiMidity as output device, you need a MIDI loopback device. (for windows) I use MIDI Yoke. It can freely be obtained MIDI-OX site (http://www.midiox.com). (for ALSA) You can easily meke it. See MIDI router section of Alsa 0.9.0 howto (http://www.suse.de/~mana/alsa090_howto.html#sect05 ). */ //#define USE_PORTMIDI 1 //#define USE_GTK_GUI 1 #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ #include "rtsyn.h" #ifdef USE_GTK_GUI #include "wsgtk_main.h" #endif #ifndef __W32__ #include #include //#include #include #endif #ifndef __W32__ static struct termios initial_settings, new_settings; static int peek_character = -1; #endif extern int volatile stream_max_compute; // play_event() の compute_data() で計算を許す最大時間 int seq_quit=~0; static int ctl_open(int using_stdin, int using_stdout); static void ctl_close(void); static int ctl_read(int32 *valp); static int cmsg(int type, int verbosity_level, char *fmt, ...); static void ctl_event(CtlEvent *e); static void ctl_pass_playing_list(int n, char *args[]); #ifndef __W32__ static void init_keybord(void); static void close_keybord(void); static int kbhit(void); static char readch(void); #endif /**********************************/ /* export the interface functions */ #define ctl portmidisyn_control_mode ControlMode ctl= { "PortMIDI Synthesizer interface", 'P', 1,0,0, 0, ctl_open, ctl_close, ctl_pass_playing_list, ctl_read, cmsg, ctl_event }; static int32 event_time_offset; static FILE *outfp; /*ARGSUSED*/ static int ctl_open(int using_stdin, int using_stdout) { ctl.opened = 1; ctl.flags &= ~(CTLF_LIST_RANDOM|CTLF_LIST_SORT); if (using_stdout) outfp = stderr; else outfp = stdout; return 0; } static void ctl_close(void) { fflush(outfp); if(seq_quit==0){ rtsyn_synth_stop(); rtsyn_close(); seq_quit=~0; } ctl.opened=0; } static int ctl_read(int32 *valp) { return RC_NONE; } #ifdef IA_W32G_SYN extern void PutsConsoleWnd(char *str); extern int ConsoleWndFlag; #endif static int cmsg(int type, int verbosity_level, char *fmt, ...) { #ifndef IA_W32G_SYN va_list ap; if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) && ctl.verbosity MAX_PORT ){ printf( "Usage: timidity -iW [Midi interface No s]\n"); return; } #endif if(n>0){ port=0; while(port MAX_PORT); printf("\n"); printf("Opening Device drivers:"); printf("Available Midi Input devices:\n"); for(i=0;i 2000 ) { winplaymidi_sleep_level = 2; } } else if ( winplaymidi_sleep_level == 0 ) { winplaymidi_active_start_time = 0; } rtsyn_play_calculate(); if ( winplaymidi_sleep_level >= 2) { Sleep ( 100 ); } else if ( winplaymidi_sleep_level > 0 ) { Sleep ( 1 ); } } #endif /* * interface__loader(); */ ControlMode *interface_P_loader(void) { return &ctl; }