package Audio;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

import Audio.Bass.SYNCPROC;

/**
 * Bass Mixer Library
 * @author rdkartono
 *
 */
@SuppressWarnings("unused")
public interface BassMix extends Library {
	BassMix Instance = Native.load("bassmix",BassMix.class);
		
		interface Constant{
			// Additional BASS_SetConfig options
			int BASS_CONFIG_MIXER_BUFFER = 0x10601;
			int BASS_CONFIG_MIXER_POSEX = 0x10602;
			int BASS_CONFIG_SPLIT_BUFFER = 0x10610;

			// BASS_Mixer_StreamCreate flags
			int BASS_MIXER_RESUME = 0x1000;	// resume stalled immediately upon new/unpaused source
			int BASS_MIXER_POSEX = 0x2000;	// enable BASS_Mixer_ChannelGetPositionEx support
			int BASS_MIXER_NOSPEAKER = 0x4000;	// ignore speaker arrangement
			int BASS_MIXER_QUEUE = 0x8000;	// queue sources
			int BASS_MIXER_END = 0x10000;	// end the stream when there are no sources
			int BASS_MIXER_NONSTOP = 0x20000;	// don't stall when there are no sources

			// BASS_Mixer_StreamAddChannel/Ex flags
			int BASS_MIXER_CHAN_ABSOLUTE = 0x1000;	// start is an absolute position
			int BASS_MIXER_CHAN_BUFFER = 0x2000;	// buffer data for BASS_Mixer_ChannelGetData/Level
			int BASS_MIXER_CHAN_LIMIT = 0x4000;	// limit mixer processing to the amount available from this source
			int BASS_MIXER_CHAN_MATRIX = 0x10000;	// matrix mixing
			int BASS_MIXER_CHAN_PAUSE = 0x20000;	// don't process the source
			int BASS_MIXER_CHAN_DOWNMIX = 0x400000; // downmix to stereo/mono
			int BASS_MIXER_CHAN_NORAMPIN = 0x800000; // don't ramp-in the start
			int BASS_MIXER_BUFFER = BASS_MIXER_CHAN_BUFFER;
			int BASS_MIXER_LIMIT = BASS_MIXER_CHAN_LIMIT;
			int BASS_MIXER_MATRIX = BASS_MIXER_CHAN_MATRIX;
			int BASS_MIXER_PAUSE = BASS_MIXER_CHAN_PAUSE;
			int BASS_MIXER_DOWNMIX = BASS_MIXER_CHAN_DOWNMIX;
			int BASS_MIXER_NORAMPIN = BASS_MIXER_CHAN_NORAMPIN;

			// Mixer attributes
			int BASS_ATTRIB_MIXER_LATENCY = 0x15000;
			int BASS_ATTRIB_MIXER_THREADS = 0x15001;
			int BASS_ATTRIB_MIXER_VOL = 0x15002;

			// Additional BASS_Mixer_ChannelIsActive return values
			int BASS_ACTIVE_WAITING = 5;
			int BASS_ACTIVE_QUEUED = 6;

			// BASS_Split_StreamCreate flags
			int BASS_SPLIT_SLAVE = 0x1000;	// only read buffered data
			int BASS_SPLIT_POS = 0x2000;

			// Splitter attributes
			int BASS_ATTRIB_SPLIT_ASYNCBUFFER = 0x15010;
			int BASS_ATTRIB_SPLIT_ASYNCPERIOD = 0x15011;
			
			// Envelope types
			int BASS_MIXER_ENV_FREQ = 1;
			int BASS_MIXER_ENV_VOL = 2;
			int BASS_MIXER_ENV_PAN = 3;
			int BASS_MIXER_ENV_LOOP = 0x10000; // flag: loop
			int BASS_MIXER_ENV_REMOVE = 0x20000; // flag: remove at end

			// Additional sync types
			int BASS_SYNC_MIXER_ENVELOPE = 0x10200;
			int BASS_SYNC_MIXER_ENVELOPE_NODE = 0x10201;
			int BASS_SYNC_MIXER_QUEUE = 0x10202;

			// Additional BASS_Mixer_ChannelSetPosition flag
			int BASS_POS_MIXER_RESET = 0x10000; // flag: clear mixer's playback buffer
			
			// Additional BASS_Mixer_ChannelGetPosition mode
			int BASS_POS_MIXER_DELAY = 5;

			// BASS_CHANNELINFO types
			int BASS_CTYPE_STREAM_MIXER = 0x10800;
			int BASS_CTYPE_STREAM_SPLIT = 0x10801;
		}
		

		// Envelope node
		@Structure.FieldOrder({"pos, value"})
		class BASS_MIXER_NODE extends Structure {
			public BASS_MIXER_NODE() {}
			public BASS_MIXER_NODE(long _pos, float _value) { pos=_pos; value=_value; }
			public long pos;
			public float value;
		}

		

		int BASS_Mixer_GetVersion();

		int BASS_Mixer_StreamCreate(int freq, int chans, int flags);
		boolean BASS_Mixer_StreamAddChannel(int handle, int channel, int flags);
		boolean BASS_Mixer_StreamAddChannelEx(int handle, int channel, int flags, long start, long length);
		int BASS_Mixer_StreamGetChannels(int handle, int[] channels, int count);

		int BASS_Mixer_ChannelGetMixer(int handle);
		int BASS_Mixer_ChannelIsActive(int handle);
		int BASS_Mixer_ChannelFlags(int handle, int flags, int mask);
		boolean BASS_Mixer_ChannelRemove(int handle);
		boolean BASS_Mixer_ChannelSetPosition(int handle, long pos, int mode);
		long BASS_Mixer_ChannelGetPosition(int handle, int mode);
		long BASS_Mixer_ChannelGetPositionEx(int channel, int mode, int delay);
		int BASS_Mixer_ChannelGetLevel(int handle);
		boolean BASS_Mixer_ChannelGetLevelEx(int handle, float[] levels, float length, int flags);
		int BASS_Mixer_ChannelGetData(int handle, Pointer buffer, int length);
		int BASS_Mixer_ChannelSetSync(int handle, int type, long param, SYNCPROC proc, Pointer user);
		boolean BASS_Mixer_ChannelRemoveSync(int channel, int sync);
		boolean BASS_Mixer_ChannelSetMatrix(int handle, float[][] matrix);
		boolean BASS_Mixer_ChannelSetMatrixEx(int handle, float[][] matrix, float time);
		boolean BASS_Mixer_ChannelGetMatrix(int handle, float[][] matrix);
		boolean BASS_Mixer_ChannelSetEnvelope(int handle, int type, BASS_MIXER_NODE[] nodes, int count);
		boolean BASS_Mixer_ChannelSetEnvelopePos(int handle, int type, long pos);
		long BASS_Mixer_ChannelGetEnvelopePos(int handle, int type, Float value);

		int BASS_Split_StreamCreate(int channel, int flags, int[] chanmap);
		int BASS_Split_StreamGetSource(int handle);
		int BASS_Split_StreamGetSplits(int handle, int[] splits, int count);
		boolean BASS_Split_StreamReset(int handle);
		boolean BASS_Split_StreamResetEx(int handle, int offset);
		int BASS_Split_StreamGetAvailable(int handle);

}
