/* SampleWindow.h */

#ifndef Included_SampleWindow_h
#define Included_SampleWindow_h

/* SampleWindow module depends on */
/* MiscInfo.h */
/* Audit */
/* Debug */
/* Definitions */
/* Screen */
/* EventLoop */
/* Menus */
/* FixedPoint */
/* Memory */
/* MainWindowStuff */
/* CodeCenter */
/* SampleObject */
/* SampleView */
/* TextEdit */
/* WindowDispatcher */
/* Alert */
/* GrowIcon */
/* SampleTestPlay */
/* DataMunging */
/* Main */
/* Numbers */
/* PcodeSystem */
/* PcodeStack */
/* Scroll */
/* SampleList */
/* SampleConsts */
/* EditImages */
/* IconButton */
/* SampleStorageActual */
/* SampleStorageDisplay */
/* FindDialog */
/* GlobalWindowMenuList */
/* CompilerRoot */
/* FunctionCode */
/* ExportWAVSample */
/* ExportRAWSample */
/* ExportAIFFSample */

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

struct SampleWindowRec;
typedef struct SampleWindowRec SampleWindowRec;

/* forward declarations */
struct MainWindowRec;
struct SampleObjectRec;
struct CodeCenterRec;
struct SampleStorageActualRec;
struct SampleListRec;

typedef enum {eSampleLoop1 EXECUTE(= - 732), eSampleLoop2, eSampleLoop3} SampleLoops;

/* create a new sample editing window.  the function gets ownership of SampleStorage */
SampleWindowRec*		NewSampleWindow(struct MainWindowRec* MainWindow,
											struct SampleObjectRec* SampleObject,
											struct CodeCenterRec* CodeCenter,
											struct SampleStorageActualRec* SampleStorage,
											struct SampleListRec* SampleList,
											OrdType WinX, OrdType WinY, OrdType WinWidth, OrdType WinHeight);

/* dispose of the window and write all modified data back */
void								DisposeSampleWindow(SampleWindowRec* Window);

/* returns True if any data has been changed since the last time the file was saved */
MyBoolean						HasSampleWindowBeenModified(SampleWindowRec* Window);

/* bring the window to the top and give it the focus */
void								SampleWindowBringToTop(SampleWindowRec* Window);

/* event handling routines */
void								SampleWindowDoIdle(SampleWindowRec* Window,
											MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
											ModifierFlags Modifiers);
void								SampleWindowBecomeActive(SampleWindowRec* Window);
void								SampleWindowBecomeInactive(SampleWindowRec* Window);
void								SampleWindowJustResized(SampleWindowRec* Window);
void								SampleWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
											ModifierFlags Modifiers, SampleWindowRec* Window);
void								SampleWindowDoKeyDown(unsigned char KeyCode,
											ModifierFlags Modifiers, SampleWindowRec* Window);
void								SampleWindowClose(SampleWindowRec* Window);
void								SampleWindowUpdator(SampleWindowRec* Window);
void								SampleWindowMenuSetup(SampleWindowRec* Window);
void								SampleWindowDoMenuCommand(SampleWindowRec* Window,
											MenuItemType* MenuItem);

/* copy data in the currently active text edit field to wherever it belongs */
void								SampleWindowFinalizeCurrentEdit(SampleWindowRec* Window);

/* get the editing version of the origin point */
long								SampleWindowGetOrigin(SampleWindowRec* Window);

/* get the current loop start point */
long								SampleWindowGetLoopStart(SampleWindowRec* Window);

/* get the current loop end point */
long								SampleWindowGetLoopEnd(SampleWindowRec* Window);

/* get the sampling rate */
long								SampleWindowGetSamplingRate(SampleWindowRec* Window);

/* get the natural recorded pitch */
double							SampleWindowGetNaturalFrequency(SampleWindowRec* Window);

/* copy the select start point from the sample view to the edit box */
void								SampleWindowPutSelectStart(SampleWindowRec* Window);

/* copy the select end point from the sample view to the edit box */
void								SampleWindowPutSelectEnd(SampleWindowRec* Window);

/* copy the scaling factor from the sample view to the edit box */
void								SampleWindowPutScalingFactor(SampleWindowRec* Window);

/* put a new origin point into the edit box */
void								SampleWindowPutOrigin(SampleWindowRec* Window, long NewOrigin);

/* put a new loop start into the current loop start edit box */
void								SampleWindowPutLoopStart(SampleWindowRec* Window, long NewLoopStart);

/* put a new loop end into the current loop end edit box */
void								SampleWindowPutLoopEnd(SampleWindowRec* Window, long NewLoopEnd);

/* put a new sampling rate into the sampling rate edit box */
void								SampleWindowPutSamplingRate(SampleWindowRec* Window,
											long NewSamplingRate);

/* put a new natural recorded pitch into the natural frequency edit box */
void								SampleWindowPutNaturalFrequency(SampleWindowRec* Window,
											double NewNaturalFrequency);

/* find the current mouse position and put it in the box */
void								SampleWindowPutMousePosition(SampleWindowRec* Window);

/* get the number of bits used to store the sample */
NumBitsType					SampleWindowGetNumBits(SampleWindowRec* Window);

/* get the number of channels the sample has */
NumChannelsType			SampleWindowGetNumChannels(SampleWindowRec* Window);

/* get a copy of the name of the sample */
char*								SampleWindowGetNameCopy(SampleWindowRec* Window);

/* get the number of frames in the current sample */
long								SampleWindowGetNumFrames(SampleWindowRec* Window);

/* get a copy of the formula text */
char*								SampleWindowGetFormulaCopy(SampleWindowRec* Window);

/* get a copy of the left channel for a stereo sample. */
largefixedsigned*		SampleWindowGetFixedArrayLeft(SampleWindowRec* Window);

/* get a copy of the right channel for a stereo sample. */
largefixedsigned*		SampleWindowGetFixedArrayRight(SampleWindowRec* Window);

/* get a copy of a mono sample. */
largefixedsigned*		SampleWindowGetFixedArrayMono(SampleWindowRec* Window);

/* put a new name in.  the caller is responsible for deleting NewName */
void								SampleWindowObjectNameChange(SampleWindowRec* Window, char* NewName);

/* evaluate the formula and modify the sample */
void								SampleWindowPerformCalculation(SampleWindowRec* Window);

/* redraw the origin and loop point bars */
void								SampleWindowRedrawThangs(SampleWindowRec* Window);

/* redraw the sample points that occur under the origin and loop point bars */
void								SampleWindowRedrawUnderThangs(SampleWindowRec* Window);

/* make sure the loop start and end are within the proper ranges */
void								AdjustSampleWindowThangs(SampleWindowRec* Window);

/* recalculate the scroll bar displacements and redraw it */
void								UpdateSampleWindowScrollbar(SampleWindowRec* Window);

/* handle a mouse down in the sample edit area. */
void								SampleWindowDoMouseDownInEdit(SampleWindowRec* Window, OrdType OrigX,
											OrdType OrigY);

/* find out which loop the sample is editing */
SampleLoops					SampleWindowEditingWhichLoop(SampleWindowRec* Window);

/* force the sample data to be written back to the object.  this does not write */
/* back any other data. */
MyBoolean						SampleWindowForceUpdateSampleObjectData(SampleWindowRec* Window);

/* get the raw data for the sample, in char or short form.  the caller must NOT */
/* dispose of this data, and it will become invalid if any modifications are made */
/* to the sample.  This is basically SampleObjectGetRawData() with a call to */
/* SampleWindowForceUpdateSampleObjectData() to keep everything consistent. */
char*								SampleWindowGetRawData(SampleWindowRec* Window);

/* get the raw fixedpoint data for the sample. */
largefixedsigned*		SampleWindowGetRawFixedPointData(SampleWindowRec* Window);

/* the document title has changed, so change the window title bar.  caller is */
/* responsible for deleting the string, which should be non-null-terminated. */
void								SampleWindowGlobalNameChange(SampleWindowRec* Window,
											char* NewFilename);

/* force the window title bar to be renamed even if the document hasn't been renamed */
void								SampleWindowResetTitlebar(SampleWindowRec* Window);

/* get an 'actual' sample object that contains the same data as the window.  the */
/* caller must delete the object. */
struct SampleStorageActualRec*	SampleWindowGetTheSampleActual(SampleWindowRec* Window);

/* force ALL modified data to be written back to the object.  this includes */
/* calling SampleWindowForceUpdateSampleObjectData() */
MyBoolean						SampleWindowWritebackModifiedData(SampleWindowRec* Window);

/* this routine updates the loop points when some number of sample frames are */
/* inserted or removed from the specified point.  (for removal, NumAddedFrames < 0) */
/* it does NOT do any redrawing of the points. */
void								SampleWindowShiftPoints(SampleWindowRec* Window, long Position,
											long NumAddedFrames);

#endif
