midi.h
上传用户:tjmskj2
上传日期:2020-08-17
资源大小:577k
文件大小:6k
源码类别:

midi

开发平台:

C/C++

  1. /* FluidSynth - A Software Synthesizer
  2.  *
  3.  * Copyright (C) 2003  Peter Hanappe and others.
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public License
  7.  * as published by the Free Software Foundation; either version 2 of
  8.  * the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *  
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18.  * 02111-1307, USA
  19.  */
  20. #ifndef _FLUIDSYNTH_MIDI_H
  21. #define _FLUIDSYNTH_MIDI_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26.  * @file midi.h
  27.  * @brief Functions for MIDI events, drivers and MIDI file playback.
  28.  */
  29. FLUIDSYNTH_API fluid_midi_event_t* new_fluid_midi_event(void);
  30. FLUIDSYNTH_API int delete_fluid_midi_event(fluid_midi_event_t* event);
  31. FLUIDSYNTH_API int fluid_midi_event_set_type(fluid_midi_event_t* evt, int type);
  32. FLUIDSYNTH_API int fluid_midi_event_get_type(fluid_midi_event_t* evt);
  33. FLUIDSYNTH_API int fluid_midi_event_set_channel(fluid_midi_event_t* evt, int chan);
  34. FLUIDSYNTH_API int fluid_midi_event_get_channel(fluid_midi_event_t* evt);
  35. FLUIDSYNTH_API int fluid_midi_event_get_key(fluid_midi_event_t* evt);
  36. FLUIDSYNTH_API int fluid_midi_event_set_key(fluid_midi_event_t* evt, int key);
  37. FLUIDSYNTH_API int fluid_midi_event_get_velocity(fluid_midi_event_t* evt);
  38. FLUIDSYNTH_API int fluid_midi_event_set_velocity(fluid_midi_event_t* evt, int vel);
  39. FLUIDSYNTH_API int fluid_midi_event_get_control(fluid_midi_event_t* evt);
  40. FLUIDSYNTH_API int fluid_midi_event_set_control(fluid_midi_event_t* evt, int ctrl);
  41. FLUIDSYNTH_API int fluid_midi_event_get_value(fluid_midi_event_t* evt);
  42. FLUIDSYNTH_API int fluid_midi_event_set_value(fluid_midi_event_t* evt, int val);
  43. FLUIDSYNTH_API int fluid_midi_event_get_program(fluid_midi_event_t* evt);
  44. FLUIDSYNTH_API int fluid_midi_event_set_program(fluid_midi_event_t* evt, int val);
  45. FLUIDSYNTH_API int fluid_midi_event_get_pitch(fluid_midi_event_t* evt);
  46. FLUIDSYNTH_API int fluid_midi_event_set_pitch(fluid_midi_event_t* evt, int val);
  47. FLUIDSYNTH_API int fluid_midi_event_set_sysex(fluid_midi_event_t* evt, void *data,
  48.                                               int size, int dynamic);
  49. /**
  50.  * MIDI router rule type.
  51.  * @since 1.1.0
  52.  */
  53. typedef enum
  54. {
  55.   FLUID_MIDI_ROUTER_RULE_NOTE,                  /**< MIDI note rule */
  56.   FLUID_MIDI_ROUTER_RULE_CC,                    /**< MIDI controller rule */
  57.   FLUID_MIDI_ROUTER_RULE_PROG_CHANGE,           /**< MIDI program change rule */
  58.   FLUID_MIDI_ROUTER_RULE_PITCH_BEND,            /**< MIDI pitch bend rule */
  59.   FLUID_MIDI_ROUTER_RULE_CHANNEL_PRESSURE,      /**< MIDI channel pressure rule */
  60.   FLUID_MIDI_ROUTER_RULE_KEY_PRESSURE,          /**< MIDI key pressure rule */
  61.   FLUID_MIDI_ROUTER_RULE_COUNT                  /**< Total count of rule types */
  62. } fluid_midi_router_rule_type;
  63. /**
  64.  * Generic callback function for MIDI events.
  65.  * @param data User defined data pointer
  66.  * @param event The MIDI event
  67.  * @return Should return #FLUID_OK on success, #FLUID_FAILED otherwise
  68.  *
  69.  * Will be used between
  70.  * - MIDI driver and MIDI router
  71.  * - MIDI router and synth
  72.  * to communicate events.
  73.  * In the not-so-far future...
  74.  */
  75. typedef int (*handle_midi_event_func_t)(void* data, fluid_midi_event_t* event);
  76. FLUIDSYNTH_API fluid_midi_router_t* new_fluid_midi_router(fluid_settings_t* settings,
  77.        handle_midi_event_func_t handler, 
  78.        void* event_handler_data); 
  79. FLUIDSYNTH_API int delete_fluid_midi_router(fluid_midi_router_t* handler); 
  80. FLUIDSYNTH_API int fluid_midi_router_set_default_rules (fluid_midi_router_t *router);
  81. FLUIDSYNTH_API int fluid_midi_router_clear_rules (fluid_midi_router_t *router);
  82. FLUIDSYNTH_API int fluid_midi_router_add_rule (fluid_midi_router_t *router,
  83.                                                fluid_midi_router_rule_t *rule, int type);
  84. FLUIDSYNTH_API fluid_midi_router_rule_t *new_fluid_midi_router_rule (void);
  85. FLUIDSYNTH_API void delete_fluid_midi_router_rule (fluid_midi_router_rule_t *rule);
  86. FLUIDSYNTH_API void fluid_midi_router_rule_set_chan (fluid_midi_router_rule_t *rule,
  87.                                                      int min, int max, float mul, int add);
  88. FLUIDSYNTH_API void fluid_midi_router_rule_set_param1 (fluid_midi_router_rule_t *rule,
  89.                                                        int min, int max, float mul, int add);
  90. FLUIDSYNTH_API void fluid_midi_router_rule_set_param2 (fluid_midi_router_rule_t *rule,
  91.                                                        int min, int max, float mul, int add);
  92. FLUIDSYNTH_API int fluid_midi_router_handle_midi_event(void* data, fluid_midi_event_t* event);
  93. FLUIDSYNTH_API int fluid_midi_dump_prerouter(void* data, fluid_midi_event_t* event); 
  94. FLUIDSYNTH_API int fluid_midi_dump_postrouter(void* data, fluid_midi_event_t* event); 
  95. FLUIDSYNTH_API 
  96. fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, 
  97.  handle_midi_event_func_t handler, 
  98.  void* event_handler_data);
  99. FLUIDSYNTH_API void delete_fluid_midi_driver(fluid_midi_driver_t* driver);
  100. /**
  101.  * MIDI player status enum.
  102.  * @since 1.1.0
  103.  */
  104. enum fluid_player_status
  105. {
  106.   FLUID_PLAYER_READY,           /**< Player is ready */
  107.   FLUID_PLAYER_PLAYING,         /**< Player is currently playing */
  108.   FLUID_PLAYER_DONE             /**< Player is finished playing */
  109. };
  110. FLUIDSYNTH_API fluid_player_t* new_fluid_player(fluid_synth_t* synth);
  111. FLUIDSYNTH_API int delete_fluid_player(fluid_player_t* player);
  112. FLUIDSYNTH_API int fluid_player_add(fluid_player_t* player, const char *midifile);
  113. FLUIDSYNTH_API int fluid_player_play(fluid_player_t* player);
  114. FLUIDSYNTH_API int fluid_player_stop(fluid_player_t* player);
  115. FLUIDSYNTH_API int fluid_player_join(fluid_player_t* player);
  116. FLUIDSYNTH_API int fluid_player_set_loop(fluid_player_t* player, int loop);
  117. FLUIDSYNTH_API int fluid_player_set_midi_tempo(fluid_player_t* player, int tempo);
  118. FLUIDSYNTH_API int fluid_player_set_bpm(fluid_player_t* player, int bpm);
  119. FLUIDSYNTH_API int fluid_player_get_status(fluid_player_t* player);
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif /* _FLUIDSYNTH_MIDI_H */