/***************************************************************************
                          sine_voice.h  -  description
                             -------------------
    begin                : Wed Jul 10 2002
    copyright            : (C) 2002 by red
    email                : red@server
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TB303_VOICE_H
#define TB303_VOICE_H

#include "voice.h"
//#include "sine.h"

/**
  *@author red
  */

class TB303_Voice : public Voice  {
public:

	struct Data { //the bank will need this data to configure us

                bool play; //play this note
                int coarse; //coarse
                int decay; //decay time
		
		Data() {

			memset(this,0,sizeof(Data)); //zero it
			play=true; //we want to play it!!
			decay=4;
  		}
	};

private:

	float base_freq; //well cache the base freq

        bool noteoff_was_pressed;
	
	Data used_data; //cache of data

	double increment;
	double offset;

	float decay; //once noteoff is pressed, decay will start deincrementing

	void recalculate_increment();	
	virtual void recalculate_pitch_internal(); //this will get called when the pitch of the note changes
public:

	void set_data(Data *p_data);


	Status get_status(); //bit obvious :)

	void poll_for_dead_staus(); //call in case we try to figure out if this note voice is dead, but i guess we dont

        void set_note_internal(char p_note,char p_velocity); //this gets called on noteon
	void set_note_off_internal(char p_velocity); //and this on noteoff
	
	void mix_modifier_call(); //this gets called, i think, 50 times per second in case we want to periodically change some modifier

public: /* MIXING! */

	void set_mix_frequency_internal(int p_mixfreq); //this will be called to configure the frequency
	void mix_internal(int p_amount,Sint32* p_where); //and this will ask us to mix the voice

	TB303_Voice();
	~TB303_Voice();
};

#endif
