/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/audio/midiin.hpp

*/

#ifndef SGX_AUDIO_MIDI_IN_HPP
#define SGX_AUDIO_MIDI_IN_HPP	1

class sgxMidiIn {
public:
	sgxMidiIn();

	tBOOL open(sgxMidiInDevice *pDevice);
	void flush();
	void close();

	void start();
	void stop();

	// Use a handler, if you don't want to subclass the whole class
	// (which you generally won't need to do, but is available to
	// follow the ideas of second chance functions)
	sgxMidiInprocess *setprocessHandler(sgxMidiInprocess *pHandler);
	
	// A utility to note the current state of the notes currently
	// down
	tBOOL	isNoteOn(tUINT32 channel, tUINT32 note);
	// The current state of various parameters
	int		getProgram(tUINT32 channel);
	int		getPressure(tUINT32 channel);
	int		getPitchWheel(tUINT32 channel=0);
	int	*	getNoteStatus();

	void	resetNotes();

	// These can be manually invoked for testing code
	void	midiSysexprocess(tBYTE *pData, tUINT32 dataSize);
	void	midiEventprocess(tUINT32 msg, tUINT32 channel, tUINT32 note, tUINT32 volume);
	void	midiClockprocess();

private:
	tBOOL					m_bRunning;
	sgxMidiInDevice	*m_pDevice;
	sgxMidiInprocess	*m_pHandler;

	int noteStatus[2048];
	int parameterStatus[128];
	int currentProgram[16];
	int currentPressure[16];
	int pitchWheel[16];
};

#endif /* SGX_AUDIO_MIDI_IN_HPP */
