/*
    TiMidity -- Experimental MIDI to WAVE converter
    Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   playmidi.h
*/

#ifndef __TIMIDITY_PLAYMIDI_H__
#define __TIMIDITY_PLAYMIDI_H__

typedef struct MidiEvent_s
{
  int time;
  byte channel, type, a, b;
}
MidiEvent;

/* Midi events */
#define ME_NONE 	0
#define ME_NOTEON	1
#define ME_NOTEOFF	2
#define ME_KEYPRESSURE	3
#define ME_MAINVOLUME	4
#define ME_PAN		5
#define ME_SUSTAIN	6
#define ME_EXPRESSION	7
#define ME_PITCHWHEEL	8
#define ME_PROGRAM	9
#define ME_TEMPO	10
#define ME_PITCH_SENS	11

#define ME_ALL_SOUNDS_OFF	12
#define ME_RESET_CONTROLLERS	13
#define ME_ALL_NOTES_OFF	14
#define ME_TONE_BANK	15

#define ME_LYRIC	16
#define ME_TONE_KIT	17
#define ME_MASTERVOLUME	18
#define ME_CHANNEL_PRESSURE 19

#define ME_HARMONICCONTENT	71
#define ME_RELEASETIME		72
#define ME_ATTACKTIME		73
#define ME_BRIGHTNESS		74

#define ME_REVERBERATION	91
#define ME_CHORUSDEPTH		93

#define ME_EOT		99


#define SFX_BANKTYPE	64

typedef struct
{
	int bank;
	int program;
	int volume;
	int sustain;
	int panning;
	int pitchbend;
	int expression; 

	int mono; /* one note only on this channel -- not implemented yet */

	/* new stuff */
	int variationbank;
	int reverberation;
	int chorusdepth;
	int harmoniccontent;

	int releasetime;
	int attacktime;
	int brightness;
	int kit;
	int sfx;
	/* end new */

	int pitchsens;

	double pitchfactor; /* precomputed pitch bend factor to save some fdiv's */

	signed char transpose;

	char *name;
}
Channel;

/* Causes the instrument's default panning to be used. */
#define NO_PANNING -1
/* envelope points */
#define MAXPOINT 7

typedef struct
{
	byte status;
	byte channel;
	byte note;
	byte velocity;
	byte clone_type;

	Sample *sample;
	Sample *left_sample;
	Sample *right_sample;

	int clone_voice;

	u32_t orig_frequency;
	u32_t frequency;

	int sample_offset;
	int loop_start;
	int loop_end;
	int envelope_volume;
	int modulation_volume;
	int envelope_target;
	int modulation_target;

	int tremolo_sweep;
	int tremolo_sweep_position;
	int tremolo_phase;

	int lfo_sweep;
	int lfo_sweep_position;
	int lfo_phase;

	int vibrato_sweep;
	int vibrato_sweep_position;
	int vibrato_depth;
	int vibrato_delay;

	int starttime;
	int echo_delay_count;

	int echo_delay;
	int sample_increment;
	int envelope_increment;
	int modulation_increment;
	int tremolo_phase_increment;
	int lfo_phase_increment;

	final_volume_t left_mix;
	final_volume_t right_mix;
	final_volume_t lr_mix;
	final_volume_t rr_mix;
	final_volume_t ce_mix;
	final_volume_t lfe_mix;

	double left_amp;
	double right_amp;
	double lr_amp;
	double rr_amp;
	double ce_amp;
	double lfe_amp;

	double volume;
	double tremolo_volume;
	double lfo_volume;

	int vibrato_sample_increment[VIBRATO_SAMPLE_INCREMENTS];

	int envelope_rate[MAXPOINT];
	int envelope_offset[MAXPOINT];

	int vibrato_phase;
	int vibrato_control_ratio;
	int vibrato_control_counter;
	int envelope_stage;
	int modulation_stage;
	int control_counter;
	int modulation_delay;
	int modulation_counter;
	int panning;
	int panned;
}
Voice;

/* Voice status options: */
#define VOICE_FREE 0
#define VOICE_ON 1
#define VOICE_SUSTAINED 2
#define VOICE_OFF 3
#define VOICE_DIE 4

/* Voice panned options: */
#define PANNED_MYSTERY 0
#define PANNED_LEFT 1
#define PANNED_RIGHT 2
#define PANNED_CENTER 3
/* Anything but PANNED_MYSTERY only uses the left volume */

/* Envelope stages: */
#define ATTACK 0
#define HOLD 1
#define DECAY 2
#define RELEASE 3
#define RELEASEB 4
#define RELEASEC 5
#define DELAY 6

extern Channel channel[16];
extern Voice voice[MAX_VOICES];

extern signed char drumvolume[MAXCHAN][MAXNOTE];
extern signed char drumpanpot[MAXCHAN][MAXNOTE];
extern signed char drumreverberation[MAXCHAN][MAXNOTE];
extern signed char drumchorusdepth[MAXCHAN][MAXNOTE];

extern int control_ratio, amp_with_poly;
extern int drumchannels;
extern int adjust_panning_immediately;

#define ISDRUMCHANNEL(c) ((drumchannels & (1<<(c))))

extern int GM_System_On;
extern int XG_System_On;
extern int GS_System_On;

extern int XG_System_reverb_type;
extern int XG_System_chorus_type;
extern int XG_System_variation_type;

#endif /* __TIMIDITY_PLAYMIDI_H__ */

//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
