1 /* 2 wildmidi_lib.h 3 4 Midi Wavetable Processing library 5 6 Copyright (C) Chris Ison 2001-2011 7 Copyright (C) Bret Curtis 2013-2014 8 9 This file is part of WildMIDI. 10 11 WildMIDI is free software: you can redistribute and/or modify the player 12 under the terms of the GNU General Public License and you can redistribute 13 and/or modify the library under the terms of the GNU Lesser General Public 14 License as published by the Free Software Foundation, either version 3 of 15 the licenses, or(at your option) any later version. 16 17 WildMIDI is distributed in the hope that it will be useful, but WITHOUT 18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License and 20 the GNU Lesser General Public License for more details. 21 22 You should have received a copy of the GNU General Public License and the 23 GNU Lesser General Public License along with WildMIDI. If not, see 24 <http://www.gnu.org/licenses/>. 25 */ 26 27 #ifndef WILDMIDI_LIB_H 28 #define WILDMIDI_LIB_H 29 30 #include "../../../source/zmusic/fileio.h" 31 #include <stdarg.h> 32 33 namespace WildMidi 34 { 35 enum EMixerOptions 36 { 37 WM_MO_LOG_VOLUME = 0x0001, 38 WM_MO_ENHANCED_RESAMPLING = 0x0002, 39 WM_MO_REVERB = 0x0004, 40 WM_MO_WHOLETEMPO = 0x8000, 41 WM_MO_ROUNDTEMPO = 0x2000, 42 43 WM_GS_VERSION = 0x0001, 44 }; 45 46 47 class SoundFontReaderInterface; 48 49 struct _WM_Info { 50 char *copyright; 51 unsigned long int current_sample; 52 unsigned long int approx_total_samples; 53 unsigned short int mixer_options; 54 unsigned long int total_midi_time; 55 }; 56 57 typedef void midi; 58 59 struct Instruments 60 { 61 MusicIO::SoundFontReaderInterface *sfreader; 62 63 struct _patch *patch[128] = {}; 64 float reverb_room_width = 16.875f; 65 float reverb_room_length = 22.5f; 66 67 float reverb_listen_posx = 8.4375f; 68 float reverb_listen_posy = 16.875f; 69 70 int fix_release = 0; 71 int auto_amp = 0; 72 int auto_amp_with_amp = 0; 73 74 unsigned short int _WM_SampleRate; // WildMidi makes the sample rate a property of the patches, not the renderer. Meaning that the instruments need to be reloaded when it changes... :? 75 InstrumentsInstruments76 Instruments(MusicIO::SoundFontReaderInterface *reader, int samplerate) 77 { 78 sfreader = reader; 79 _WM_SampleRate = samplerate; 80 } 81 ~Instruments(); 82 83 int LoadConfig(const char *config_file); 84 int load_sample(struct _patch *sample_patch); 85 struct _patch *get_patch_data(unsigned short patchid); 86 void load_patch(struct _mdi *mdi, unsigned short patchid); GetSampleRateInstruments87 int GetSampleRate() { return _WM_SampleRate; } 88 struct _sample * load_gus_pat(const char *filename); 89 90 private: 91 void FreePatches(void); 92 }; 93 94 const char * WildMidi_GetString (unsigned short int info); 95 96 97 98 class Renderer 99 { 100 Instruments *instruments; 101 102 signed int WM_MasterVolume = 948; 103 unsigned int WM_MixerOptions = 0; 104 105 public: 106 Renderer(Instruments *instr, unsigned mixOpt = 0); 107 ~Renderer(); 108 109 void ShortEvent(int status, int parm1, int parm2); 110 void LongEvent(const unsigned char *data, int len); 111 void ComputeOutput(float *buffer, int len); 112 void LoadInstrument(int bank, int percussion, int instr); 113 int GetVoiceCount(); 114 int SetOption(int opt, int set); 115 116 void SetMasterVolume(unsigned char master_volume); 117 midi * NewMidi(); 118 119 private: 120 void *handle; 121 122 void AdjustNoteVolumes(struct _mdi *mdi, unsigned char ch, struct _note *nte); 123 void AdjustChannelVolumes(struct _mdi *mdi, unsigned char ch); 124 void do_note_on(struct _mdi *mdi, struct _event_data *data); 125 void do_aftertouch(struct _mdi *mdi, struct _event_data *data); 126 void do_control_channel_volume(struct _mdi *mdi, struct _event_data *data); 127 void do_control_channel_balance(struct _mdi *mdi, struct _event_data *data); 128 void do_control_channel_pan(struct _mdi *mdi, struct _event_data *data); 129 void do_control_channel_expression(struct _mdi *mdi, struct _event_data *data); 130 void do_control_channel_controllers_off(struct _mdi *mdi, struct _event_data *data); 131 void do_pitch(struct _mdi *mdi, struct _event_data *data); 132 void do_patch(struct _mdi *mdi, struct _event_data *data); 133 void do_channel_pressure(struct _mdi *mdi, struct _event_data *data); 134 void do_sysex_roland_drum_track(struct _mdi *mdi, struct _event_data *data); 135 void do_sysex_gm_reset(struct _mdi *mdi, struct _event_data *data); 136 void do_sysex_roland_reset(struct _mdi *mdi, struct _event_data *data); 137 void do_sysex_yamaha_reset(struct _mdi *mdi, struct _event_data *data); 138 struct _mdi *Init_MDI(); 139 unsigned long int get_inc(struct _mdi *mdi, struct _note *nte); 140 }; 141 142 extern void (*wm_error_func)(const char *wmfmt, va_list args); 143 } 144 145 #endif /* WILDMIDI_LIB_H */ 146 147