File: Midi.h

package info (click to toggle)
exult 1.2-4
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 9,040 kB
  • ctags: 10,543
  • sloc: cpp: 99,373; sh: 8,333; ansic: 4,659; makefile: 988; yacc: 769; lex: 313; xml: 19
file content (139 lines) | stat: -rw-r--r-- 4,127 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 *  Copyright (C) 2000-2001  The Exult Team
 *
 *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _MIDI_H_
#define _MIDI_H_

#include <vector>
#ifndef WIN32
//#include "Mixer.h"
#endif
#include "xmidi.h"

// The 'types' of midi drivers
enum MidiDriverType {
	MIDI_DRIVER_NORMAL	= 0,	// We are outputting using Normal Midi Drivers
	MIDI_DRIVER_OGG,			// We are outputting using Oggs

#ifdef USE_FMOPL_MIDI
	MIDI_DRIVER_FMSYNTH,		// We are outputting using FM Synth Driver
#endif

#ifdef USE_MT32EMU_MIDI
	MIDI_DRIVER_MT32EMU,		// We are outputting using MT32EMU Driver (Ha, you'll never see this!)
#endif

	NUM_MIDI_DRIVER_TYPES		// Count of midi drivers
};


#include "SDL_mixer.h"

#include <string>

//---- MidiAbstract -----------------------------------------------------------

class	MidiAbstract
{
public:
	virtual void start_track(XMIDIEventList *, bool repeat) = 0;
	virtual void start_sfx(XMIDIEventList *) { }
	
	virtual void	stop_track(void)=0;
	virtual void	stop_sfx(void) { };
	virtual	bool	is_playing(void)=0;
	virtual	const	char *copyright(void)=0;

	virtual void load_patches(bool force_xmidi) { }
	virtual bool is_fm_synth() { return false; }
	virtual bool use_gs127() { return false; }

	MidiAbstract() {};
	virtual	~MidiAbstract() {};
};

//Pseudo device, used purely to create the OGG_MIDI class with something
class	OGG_MIDI : virtual public MidiAbstract
{
	static void		music_complete_callback(void);
public:
	OGG_MIDI();
	virtual	~OGG_MIDI();
	virtual void	start_track(XMIDIEventList *, bool repeat);
	virtual void	stop_track(void);
	virtual	bool	is_playing(void);
	virtual const	char *copyright(void);
};

//---- MyMidiPlayer -----------------------------------------------------------

class	MyMidiPlayer
{
public:

	MyMidiPlayer();
	~MyMidiPlayer();
	MyMidiPlayer(const char *flexfile);
	void	start_music(int num,bool continuous=false,int bank=0);
	void	start_music(const char *fname,int num,bool continuous=false);
	void	start_track(int num,bool continuous=false,int bank=0);
	void	start_track(const char *fname,int num,bool continuous=false);
	void	start_track(XMIDIEventList *eventlist, bool continuous=false);
	void	start_sound_effect(int num);
	void	stop_sound_effects();
	void	load_patches(bool force_xmidi=false) { if (midi_device) midi_device->load_patches(force_xmidi); }

	void	stop_music();
	
	bool	add_midi_bank(const char *s);
	void	set_music_conversion(int conv);
	int		get_music_conversion() { return music_conversion; }
	void	set_effects_conversion(int conv);
	int		get_effects_conversion() { return effects_conversion; }

	int		get_output_driver_type() { return output_driver_type; }
	void	set_output_driver_type(int);

	inline bool	is_track_playing(int num) { 
		return midi_device && current_track==num && midi_device->is_playing();
	}
	inline int	get_current_track() { return (midi_device!=0)&&midi_device->is_playing()?current_track:-1; }
	inline int	is_repeating() { return repeating; }

	bool is_fm_synth() { return midi_device?midi_device->is_fm_synth():false; }

	
private:

	MyMidiPlayer(const MyMidiPlayer &m) ; // Cannot call
	MyMidiPlayer &operator=(const MyMidiPlayer &); // Cannot call
	void    kmidi_start_track(int num,bool continuous=false);
	std::vector<std::string>	midi_bank;
	int	current_track;
	bool	repeating;
	MidiAbstract	*midi_device;
	bool	initialized;

	bool	init_device(void);

	int		music_conversion;
	int		effects_conversion;
	int		output_driver_type;
};

#endif