/*
 *  MGroup.h
 *  MSE
 *
 *  Created by Hawk on 10/30/09.
 *  Copyright 2009 Maizesoft. All rights reserved.
 *
 */

#pragma once

#include "MVoice.h"

//group is a collection of samples which share some properties

struct MSE_GroupProperty
{
	MSE_GroupSelection selectionType;
	int midiCh;
	int keySwitch;
	int controller;
	int controllerRangeLow, controllerRangeHigh;
	int program;
	MSE_OverlapTrigger overlapTrigger;

	//over all ADSR
	float attack;		//time in ms
	float decay;		//time in ms
	float sustain;		//dB
	float release;		//time in ms
	
	MSE_Rect range;
	int releaseTrigger;
	float releaseTriggerDecay;	//time in ms

	float gain;
	int disabled;
	int output;
    float pan;
	int reserved[123];
};

class MSE_API MGroup
{
public:
	MGroup();
	~MGroup();
	
	//samples
	bool AddSample(MSample* pSample);
	void RemoveSample(MSample* pSample);
	void RemoveAllSamples();
	int GetSampleCount();
	MSample* GetSample(int index);
	
	void UpdateAllSampleProperty();
    void UpdateSampleMapping();

	//client samples management
	int GetClientSampleCount();
	MSample* GetClientSample(int index);
	void AddClientSample(MSample* sample);
	void RemoveClientSample(MSample* sample);
	void RemoveAllClientSamples();
	bool IsSampleInClient(MSample* sample);
	MSample* GetSingleClientSample();
	int GetSingleClientSampleIndex();
	void SetSingleClientSample(MSample* sample);
	void SetSingleClientSample(int index);

	//MIDI
	MSample* FindSample(MSE_Byte note, MSE_Byte velocity);
	MSample* FindRobinSample(MSE_Byte note, MSE_Byte velocity);
	
	//properties
	MSE_GroupProperty f_Property;
	std::string f_GroupName;
	
protected:
	std::vector<MSample*> m_SampleList;
	std::vector<MSample*> m_ClientSamples;	//only for GUI client use
	int m_LastRobin;
	int m_FindSamplePosition;
    std::vector<MSample*> m_SampleMapping[128][128];
};

