main.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #ifndef STRICT
  2. #define STRICT
  3. #endif
  4. #include "../Agave/Language/api_language.h"
  5. #include <windows.h>
  6. #include <malloc.h>
  7. #ifndef NOVTABLE
  8. #define NOVTABLE _declspec(novtable)
  9. #endif
  10. #include <mmsystem.h>
  11. #include "core_api.h"
  12. #include "../pfc/string_unicode.h"
  13. #include "locale.h"
  14. #define VER L"3.57"
  15. #include "utils.h"
  16. //#define USE_LOG
  17. #ifdef USE_LOG
  18. void log_write(char*);
  19. void log_start();
  20. void log_quit();
  21. #else
  22. #define log_write(X)
  23. #define log_start()
  24. #define log_quit()
  25. #endif
  26. class CStream;
  27. struct CTempoMap;
  28. struct CSysexMap;
  29. class player_base;
  30. class NOVTABLE MIDI_device
  31. {
  32. friend class MIDI_driver;
  33. private:
  34. MIDI_device * next;
  35. MIDI_driver * driver;
  36. string_w dev_name,dev_info;
  37. protected:
  38. void set_name(const wchar_t * src) {dev_name=src;}
  39. void set_info(const wchar_t * src) {dev_info=src;}
  40. public:
  41. //override me
  42. virtual player_base * create()=0;
  43. virtual GUID get_guid()=0;
  44. virtual ~MIDI_device() {};
  45. virtual bool is_default() {return 0;}
  46. virtual bool has_output() {return 0;}
  47. virtual bool has_dls() {return 0;}
  48. virtual bool has_freq() {return 0;}
  49. virtual bool volctrl_happy() {return 0;}
  50. const wchar_t * get_name() {return dev_name;}
  51. const wchar_t * get_info() {return dev_info;}
  52. MIDI_driver * get_driver() {return driver;}
  53. };
  54. class NOVTABLE MIDI_driver//ONLY for static objects !!!!!
  55. {
  56. private:
  57. static MIDI_driver * driver_list;
  58. MIDI_driver * next;
  59. MIDI_device * device_list;
  60. bool inited;
  61. void init() {if (!inited) {do_init();inited=1;};}
  62. void deinit() {if (inited) {do_deinit();reset_devices();inited=0;};}
  63. protected:
  64. MIDI_driver();
  65. ~MIDI_driver();
  66. void reset_devices();
  67. void add_device(MIDI_device * dev);//call this to add new device
  68. //override me
  69. virtual void do_init() {};
  70. virtual void do_deinit() {}
  71. public:
  72. static MIDI_driver * driver_enumerate(int n);
  73. static int driver_count();
  74. MIDI_device * device_enumerate(int n);
  75. int device_count();
  76. static MIDI_device * find_device(GUID guid_driver,GUID guid_device);
  77. static MIDI_driver * find_driver(GUID guid_driver);
  78. static MIDI_device * find_device_default();
  79. static void shutdown();
  80. //override me
  81. virtual const wchar_t * get_name()=0;
  82. virtual GUID get_guid()=0;
  83. virtual bool is_default() {return 0;}
  84. };
  85. #include "midifile.h"
  86. class NOVTABLE player_base
  87. {
  88. public:
  89. virtual ~player_base() {}
  90. virtual int gettime()=0;
  91. virtual int settime(int)=0;
  92. virtual void pause()=0;
  93. virtual void unpause()=0;
  94. virtual int setvol(int) {return 0;};
  95. virtual int setpan(int) {return 0;};
  96. };
  97. class MIDI_core
  98. {
  99. public:
  100. static int Init();
  101. static int UsesOutput() {return use_out;}
  102. static int OpenFile(MIDI_file * file);
  103. static void Close();
  104. static int GetSamples(void *sample_buffer, int bytes, char *killswitch);
  105. static void GetPCM(int * srate,int * nch,int * bps) {*srate=format_srate;*nch=format_nch;*bps=format_bps;}
  106. static int SetPosition(int);
  107. static void Pause(int pause);
  108. static int GetPosition(void);
  109. static int GetLength(void);
  110. static void Eof();
  111. static int SetVolume(int volume);
  112. static int SetPan(int pan);
  113. //setvolune/setpan safe to call at any moment
  114. static int player_getVol() {return volume;}
  115. static int player_getPan() {return pan;}
  116. static inline void player_setSource(CStream *s) {data_src=s;}
  117. static void MM_error(DWORD code);
  118. static inline MIDI_file * getFile() {return theFile;}
  119. static inline MIDI_device * getDevice() {return device;}
  120. static inline bool HavePCM() {return !!data_src;}
  121. static inline bool HavePlayer() {return !!plr;}
  122. static int IsOurFile(const char *fn);
  123. static void GlobalInit();
  124. static void GlobalQuit();
  125. static int Config(HWND wnd);
  126. static void WriteConfig();
  127. static int FileTypes_GetNum();
  128. static const char * FileTypes_GetExtension(int);
  129. static char * FileTypes_GetDescription(int);
  130. private:
  131. static BOOL CALLBACK KarProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
  132. static void update_vol();
  133. static bool use_out,use_smp;
  134. static MIDI_file* theFile;
  135. static CStream* data_src;
  136. static player_base* plr;
  137. static int format_srate,format_nch,format_bps;
  138. static int volume,pan;
  139. static bool eof;
  140. static UINT volmod;
  141. static UINT mix_dev,mix_idx;
  142. static HWND kwnd;
  143. static KAR_ENTRY *kmap;
  144. static UINT kmap_size,kmap_ptr;
  145. static char * kmap_data;
  146. static critical_section sync;
  147. static MIDI_device * device;
  148. };
  149. namespace MIDI_callback //per-winamp implementations
  150. {
  151. HWND GetMainWindow();
  152. HINSTANCE GetInstance();
  153. void NotifyEOF();
  154. void Error(const char *);
  155. void Idle(int ms=0);
  156. };
  157. //#pragma warning(disable:4800)
  158. void get_temp_file(char* fn);
  159. extern cfg_int cfg_hardware_reset;
  160. extern cfg_int cfg_smp,cfg_reverb,cfg_chorus,cfg_nosysex;
  161. extern cfg_int cfg_sampout,cfg_dm_imm;
  162. extern cfg_int cfg_loop_type,cfg_loop_count,cfg_loop_infinite;
  163. extern cfg_int cfg_wavein_dev,cfg_wavein_sr,cfg_wavein_ch,cfg_wavein_bps,cfg_wavein_src;
  164. extern cfg_int cfg_ctrl_x,cfg_ctrl_y;
  165. extern cfg_int cfg_ext_mask;
  166. extern cfg_string cfg_extra_exts;
  167. extern cfg_int cfg_volmode;
  168. extern cfg_int cfg_recover_tracks;
  169. extern cfg_int cfg_quick_seek;
  170. extern cfg_int cfg_rmi_def;
  171. extern cfg_int cfg_logvol;
  172. extern cfg_struct_t<GUID> cfg_driver,cfg_device;
  173. extern cfg_int cfg_playback_mode;
  174. extern cfg_int cfg_eof_delay;
  175. extern cfg_int cfg_bugged;
  176. extern cfg_int cfg_freq;
  177. extern cfg_int cfg_cur_tab;
  178. enum{BUGGED_BLAH=0x10};
  179. extern sysex_table cfg_sysex_table;
  180. void ReleaseObject(IUnknown* o);
  181. #include "in2.h"
  182. extern In_Module mod;