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

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 _FLUID_CHAN_H
  21. #define _FLUID_CHAN_H
  22. #include "fluidsynth_priv.h"
  23. #include "fluid_midi.h"
  24. #include "fluid_tuning.h"
  25. /*
  26.  * fluid_channel_t
  27.  *
  28.  * Mutual exclusion notes:
  29.  *
  30.  * Set once on init:
  31.  * channum
  32.  * synth
  33.  *
  34.  * Synthesis thread context only:
  35.  * preset
  36.  * tuning
  37.  * nrpn_select
  38.  * nrpn_active
  39.  * gen[]
  40.  * gen_abs[]
  41.  *
  42.  * Uses atomic operations:
  43.  * sfont_bank_prog
  44.  * shadow_preset
  45.  * key_pressure
  46.  * channel_pressure
  47.  * pitch_bend
  48.  * pitch_wheel_sensitivity
  49.  * cc[]
  50.  * interp_method
  51.  */
  52. struct _fluid_channel_t
  53. {
  54.   fluid_mutex_t mutex;                  /* Lock for thread sensitive parameters */
  55.   fluid_synth_t* synth;                 /**< Parent synthesizer instance */
  56.   int channum;                          /**< MIDI channel number */
  57.   int sfont_bank_prog;                  /**< SoundFont ID (bit 21-31), bank (bit 7-20), program (bit 0-6) */
  58.   fluid_preset_t* preset;               /**< Selected preset */
  59.   fluid_preset_t* shadow_preset;        /**< Most recently assigned preset */
  60.   int key_pressure;                     /**< MIDI key pressure */
  61.   int channel_pressure;                 /**< MIDI channel pressure */
  62.   int pitch_bend;                       /**< Current pitch bend value */
  63.   int pitch_wheel_sensitivity;          /**< Current pitch wheel sensitivity */
  64.   int cc[128];                          /**< MIDI controller values */
  65.   int interp_method;                    /**< Interpolation method (enum fluid_interp) */
  66.   fluid_tuning_t* tuning;               /**< Micro tuning */
  67.   int tuning_bank;                      /**< Current tuning bank number */
  68.   int tuning_prog;                      /**< Current tuning program number */
  69.   /* NRPN system */
  70.   int nrpn_select;      /* Generator ID of SoundFont NRPN message */
  71.   int nrpn_active;      /* 1 if data entry CCs are for NRPN, 0 if RPN */
  72.   /* The values of the generators, set by NRPN messages, or by
  73.    * fluid_synth_set_gen(), are cached in the channel so they can be
  74.    * applied to future notes. They are copied to a voice's generators
  75.    * in fluid_voice_init(), which calls fluid_gen_init().  */
  76.   fluid_real_t gen[GEN_LAST];
  77.   /* By default, the NRPN values are relative to the values of the
  78.    * generators set in the SoundFont. For example, if the NRPN
  79.    * specifies an attack of 100 msec then 100 msec will be added to the
  80.    * combined attack time of the sound font and the modulators.
  81.    *
  82.    * However, it is useful to be able to specify the generator value
  83.    * absolutely, completely ignoring the generators of the SoundFont
  84.    * and the values of modulators. The gen_abs field, is a boolean
  85.    * flag indicating whether the NRPN value is absolute or not.
  86.    */
  87.   char gen_abs[GEN_LAST];
  88. };
  89. fluid_channel_t* new_fluid_channel(fluid_synth_t* synth, int num);
  90. void fluid_channel_init_ctrl(fluid_channel_t* chan, int is_all_ctrl_off);
  91. int delete_fluid_channel(fluid_channel_t* chan);
  92. void fluid_channel_reset(fluid_channel_t* chan);
  93. int fluid_channel_set_preset(fluid_channel_t* chan, fluid_preset_t* preset);
  94. fluid_preset_t* fluid_channel_get_preset(fluid_channel_t* chan);
  95. void fluid_channel_set_sfont_bank_prog(fluid_channel_t* chan, int sfont,
  96.                                        int bank, int prog);
  97. void fluid_channel_set_bank_lsb(fluid_channel_t* chan, int banklsb);
  98. void fluid_channel_set_bank_msb(fluid_channel_t* chan, int bankmsb);
  99. void fluid_channel_get_sfont_bank_prog(fluid_channel_t* chan, int *sfont,
  100.                                        int *bank, int *prog);
  101. int fluid_channel_get_num(fluid_channel_t* chan);
  102. void fluid_channel_set_interp_method(fluid_channel_t* chan, int new_method);
  103. int fluid_channel_get_interp_method(fluid_channel_t* chan);
  104. #define fluid_channel_get_preset(chan)          ((chan)->preset)
  105. #define fluid_channel_set_cc(chan, num, val) 
  106.   fluid_atomic_int_set (&(chan)->cc[num], val)
  107. #define fluid_channel_get_cc(chan, num)   fluid_atomic_int_get (&(chan)->cc[num])
  108. #define fluid_channel_get_key_pressure(chan) 
  109.   fluid_atomic_int_get (&(chan)->key_pressure)
  110. #define fluid_channel_set_key_pressure(chan, val) 
  111.   fluid_atomic_int_set (&(chan)->key_pressure, val)
  112. #define fluid_channel_get_channel_pressure(chan) 
  113.   fluid_atomic_int_get (&(chan)->channel_pressure)
  114. #define fluid_channel_set_channel_pressure(chan, val) 
  115.   fluid_atomic_int_set (&(chan)->channel_pressure, val)
  116. #define fluid_channel_get_pitch_bend(chan) 
  117.   fluid_atomic_int_get (&(chan)->pitch_bend)
  118. #define fluid_channel_set_pitch_bend(chan, val) 
  119.   fluid_atomic_int_set (&(chan)->pitch_bend, val)
  120. #define fluid_channel_get_pitch_wheel_sensitivity(chan) 
  121.   fluid_atomic_int_get (&(chan)->pitch_wheel_sensitivity)
  122. #define fluid_channel_set_pitch_wheel_sensitivity(chan, val) 
  123.   fluid_atomic_int_set (&(chan)->pitch_wheel_sensitivity, val)
  124. #define fluid_channel_get_num(chan)             ((chan)->channum)
  125. #define fluid_channel_set_interp_method(chan, new_method) 
  126.   fluid_atomic_int_set (&(chan)->interp_method, new_method)
  127. #define fluid_channel_get_interp_method(chan) 
  128.   fluid_atomic_int_get (&(chan)->interp_method);
  129. #define fluid_channel_set_tuning(_c, _t)        { (_c)->tuning = _t; }
  130. #define fluid_channel_has_tuning(_c)            ((_c)->tuning != NULL)
  131. #define fluid_channel_get_tuning(_c)            ((_c)->tuning)
  132. #define fluid_channel_get_tuning_bank(chan)     
  133.   fluid_atomic_int_get (&(chan)->tuning_bank)
  134. #define fluid_channel_set_tuning_bank(chan, bank) 
  135.   fluid_atomic_int_set (&(chan)->tuning_bank, bank)
  136. #define fluid_channel_get_tuning_prog(chan)     
  137.   fluid_atomic_int_get (&(chan)->tuning_prog)
  138. #define fluid_channel_set_tuning_prog(chan, prog) 
  139.   fluid_atomic_int_set (&(chan)->tuning_prog, prog)
  140. #define fluid_channel_sustained(_c)             ((_c)->cc[SUSTAIN_SWITCH] >= 64)
  141. #define fluid_channel_set_gen(_c, _n, _v, _a)   { (_c)->gen[_n] = _v; (_c)->gen_abs[_n] = _a; }
  142. #define fluid_channel_get_gen(_c, _n)           ((_c)->gen[_n])
  143. #define fluid_channel_get_gen_abs(_c, _n)       ((_c)->gen_abs[_n])
  144. #define fluid_channel_get_min_note_length_ticks(chan) 
  145.   ((chan)->synth->min_note_length_ticks)
  146. #endif /* _FLUID_CHAN_H */