/* SampleView.h */

#ifndef Included_SampleView_h
#define Included_SampleView_h

/* SampleView module depends on */
/* MiscInfo.h */
/* Audit */
/* Debug */
/* Definitions */
/* SampleStorageDisplay */
/* FixedPoint */
/* Screen */
/* Memory */
/* SampleConsts */

#include "Screen.h"
#include "FixedPoint.h"
#include "SampleConsts.h"

#define MINIMUMHORIZSCALE (0.001)

struct SampleViewRec;
typedef struct SampleViewRec SampleViewRec;

/* forwards */
struct SampleStorageDisplayRec;

/* create a new sample view that will display the specified storage object. */
SampleViewRec*			NewSampleView(WinType* Screen, OrdType XLoc, OrdType YLoc,
											OrdType Width, OrdType Height,
											struct SampleStorageDisplayRec* TheRawData);

/* dispose of the sample view.  the raw data object is also disposed. */
void								DisposeSampleView(SampleViewRec* View);

/* redraw one displayed sample line, at the specified X coordinate */
void								RedrawSampleViewOneLine(SampleViewRec* View, OrdType XPixel);

/* redraw the entire sample view area */
void								RedrawSampleView(SampleViewRec* View);

/* return the left edge of the sample view area */
OrdType							GetSampleViewXLoc(SampleViewRec* View);

/* return the top edge of the sample view area */
OrdType							GetSampleViewYLoc(SampleViewRec* View);

/* return the width of the sample view area */
OrdType							GetSampleViewWidth(SampleViewRec* View);

/* return the height of the sample view area */
OrdType							GetSampleViewHeight(SampleViewRec* View);

/* return the number of bits that the sample storage object has */
NumBitsType					GetSampleViewNumBits(SampleViewRec* View);

/* return the number of channels that the sample has */
NumChannelsType			GetSampleViewNumChannels(SampleViewRec* View);

/* return the number of sample frames in the sample */
long								GetSampleViewNumFrames(SampleViewRec* View);

/* return one point from the sample array.  for mono samples, WhichChannel must be */
/* eMonoChannel.  for stereo samples, it must either be eRightChannel or eLeftChannel */
largefixedsigned		GetSampleViewValue(SampleViewRec* View, long Index,
											ChannelType WhichChannel);

/* return the index of the leftmost displayed sample frame */
long								GetSampleViewXOffset(SampleViewRec* View);

/* return the scaling factor (zoom in/out).  large numbers are compress more. */
double							GetSampleViewHorizontalScale(SampleViewRec* View);

/* get the start point of the selection */
long								GetSampleViewSelectStart(SampleViewRec* View);

/* get the end point of the selection */
long								GetSampleViewSelectEnd(SampleViewRec* View);

/* return the number of frames that are currently displayed. */
long								GetSampleViewNumVisibleFrames(SampleViewRec* View);

/* return True if the data has been modified since the last time it was saved */
MyBoolean						DoesSampleViewNeedToBeSaved(SampleViewRec* View);

/* returns True if there is a selection or False if there is an insertion point. */
MyBoolean						SampleViewIsThereValidSelection(SampleViewRec* View);

/* move the sample view to a new location and redraw */
void								SetSampleViewLocation(SampleViewRec* View, OrdType XLoc,
											OrdType YLoc, OrdType Width, OrdType Height);

/* change the number of bits the sample is stored as */
MyBoolean						SetSampleViewNumBits(SampleViewRec* View,
											NumBitsType NewNumBits);

/* change the number of channels the sample has */
MyBoolean						SetSampleViewNumChannels(SampleViewRec* View,
											NumChannelsType NewNumChannels);

/* change the value of one sample point.  this does not redraw the screen */
void								SetSampleViewValue(SampleViewRec* View, long Index,
											ChannelType WhichChannel, largefixedsigned NewValue);

/* change the index into the sample that is being displayed. */
void								SetSampleViewXOffset(SampleViewRec* View, long NewXOffset);

/* change the horizontal scaling factor */
void								SetSampleViewHorizontalScale(SampleViewRec* View,
											double NewHorizontalScale);

/* set a selection.  if the selection is invalid, it will be corrected. */
void								SetSampleViewSelection(SampleViewRec* View, long Start, long End);

/* make sure the selection is correct (i.e. not out of range) */
void								SampleViewValidateSelection(SampleViewRec* View);

/* clear the not-saved flag.  this is called when the file is saved */
void								SampleViewHasBeenSaved(SampleViewRec* View);

/* make a copy of the data in NewData & store it in the current sample.  NewData is */
/* not disposed. */
MyBoolean						SampleViewSetContents(SampleViewRec* View,
											struct SampleStorageDisplayRec* NewData);

/* insert a zero area into the sample.  returns True if successful. */
MyBoolean						InsertSampleViewArea(SampleViewRec* View, long Index,
											long NumFramesToInsert);

/* delete an area from the sample.  returns True if successful. */
MyBoolean						DeleteSampleViewArea(SampleViewRec* View, long Index,
											long NumFramesToDelete);

/* extract a section of the sample & return a new sample object containing it. */
struct SampleStorageDisplayRec*	ExtractSampleViewSection(SampleViewRec* View, long Index,
											long NumFramesToExtract);

/* insert a sample into our sample at a specified point.  returns True if successful */
MyBoolean						InsertSampleViewSection(SampleViewRec* View, long Index,
											struct SampleStorageDisplayRec* DataToInsert);

/* get a copy of the specified channel as an array of fixedpoint numbers */
largefixedsigned*		SampleViewGetChannelFixed(SampleViewRec* View,
											ChannelType WhichChannel);

/* store a new array of data into the sample (replacing old contents).  returns */
/* True if successful.  this can only be used for mono samples. */
MyBoolean						SampleViewPutMonoFixed(SampleViewRec* View, largefixedsigned* Data);

/* store new arrays of data into the sample (replacing old contents).  returns True */
/* if successful.  this can only be used for stereo samples. */
MyBoolean						SampleViewPutStereoFixed(SampleViewRec* View, largefixedsigned* Left,
											largefixedsigned* Right);

/* the user is responsible for calling undo routines; none of the routines in */
/* this package call them. */

/* flush undo information. */
void								SampleViewFlushUndo(SampleViewRec* View);

/* save the current sample configuration into the undo information. */
MyBoolean						SampleViewSetupForUndo(SampleViewRec* View);

/* find out if it is possible to restore state to the last SampleViewSetupForUndo() */
MyBoolean						SampleViewUndoAvailable(SampleViewRec* View);

/* attempt to undo.  returns True if successful.  this call swaps the current sample */
/* state with that saved from the last call to SampleViewSetupForUndo(). */
MyBoolean						SampleViewUndo(SampleViewRec* View);

/* get the actual raw sample data */
largefixedsigned*		SampleViewGetActualRawData(SampleViewRec* View);

#endif
