/* WaveTableOscControl.h */

#ifndef Included_WaveTableOscControl_h
#define Included_WaveTableOscControl_h

/* WaveTableOscControl module depends on */
/* MiscInfo.h */
/* Audit */
/* Debug */
/* Definitions */
/* FastFixedPoint */
/* FixedPoint */
/* Memory */
/* EnvelopeState */
/* SampleConsts */
/* LFOGenerator */
/* Multisampler */
/* OscillatorSpecifier */
/* Envelope */
/* LFOListSpecifier */
/* FastModulation */
/* 64BitMath */
/* ErrorDaemon */
/* OscEffectGenerator */
/* EffectSpecList */
/* AccentStruct */

#include "FixedPoint.h"
#include "AccentStruct.h"

struct WaveTableTemplateRec;
typedef struct WaveTableTemplateRec WaveTableTemplateRec;

struct WaveTableStateRec;
typedef struct WaveTableStateRec WaveTableStateRec;

/* forwards */
struct OscillatorRec;
struct ArrayRec;
struct ErrorDaemonRec;

/* get rid of all cached memory for state or template records */
void									FlushWaveTableOscControl(void);

/* perform one envelope update cycle, and set a new frequency for a wave table */
/* state object.  used for portamento and modulation of frequency (vibrato) */
void									UpdateWaveTableEnvelopes(WaveTableStateRec* State,
												float NewFrequencyHertz);

/* dispose of the wave table state record */
void									DisposeWaveTableState(WaveTableStateRec* State);

/* dispose of the wave table information template */
void									DisposeWaveTableTemplate(WaveTableTemplateRec* Template);

/* create a new wave table template */
WaveTableTemplateRec*	NewWaveTableTemplate(struct OscillatorRec* Oscillator,
												float EnvelopeTicksPerSecond, long SamplingRate,
												MyBoolean Stereo, MyBoolean TimeInterp, MyBoolean WaveInterp,
												struct ErrorDaemonRec* ErrorDaemon,
												struct MainWindowRec* MainWindow, float InverseVolume);

/* create a new wave table state object. */
WaveTableStateRec*		NewWaveTableState(WaveTableTemplateRec* Template,
												float FreqForMultisampling, AccentParam* Accents,
												float Loudness, float HurryUp,
												long* PreOriginTimeOut, float StereoPosition,
												float InitialFrequency, float PitchDisplacementDepthLimit,
												float PitchDisplacementRateLimit,
												long PitchDisplacementStartPoint);

/* fix up pre-origin time for the wave table state object */
void									FixUpWaveTableStatePreOrigin(WaveTableStateRec* State,
												long ActualPreOrigin);

/* send a key-up signal to one of the oscillators */
void									WaveTableKeyUpSustain1(WaveTableStateRec* State);
void									WaveTableKeyUpSustain2(WaveTableStateRec* State);
void									WaveTableKeyUpSustain3(WaveTableStateRec* State);

/* restart a wave table oscillator.  this is used for tie continuations */
void									RestartWaveTableState(WaveTableStateRec* State,
												float NewFreqMultisampling, AccentParam* NewAccents,
												float NewLoudness, float NewHurryUp, MyBoolean RetriggerEnvelopes,
												float NewStereoPosition, float NewInitialFrequency,
												float PitchDisplacementDepthLimit,
												float PitchDisplacementRateLimit,
												long PitchDisplacementStartPoint);

/* generate a sequence of samples (called for each envelope clock) */
void									WaveTableGenSamples(WaveTableStateRec* State,
												long SampleCount, largefixedsigned* RawBuffer,
												largefixedsigned* PrivateWorkspace);

/* find out if the wave table oscillator has finished */
MyBoolean							WaveTableIsItFinished(WaveTableStateRec* State);

#endif
