1 /* 2 TiMidity++ -- MIDI to WAVE converter and player 3 Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp> 4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 20 21 rtsyn.h 22 Copyright (c) 2003 Keishi Suenaga <s_keishi@mutt.freemail.ne.jp> 23 24 I referenced following sources. 25 alsaseq_c.c - ALSA sequencer server interface 26 Copyright (c) 2000 Takashi Iwai <tiwai@suse.de> 27 readmidi.c 28 */ 29 #include "interface.h" 30 31 #include <stdio.h> 32 33 #include <stdarg.h> 34 #ifdef HAVE_UNISTD_H 35 #include <unistd.h> 36 #endif 37 #ifdef HAVE_SYS_TYPES_H 38 #include <sys/types.h> 39 #endif /* HAVE_SYS_TYPES_H */ 40 #ifdef TIME_WITH_SYS_TIME 41 #include <sys/time.h> 42 #endif 43 #ifndef NO_STRING_H 44 #include <string.h> 45 #else 46 #include <strings.h> 47 #endif 48 #include <math.h> 49 #include <signal.h> 50 51 #include "server_defs.h" 52 53 #ifdef __W32__ 54 #include <windows.h> 55 #include <mmsystem.h> 56 #endif 57 58 59 #ifndef __W32__ 60 #ifdef HAVE_STDLIB_H 61 #include <stdlib.h> 62 #endif 63 #endif 64 65 66 67 #include "timidity.h" 68 #include "common.h" 69 #include "controls.h" 70 #include "instrum.h" 71 #include "playmidi.h" 72 #include "readmidi.h" 73 #include "recache.h" 74 #include "output.h" 75 #include "aq.h" 76 #include "timer.h" 77 78 79 #define USE_PORTMIDI 1 80 81 /******************************************************************************/ 82 /* */ 83 /* Interface independent functions (see rtsyn_common.c) */ 84 /* */ 85 /******************************************************************************/ 86 87 /* peek playmidi.c */ 88 extern int32 current_sample; 89 90 /* peek timidity.c */ 91 extern VOLATILE int intr; 92 93 /* How often data pass to the buffer */ 94 #define TICKTIME_HZ 200 95 96 /* latency (sec) > 1.0 / TICKTIME_HZ * 4.0 */ 97 #define RTSYN_LATENCY 0.20 98 99 100 extern double rtsyn_latency; /* = RTYSN_LATENCY */ 101 extern int rtsyn_system_mode; 102 103 extern int32 rtsyn_start_sample; 104 extern int rtsyn_sample_time_mode; //bool 1 ture 0 false 105 106 /* reset synth */ 107 void rtsyn_gm_reset(void); 108 void rtsyn_gs_reset(void); 109 void rtsyn_xg_reset(void); 110 void rtsyn_normal_reset(void); 111 112 /* mode change * 113 * only in nomalmode program can accept reset(sysex) data */ 114 void rtsyn_gm_modeset(void); 115 void rtsyn_gs_modeset(void); 116 void rtsyn_xg_modeset(void); 117 void rtsyn_normal_modeset(void); 118 119 void rtsyn_init(void); 120 void rtsyn_close(void); 121 double rtsyn_set_latency(double latency); 122 void rtsyn_play_event(MidiEvent *ev); 123 void rtsyn_play_event_time(MidiEvent *ev, double event_time); 124 void rtsyn_tmr_reset(void); 125 void rtsyn_server_reset(void); 126 void rtsyn_reset(void); 127 void rtsyn_stop_playing(void); 128 int rtsyn_play_one_data (int port, int32 dwParam1, double event_time); 129 void rtsyn_play_one_sysex (char *sysexbuffer, int exlen, double event_time ); 130 void rtsyn_play_calculate(void); 131 132 133 134 /******************************************************************************/ 135 /* */ 136 /* Interface dependent functions (see rtsyn_winmm.c rtsyn_portmidi.c) */ 137 /* */ 138 /******************************************************************************/ 139 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_W32G_SYN) 140 141 #define MAX_PORT 4 142 extern int rtsyn_portnumber; 143 extern unsigned int portID[MAX_PORT]; 144 extern char rtsyn_portlist[32][80]; 145 extern int rtsyn_nportlist; 146 147 void rtsyn_get_port_list(void); 148 int rtsyn_synth_start(void); 149 void rtsyn_synth_stop(void); 150 int rtsyn_play_some_data (void); 151 void rtsyn_midiports_close(void); 152 153 #if defined(IA_WINSYN) || defined(IA_W32G_SYN) 154 int rtsyn_buf_check(void); 155 #endif 156 157 #endif /* IA_WINSYN IA_PORTMIDISYN IA_W32G_SYN */ 158 159 #ifdef IA_NPSYN 160 #define RTSYN_NP_DATA 1 161 #define RTSYN_NP_LONGDATA 2 162 163 typedef struct rtsyn_np_evbuf_t{ 164 uint32 wMsg; 165 union { 166 uint32 port; 167 uint32 exlen; 168 }; 169 union { 170 uint32 dwParam1; 171 }; 172 uint32 dwParam2; 173 } RtsynNpEvBuf; 174 175 void rtsyn_np_set_pipe_name(char*); 176 int rtsyn_np_synth_start(void); 177 void rtsyn_np_synth_stop(void); 178 int rtsyn_np_play_some_data (void); 179 void rtsyn_np_pipe_close(); 180 #endif 181 182 #ifdef USE_WINSYN_TIMER_I 183 184 #if defined(__W32__) 185 typedef CRITICAL_SECTION rtsyn_mutex_t; 186 #define rtsyn_mutex_init(_m) InitializeCriticalSection(&_m) 187 #define rtsyn_mutex_destroy(_m) DeleteCriticalSection(&_m) 188 #define rtsyn_mutex_lock(_m) EnterCriticalSection(&_m) 189 #define rtsyn_mutex_unlock(_m) LeaveCriticalSection(&_m) 190 191 #else 192 typedef pthread_mutex_t rtsyn_mutex_t; 193 #define rtsyn_mutex_init(_m) pthread_mutex_init(&(_m), NULL) 194 #define rtsyn_mutex_destroy(_m) pthread_mutex_destroy(&(_m)) 195 #define rtsyn_mutex_lock(_m) pthread_mutex_lock(&(_m)) 196 #define rtsyn_mutex_unlock(_m) pthread_mutex_unlock(&(_m)) 197 #endif 198 199 #endif 200