<commit_before>/* FluidSynth - A Software Synthesizer
 *
 * Copyright (C) 2003  <NAME> and others.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307, USA
 */


#ifndef _FLUID_SYNTH_H
#define _FLUID_SYNTH_H


/***************************************************************
 *
 *                         INCLUDES
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "fluidsynth_priv.h"
#include "fluid_event_queue.h"
#include "fluid_list.h"
#include "fluid_rev.h"
#include "fluid_voice.h"
#include "fluid_chorus.h"
#include "fluid_ladspa.h"
#include "fluid_midi_router.h"
#include "fluid_sys.h"

/***************************************************************
 *
 *                         DEFINES
 */
#define FLUID_NUM_PROGRAMS      128
#define DRUM_INST_BANK		128

#if defined(WITH_FLOAT)
#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_FLOAT
#else
#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_DOUBLE
#endif


/***************************************************************
 *
 *                         ENUM
 */
enum fluid_loop {
  FLUID_UNLOOPED = 0,
  FLUID_LOOP_DURING_RELEASE = 1,
  FLUID_NOTUSED = 2,
  FLUID_LOOP_UNTIL_RELEASE = 3
};

enum fluid_synth_status
{
  FLUID_SYNTH_CLEAN,
  FLUID_SYNTH_PLAYING,
  FLUID_SYNTH_QUIET,
  FLUID_SYNTH_STOPPED
};

#define SYNTH_REVERB_CHANNEL 0
#define SYNTH_CHORUS_CHANNEL 1

/**
 * Defines the current MIDI mode.
 */
typedef enum
{
  FLUID_SYNTH_MIDI_MODE_NORMAL,         /**< Normal MIDI mode (percussion channel not special) */
  FLUID_SYNTH_MIDI_MODE_GM,             /**< GM MIDI mode, no note-offs on percussion channel (except for long guiro and whistle) */
  FLUID_SYNTH_MIDI_MODE_GS              /**< GS MIDI mode, identical to #FLUID_SYNTH_MIDI_MODE_GM at the moment */
} fluid_synth_midi_mode_t;

/**
 * Structure used for sfont_info field in #fluid_synth_t for each loaded
 * SoundFont with the SoundFont instance and additional fields.
 */
typedef struct _fluid_sfont_info_t {
  fluid_sfont_t *sfont; /**< Loaded SoundFont */
  fluid_synth_t *synth; /**< Parent synth */
  int refcount;         /**< SoundFont reference count (0 if no presets referencing it) */
  int bankofs;          /**< Bank offset */
} fluid_sfont_info_t;

/*
 * fluid_synth_t
 *
 * Mutual exclusion notes:
 *
 * Set only once on init:
 * ----------------------
 * verbose
 * dump
 * sample_rate (will be runtime change-able in the future)
 * midi_channels
 * audio_channels
 * audio_groups
 * effects_channels
 * start
 * channel[] (Contents change)
 * nvoice
 * voice[] (Contents change)
 * nbuf
 * left_buf[], right_buf[] (Contents change)
 * fx_left_buf[], fx_right_buf[] (Contents change)
 * LADSPA_FxUnit (Contents change)
 * cores
 * core_threads[]
 *
 * Single thread use only (modify only prior to synthesis):
 * loaders<>
 * midi_router
 *
 * Mutex protected:
 * settings{} (has its own mutex)
 * sfont_info<>
 * tuning
 * sfont_id
 * gain
 * reverb_roomsize, reverb_damping, reverb_width, reverb_level
 * chorus_nr, chorus_level, chorus_speed, chorus_depth, chorus_type
 *
 * Atomic operations:
 * ----------------------
 * with_reverb
 * with_chorus
 * state
 * midi_mode
 * midi_mode_lock
 * cpu_load
 * noteid
 * storeid
 * outbuf
 * sample_timers
 *
 * Only synth thread changes
 * -------------------------
 * ticks
 * reverb{}
 * chorus{}
 * cur
 * dither_index
 * polyphony (atomic int get for non-synth threads)
 * st_gain
 */

struct _fluid_synth_t
{
  fluid_thread_id_t synth_thread_id; /**< ID of the synthesis thread or FLUID_THREAD_ID_NULL if not yet set */
  fluid_private_t thread_queues;     /**< Thread private data for event queues for each non-synthesis thread queuing events */
  fluid_event_queue_t *queues[FLUID_MAX_EVENT_QUEUES];   /**< Thread event queues (NULL for unused elements) */

  fluid_rec_mutex_t mutex;           /**< Lock for multi-thread sensitive variables (not used by synthesis process) */
  fluid_list_t *queue_pool;          /**< List of event queues whose threads have been destroyed and which can be re-used */
  fluid_event_queue_t *return_queue; /**< Event queue for events from synthesis thread to non-synthesis threads (memory frees, etc) */
  fluid_timer_t *return_queue_timer; /**< Timer thread to process return event queue */

  fluid_settings_t* settings;        /**< the synthesizer settings */
  int device_id;                     /**< Device ID used for SYSEX messages */
  int polyphony;                     /**< maximum polyphony */
  char with_reverb;                  /**< Should the synth use the built-in reverb unit? */
  char with_chorus;                  /**< Should the synth use the built-in chorus unit? */
  char verbose;                      /**< Turn verbose mode on? */
  char dump;                         /**< Dump events to stdout to hook up a user interface? */
  double sample_rate;                /**< The sample rate */
  int midi_channels;                 /**< the number of MIDI channels (>= 16) */
  int audio_channels;                /**< the number of audio channels (1 channel=left+right) */
  int audio_groups;                  /**< the number of (stereo) 'sub'groups from the synth.
					  Typically equal to audio_channels. */
  int effects_channels;              /**< the number of effects channels (>= 2) */
  int state;                         /**< the synthesizer state */
  unsigned int ticks;                /**< the number of audio samples since the start */
  unsigned int start;                /**< the start in msec, as returned by system clock */
  int midi_mode;                     /**< Current MIDI mode (#fluid_synth_midi_mode_t) */
  int midi_mode_lock;                /**< TRUE if MIDI mode cannot be changed by SYSEX messages */
<commit_msg>Made with_reverb and with_chorus of type int instead of char, so that atomic int ops will work right.<commit_after>/* FluidSynth - A Software Synthesizer
 *
 * Copyright (C) 2003  <NAME> and others.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307, USA
 */


#ifndef _FLUID_SYNTH_H
#define _FLUID_SYNTH_H


/***************************************************************
 *
 *                         INCLUDES
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "fluidsynth_priv.h"
#include "fluid_event_queue.h"
#include "fluid_list.h"
#include "fluid_rev.h"
#include "fluid_voice.h"
#include "fluid_chorus.h"
#include "fluid_ladspa.h"
#include "fluid_midi_router.h"
#include "fluid_sys.h"

/***************************************************************
 *
 *                         DEFINES
 */
#define FLUID_NUM_PROGRAMS      128
#define DRUM_INST_BANK		128

#if defined(WITH_FLOAT)
#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_FLOAT
#else
#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_DOUBLE
#endif


/***************************************************************
 *
 *                         ENUM
 */
enum fluid_loop {
  FLUID_UNLOOPED = 0,
  FLUID_LOOP_DURING_RELEASE = 1,
  FLUID_NOTUSED = 2,
  FLUID_LOOP_UNTIL_RELEASE = 3
};

enum fluid_synth_status
{
  FLUID_SYNTH_CLEAN,
  FLUID_SYNTH_PLAYING,
  FLUID_SYNTH_QUIET,
  FLUID_SYNTH_STOPPED
};

#define SYNTH_REVERB_CHANNEL 0
#define SYNTH_CHORUS_CHANNEL 1

/**
 * Defines the current MIDI mode.
 */
typedef enum
{
  FLUID_SYNTH_MIDI_MODE_NORMAL,         /**< Normal MIDI mode (percussion channel not special) */
  FLUID_SYNTH_MIDI_MODE_GM,             /**< GM MIDI mode, no note-offs on percussion channel (except for long guiro and whistle) */
  FLUID_SYNTH_MIDI_MODE_GS              /**< GS MIDI mode, identical to #FLUID_SYNTH_MIDI_MODE_GM at the moment */
} fluid_synth_midi_mode_t;

/**
 * Structure used for sfont_info field in #fluid_synth_t for each loaded
 * SoundFont with the SoundFont instance and additional fields.
 */
typedef struct _fluid_sfont_info_t {
  fluid_sfont_t *sfont; /**< Loaded SoundFont */
  fluid_synth_t *synth; /**< Parent synth */
  int refcount;         /**< SoundFont reference count (0 if no presets referencing it) */
  int bankofs;          /**< Bank offset */
} fluid_sfont_info_t;

/*
 * fluid_synth_t
 *
 * Mutual exclusion notes:
 *
 * Set only once on init:
 * ----------------------
 * verbose
 * dump
 * sample_rate (will be runtime change-able in the future)
 * midi_channels
 * audio_channels
 * audio_groups
 * effects_channels
 * start
 * channel[] (Contents change)
 * nvoice
 * voice[] (Contents change)
 * nbuf
 * left_buf[], right_buf[] (Contents change)
 * fx_left_buf[], fx_right_buf[] (Contents change)
 * LADSPA_FxUnit (Contents change)
 * cores
 * core_threads[]
 *
 * Single thread use only (modify only prior to synthesis):
 * loaders<>
 * midi_router
 *
 * Mutex protected:
 * settings{} (has its own mutex)
 * sfont_info<>
 * tuning
 * sfont_id
 * gain
 * reverb_roomsize, reverb_damping, reverb_width, reverb_level
 * chorus_nr, chorus_level, chorus_speed, chorus_depth, chorus_type
 *
 * Atomic operations:
 * ----------------------
 * with_reverb
 * with_chorus
 * state
 * midi_mode
 * midi_mode_lock
 * cpu_load
 * noteid
 * storeid
 * outbuf
 * sample_timers
 *
 * Only synth thread changes
 * -------------------------
 * ticks
 * reverb{}
 * chorus{}
 * cur
 * dither_index
 * polyphony (atomic int get for non-synth threads)
 * st_gain
 */

struct _fluid_synth_t
{
  fluid_thread_id_t synth_thread_id; /**< ID of the synthesis thread or FLUID_THREAD_ID_NULL if not yet set */
  fluid_private_t thread_queues;     /**< Thread private data for event queues for each non-synthesis thread queuing events */
  fluid_event_queue_t *queues[FLUID_MAX_EVENT_QUEUES];   /**< Thread event queues (NULL for unused elements) */

  fluid_rec_mutex_t mutex;           /**< Lock for multi-thread sensitive variables (not used by synthesis process) */
  fluid_list_t *queue_pool;          /**< List of event queues whose threads have been destroyed and which can be re-used */
  fluid_event_queue_t *return_queue; /**< Event queue for events from synthesis thread to non-synthesis threads (memory frees, etc) */
  fluid_timer_t *return_queue_timer; /**< Timer thread to process return event queue */

  fluid_settings_t* settings;        /**< the synthesizer settings */
  int device_id;                     /**< Device ID used for SYSEX messages */
  int polyphony;                     /**< maximum polyphony */
  int with_reverb;                  /**< Should the synth use the built-in reverb unit? */
  int with_chorus;                  /**< Should the synth use the built-in chorus unit? */
  char verbose;                      /**< Turn verbose mode on? */
  char dump;                         /**< Dump events to stdout to hook up a user interface? */
  double sample_rate;                /**< The sample rate */
  int midi_channels;                 /**< the number of MIDI channels (>= 16) */
  int audio_channels;                /**< the number of audio channels (1 channel=left+right) */
  int audio_groups;                  /**< the number of (stereo) 'sub'groups from the synth.
					  Typically equal to audio_channels. */
  int effects_channels;              /**< the number of effects channels (>= 2) */
  int state;                         /**< the synthesizer state */
  unsigned int ticks;                /**< the number of audio samples since the start */
  unsigned int start;                /**< the start in msec, as returned by system clock */
  int midi_mode;                     /**< Current MIDI mode (#fluid_synth_midi_mode_t) */
  int midi_mode_lock;                /**< TRUE if MIDI mode cannot be changed by SYSEX messages */

{'fraction_non_alphanumeric': 0.1268901013250195, 'fraction_numerical': 0.0056118472330475445, 'mean_word_length': 2.929862174578867, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1978079', 'n_tokens_mistral': 4086, 'n_tokens_neox': 3824, 'n_words': 1259}