/* PlayPrefsDialog.c */
/*****************************************************************************/
/*                                                                           */
/*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
/*    Copyright (C) 1994  Thomas R. Lawrence                                 */
/*                                                                           */
/*    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.                                    */
/*                                                                           */
/*    This program is distributed in the hope that it will be useful,        */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
/*    GNU General Public License for more details.                           */
/*                                                                           */
/*    You should have received a copy of the GNU General Public License      */
/*    along with this program; if not, write to the Free Software            */
/*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
/*                                                                           */
/*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
/*                                                                           */
/*****************************************************************************/

#include "MiscInfo.h"
#include "Audit.h"
#include "Debug.h"
#include "Definitions.h"

#include "PlayPrefsDialog.h"
#include "Memory.h"
#include "Screen.h"
#include "EventLoop.h"
#include "Menus.h"
#include "Alert.h"
#include "MainWindowStuff.h"
#include "StringList.h"
#include "TrackList.h"
#include "Array.h"
#include "TrackObject.h"
#include "TextEdit.h"
#include "DataMunging.h"
#include "SimpleButton.h"
#include "Numbers.h"
#include "Main.h"
#include "RadioButton.h"
#include "CheckBox.h"
#include "SampleDeviceOutput.h"
#include "DiskFileOutput.h"
#include "PlayAIFFFile.h"


#define WINXSIZE (465)

#define INDENTVALUE (100)

#define TRACKLISTX (0)
#define TRACKLISTY (0)
#define TRACKLISTWIDTH (200)
#define TRACKLISTHEIGHT (240)

#define SELECTALLBUTTONWIDTH (85)
#define SELECTALLBUTTONHEIGHT (21)
#define SELECTALLBUTTONX (TRACKLISTX + (TRACKLISTWIDTH / 2)\
					- ((TRACKLISTWIDTH / 2) / 2) - (SELECTALLBUTTONWIDTH / 2))
#define SELECTALLBUTTONY (TRACKLISTY + TRACKLISTHEIGHT + 5)

#define SELECTNONEBUTTONWIDTH (SELECTALLBUTTONWIDTH)
#define SELECTNONEBUTTONHEIGHT (SELECTALLBUTTONHEIGHT)
#define SELECTNONEBUTTONX (TRACKLISTX + (TRACKLISTWIDTH / 2)\
					+ ((TRACKLISTWIDTH / 2) / 2) - (SELECTALLBUTTONWIDTH / 2))
#define SELECTNONEBUTTONY (SELECTALLBUTTONY)

#define CANCELBUTTONWIDTH (95)
#define CANCELBUTTONHEIGHT (SELECTALLBUTTONHEIGHT)
#define CANCELBUTTONX (((1 * WINXSIZE) / 8) - (CANCELBUTTONWIDTH / 2))
#define CANCELBUTTONY (SELECTALLBUTTONY + SELECTALLBUTTONHEIGHT + 10)

#define DONTPLAYBUTTONWIDTH (CANCELBUTTONWIDTH)
#define DONTPLAYBUTTONHEIGHT (SELECTALLBUTTONHEIGHT)
#define DONTPLAYBUTTONX (((3 * WINXSIZE) / 8) - (DONTPLAYBUTTONWIDTH / 2))
#define DONTPLAYBUTTONY (CANCELBUTTONY)

#define PLAYAUDIOBUTTONWIDTH (CANCELBUTTONWIDTH)
#define PLAYAUDIOBUTTONHEIGHT (SELECTALLBUTTONHEIGHT)
#define PLAYAUDIOBUTTONX (((5 * WINXSIZE) / 8) - (PLAYAUDIOBUTTONWIDTH / 2))
#define PLAYAUDIOBUTTONY (CANCELBUTTONY)

#define PLAYDISKBUTTONWIDTH (CANCELBUTTONWIDTH)
#define PLAYDISKBUTTONHEIGHT (SELECTALLBUTTONHEIGHT)
#define PLAYDISKBUTTONX (((7 * WINXSIZE) / 8) - (PLAYDISKBUTTONWIDTH / 2))
#define PLAYDISKBUTTONY (CANCELBUTTONY)

#define SAMPLERATEPROMPTX (TRACKLISTX + TRACKLISTWIDTH + 20)
#define SAMPLERATEPROMPTY (13)

#define SAMPLERATEEDITX (SAMPLERATEPROMPTX + INDENTVALUE)
#define SAMPLERATEEDITY (SAMPLERATEPROMPTY - 3)
#define SAMPLERATEEDITWIDTH (130)
#define SAMPLERATEEDITHEIGHT (21)

#define ENVELOPERATEPROMPTX (SAMPLERATEPROMPTX)
#define ENVELOPERATEPROMPTY (SAMPLERATEPROMPTY + SAMPLERATEEDITHEIGHT + 3)

#define ENVELOPERATEEDITX (ENVELOPERATEPROMPTX + INDENTVALUE)
#define ENVELOPERATEEDITY (ENVELOPERATEPROMPTY - 3)
#define ENVELOPERATEEDITWIDTH (SAMPLERATEEDITWIDTH)
#define ENVELOPERATEEDITHEIGHT (SAMPLERATEEDITHEIGHT)

#define BEATSPERMINPROMPTX (SAMPLERATEPROMPTX)
#define BEATSPERMINPROMPTY (ENVELOPERATEPROMPTY + ENVELOPERATEEDITHEIGHT + 3)

#define BEATSPERMINEDITX (BEATSPERMINPROMPTX + INDENTVALUE)
#define BEATSPERMINEDITY (BEATSPERMINPROMPTY - 3)
#define BEATSPERMINEDITWIDTH (SAMPLERATEEDITWIDTH)
#define BEATSPERMINEDITHEIGHT (SAMPLERATEEDITHEIGHT)

#define VOLUMEPROMPTX (SAMPLERATEPROMPTX)
#define VOLUMEPROMPTY (BEATSPERMINPROMPTY + BEATSPERMINEDITHEIGHT + 3)

#define VOLUMEEDITX (VOLUMEPROMPTX + INDENTVALUE)
#define VOLUMEEDITY (VOLUMEPROMPTY - 3)
#define VOLUMEEDITWIDTH (SAMPLERATEEDITWIDTH)
#define VOLUMEEDITHEIGHT (SAMPLERATEEDITHEIGHT)

#define SCANNINGGAPPROMPTX (SAMPLERATEPROMPTX)
#define SCANNINGGAPPROMPTY (VOLUMEPROMPTY + VOLUMEEDITHEIGHT + 3)

#define SCANNINGGAPEDITX (SCANNINGGAPPROMPTX + INDENTVALUE)
#define SCANNINGGAPEDITY (SCANNINGGAPPROMPTY - 3)
#define SCANNINGGAPEDITWIDTH (SAMPLERATEEDITWIDTH)
#define SCANNINGGAPEDITHEIGHT (SAMPLERATEEDITHEIGHT)

#define BUFFERDURATIONPROMPTX (SAMPLERATEPROMPTX)
#define BUFFERDURATIONPROMPTY (SCANNINGGAPPROMPTY + SCANNINGGAPEDITHEIGHT + 3)

#define BUFFERDURATIONEDITX (BUFFERDURATIONPROMPTX + INDENTVALUE)
#define BUFFERDURATIONEDITY (BUFFERDURATIONPROMPTY - 3)
#define BUFFERDURATIONWIDTH (SAMPLERATEEDITWIDTH)
#define BUFFERDURATIONHEIGHT (SAMPLERATEEDITHEIGHT)

#define BITS8BUTTONX (BUFFERDURATIONPROMPTX)
#define BITS8BUTTONY (BUFFERDURATIONPROMPTY + VOLUMEEDITHEIGHT + 5)
#define BITS8BUTTONWIDTH (100)
#define BITS8BUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define BITS16BUTTONX (BITS8BUTTONX)
#define BITS16BUTTONY (BITS8BUTTONY + BITS8BUTTONHEIGHT - 1)
#define BITS16BUTTONWIDTH (BITS8BUTTONWIDTH)
#define BITS16BUTTONHEIGHT (BITS8BUTTONHEIGHT)

#define BITS24BUTTONX (BITS8BUTTONX)
#define BITS24BUTTONY (BITS16BUTTONY + BITS16BUTTONHEIGHT - 1)
#define BITS24BUTTONWIDTH (BITS8BUTTONWIDTH)
#define BITS24BUTTONHEIGHT (BITS8BUTTONHEIGHT)

#define BITS32BUTTONX (BITS8BUTTONX)
#define BITS32BUTTONY (BITS24BUTTONY + BITS24BUTTONHEIGHT - 1)
#define BITS32BUTTONWIDTH (BITS8BUTTONWIDTH)
#define BITS32BUTTONHEIGHT (BITS8BUTTONHEIGHT)

#define STEREOBUTTONX (BITS8BUTTONX + 105)
#define STEREOBUTTONY (BITS8BUTTONY)
#define STEREOBUTTONWIDTH (80)
#define STEREOBUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define MONOBUTTONX (STEREOBUTTONX)
#define MONOBUTTONY (STEREOBUTTONY + STEREOBUTTONHEIGHT - 1)
#define MONOBUTTONWIDTH (STEREOBUTTONWIDTH)
#define MONOBUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define INTERPTIMEBUTTONX (STEREOBUTTONX)
#define INTERPTIMEBUTTONY (MONOBUTTONY + MONOBUTTONHEIGHT + 5)
#define INTERPTIMEBUTTONWIDTH (140)
#define INTERPTIMEBUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define INTERPWAVEBUTTONX (STEREOBUTTONX)
#define INTERPWAVEBUTTONY (INTERPTIMEBUTTONY + INTERPTIMEBUTTONHEIGHT - 1)
#define INTERPWAVEBUTTONWIDTH (INTERPTIMEBUTTONWIDTH)
#define INTERPWAVEBUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define CLIPWARNBUTTONX (STEREOBUTTONX)
#define CLIPWARNBUTTONY (INTERPWAVEBUTTONY + INTERPWAVEBUTTONHEIGHT + 5)
#define CLIPWARNBUTTONWIDTH (INTERPTIMEBUTTONWIDTH)
#define CLIPWARNBUTTONHEIGHT (SAMPLERATEEDITHEIGHT)

#define WINYSIZE (CANCELBUTTONY + CANCELBUTTONHEIGHT + 10)


typedef struct
	{
		WinType*						ScreenID;
		StringListRec*			TrackActivationList;
		SimpleButtonRec*		SelectAllButton;
		SimpleButtonRec*		SelectNoneButton;
		SimpleButtonRec*		CancelButton;
		SimpleButtonRec*		DontPlayButton;
		SimpleButtonRec*		PlayAudioButton;
		SimpleButtonRec*		PlayDiskButton;
		TextEditRec*				SampleRateEdit;
		TextEditRec*				EnvelopeRateEdit;
		TextEditRec*				BeatsPerMinEdit;
		TextEditRec*				VolumeEdit;
		TextEditRec*				ScanningGapEdit;
		TextEditRec*				DurationWidthEdit;
		RadioButtonRec*			Bits8Button;
		RadioButtonRec*			Bits16Button;
		RadioButtonRec*			Bits24Button;
		RadioButtonRec*			Bits32Button;
		RadioButtonRec*			StereoButton;
		RadioButtonRec*			MonoButton;
		CheckBoxRec*				InterpTimeButton;
		CheckBoxRec*				InterpWaveButton;
		CheckBoxRec*				ClipWarnButton;
	} WindowRec;


static void					RedrawTheWindow(WindowRec* Window)
	{
		CheckPtrExistence(Window);
		RedrawStringList(Window->TrackActivationList);
		RedrawSimpleButton(Window->SelectAllButton);
		RedrawSimpleButton(Window->SelectNoneButton);
		RedrawSimpleButton(Window->CancelButton);
		RedrawSimpleButton(Window->DontPlayButton);
		RedrawSimpleButton(Window->PlayAudioButton);
		RedrawSimpleButton(Window->PlayDiskButton);
		TextEditFullRedraw(Window->SampleRateEdit);
		TextEditFullRedraw(Window->EnvelopeRateEdit);
		TextEditFullRedraw(Window->BeatsPerMinEdit);
		TextEditFullRedraw(Window->VolumeEdit);
		TextEditFullRedraw(Window->ScanningGapEdit);
		TextEditFullRedraw(Window->DurationWidthEdit);
		RedrawRadioButton(Window->Bits8Button);
		RedrawRadioButton(Window->Bits16Button);
		RedrawRadioButton(Window->Bits24Button);
		RedrawRadioButton(Window->Bits32Button);
		RedrawRadioButton(Window->StereoButton);
		RedrawRadioButton(Window->MonoButton);
		RedrawCheckBox(Window->InterpTimeButton);
		RedrawCheckBox(Window->InterpWaveButton);
		RedrawCheckBox(Window->ClipWarnButton);
		SetClipRect(Window->ScreenID,0,0,WINXSIZE,WINYSIZE);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Sampling Rate:",14,
			SAMPLERATEPROMPTX,SAMPLERATEPROMPTY,ePlain);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Envelope Rate:",14,
			ENVELOPERATEPROMPTX,ENVELOPERATEPROMPTY,ePlain);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Beats Per Minute:",17,
			BEATSPERMINPROMPTX,BEATSPERMINPROMPTY,ePlain);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Inverse Volume:",15,
			VOLUMEPROMPTX,VOLUMEPROMPTY,ePlain);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Scanning Gap:",13,
			SCANNINGGAPPROMPTX,SCANNINGGAPPROMPTY,ePlain);
		DrawTextLine(Window->ScreenID,GetScreenFont(),9,"Buffer Seconds:",15,
			BUFFERDURATIONPROMPTX,BUFFERDURATIONPROMPTY,ePlain);
	}


typedef enum
	{
		eCancelled EXECUTE(= -21985),
		eDontPlay,
		ePlayToDevice,
		ePlayToDisk
	} CommandType;


/* show the play prefs dialog (which also allows the user to play) */
void								DoPlayPrefsDialog(struct MainWindowRec* MainWindow,
											struct TrackListRec* TrackList)
	{
		WindowRec*				Window;
		ArrayRec*					ArrayTemp;
		long							Scan;
		long							Limit;
		MyBoolean					LoopFlag;
		TextEditRec*			ActiveTextEdit;
		CommandType				Operation EXECUTE(= (CommandType)-31342);
		char*							StringTemp;

		CheckPtrExistence(MainWindow);

		Window = (WindowRec*)AllocPtrCanFail(sizeof(WindowRec),"WindowRec");
		if (Window == NIL)
			{
			 FailurePoint1:
				AlertHalt("There is not enough memory available to display the playback "
					"dialog box.",NIL);
				return;
			}

		Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
			eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINXSIZE),
			DialogTopEdge(WINYSIZE),WINXSIZE,WINYSIZE,
			(void (*)(void*))&RedrawTheWindow,Window);
		if (Window->ScreenID == NIL)
			{
			 FailurePoint2:
				ReleasePtr((char*)Window);
				goto FailurePoint1;
			}
		SetWindowName(Window->ScreenID,"Play Parameters");

		Window->TrackActivationList = NewStringList(Window->ScreenID,TRACKLISTX,
			TRACKLISTY,TRACKLISTWIDTH,TRACKLISTHEIGHT,GetScreenFont(),9,
			StringListDoAllowMultipleSelection,"Tracks to Play:");
		if (Window->TrackActivationList == NIL)
			{
			 FailurePoint3:
				KillWindow(Window->ScreenID);
				goto FailurePoint2;
			}
		EnableStringList(Window->TrackActivationList);
		ArrayTemp = TrackListGetListOfAllTracks(TrackList);
		if (ArrayTemp == NIL)
			{
			 FailurePoint4:
				DisposeStringList(Window->TrackActivationList);
				goto FailurePoint3;
			}
		Limit = ArrayGetLength(ArrayTemp);
		for (Scan = 0; Scan < Limit; Scan += 1)
			{
				char*							TrackName;
				TrackObjectRec*		TheTrackObject;
				char*							TrackNameNullTerminated;

				TheTrackObject = (TrackObjectRec*)ArrayGetElement(ArrayTemp,Scan);
				TrackName = TrackObjectGetNameCopy(TheTrackObject);
				if (TrackName == NIL)
					{
					 FailurePoint4a:
						DisposeArray(ArrayTemp);
						goto FailurePoint4;
					}
				TrackNameNullTerminated = BlockToStringCopy(TrackName);
				if (TrackNameNullTerminated == NIL)
					{
					 FailurePoint4b:
						ReleasePtr(TrackName);
						goto FailurePoint4a;
					}
				if (!InsertStringListElement(Window->TrackActivationList,
					TrackNameNullTerminated,NIL,TheTrackObject,False))
					{
					 FailurePoint4c:
						ReleasePtr(TrackNameNullTerminated);
						goto FailurePoint4b;
					}
				if (TrackObjectShouldItBePlayed(TheTrackObject))
					{
						SelectStringListElement(Window->TrackActivationList,TheTrackObject);
					}
				ReleasePtr(TrackNameNullTerminated);
				ReleasePtr(TrackName);
			}
		DisposeArray(ArrayTemp);

		Window->SelectAllButton = NewSimpleButton(Window->ScreenID,"Select All",
			SELECTALLBUTTONX,SELECTALLBUTTONY,SELECTALLBUTTONWIDTH,SELECTALLBUTTONHEIGHT);
		if (Window->SelectAllButton == NIL)
			{
			 FailurePoint5:
				goto FailurePoint4;
			}

		Window->SelectNoneButton = NewSimpleButton(Window->ScreenID,"Deselect All",
			SELECTNONEBUTTONX,SELECTNONEBUTTONY,SELECTNONEBUTTONWIDTH,SELECTNONEBUTTONHEIGHT);
		if (Window->SelectNoneButton == NIL)
			{
			 FailurePoint6:
				DisposeSimpleButton(Window->SelectAllButton);
				goto FailurePoint5;
			}

		Window->CancelButton = NewSimpleButton(Window->ScreenID,"Cancel",
			CANCELBUTTONX,CANCELBUTTONY,CANCELBUTTONWIDTH,CANCELBUTTONHEIGHT);
		if (Window->CancelButton == NIL)
			{
			 FailurePoint7:
				DisposeSimpleButton(Window->SelectNoneButton);
				goto FailurePoint6;
			}

		Window->DontPlayButton = NewSimpleButton(Window->ScreenID,"Done",
			DONTPLAYBUTTONX,DONTPLAYBUTTONY,DONTPLAYBUTTONWIDTH,DONTPLAYBUTTONHEIGHT);
		if (Window->DontPlayButton == NIL)
			{
			 FailurePoint8:
				DisposeSimpleButton(Window->CancelButton);
				goto FailurePoint7;
			}

		Window->PlayAudioButton = NewSimpleButton(Window->ScreenID,"Play To Audio",
			PLAYAUDIOBUTTONX,PLAYAUDIOBUTTONY,PLAYAUDIOBUTTONWIDTH,PLAYAUDIOBUTTONHEIGHT);
		if (Window->PlayAudioButton == NIL)
			{
			 FailurePoint9:
				DisposeSimpleButton(Window->DontPlayButton);
				goto FailurePoint8;
			}

		Window->PlayDiskButton = NewSimpleButton(Window->ScreenID,"Play To Disk",
			PLAYDISKBUTTONX,PLAYDISKBUTTONY,PLAYDISKBUTTONWIDTH,PLAYDISKBUTTONHEIGHT);
		if (Window->PlayDiskButton == NIL)
			{
			 FailurePoint10:
				DisposeSimpleButton(Window->PlayAudioButton);
				goto FailurePoint9;
			}

		Window->SampleRateEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,SAMPLERATEEDITX,SAMPLERATEEDITY,SAMPLERATEEDITWIDTH,
			SAMPLERATEEDITHEIGHT);
		if (Window->SampleRateEdit == NIL)
			{
			 FailurePoint11:
				DisposeSimpleButton(Window->PlayDiskButton);
				goto FailurePoint10;
			}
		StringTemp = IntegerToString(MainWindowGetSamplingRate(MainWindow));
		if (StringTemp == NIL)
			{
			 FailurePoint12:
				DisposeTextEdit(Window->SampleRateEdit);
				goto FailurePoint11;
			}
		TextEditNewRawData(Window->SampleRateEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->EnvelopeRateEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,ENVELOPERATEEDITX,ENVELOPERATEEDITY,ENVELOPERATEEDITWIDTH,
			ENVELOPERATEEDITHEIGHT);
		if (Window->EnvelopeRateEdit == NIL)
			{
			 FailurePoint13:
				goto FailurePoint12;
			}
		StringTemp = IntegerToString(MainWindowGetEnvelopeRate(MainWindow));
		if (StringTemp == NIL)
			{
			 FailurePoint14:
				DisposeTextEdit(Window->EnvelopeRateEdit);
				goto FailurePoint13;
			}
		TextEditNewRawData(Window->EnvelopeRateEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->BeatsPerMinEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,BEATSPERMINEDITX,BEATSPERMINEDITY,BEATSPERMINEDITWIDTH,
			BEATSPERMINEDITHEIGHT);
		if (Window->BeatsPerMinEdit == NIL)
			{
			 FailurePoint15:
				goto FailurePoint14;
			}
		StringTemp = LongDoubleToString(MainWindowGetBeatsPerMinute(MainWindow),7,1e-4,1e6);
		if (StringTemp == NIL)
			{
			 FailurePoint16:
				DisposeTextEdit(Window->BeatsPerMinEdit);
				goto FailurePoint15;
			}
		TextEditNewRawData(Window->BeatsPerMinEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->VolumeEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,VOLUMEEDITX,VOLUMEEDITY,VOLUMEEDITWIDTH,VOLUMEEDITHEIGHT);
		if (Window->VolumeEdit == NIL)
			{
			 FailurePoint17:
				goto FailurePoint16;
			}
		StringTemp = LongDoubleToString(MainWindowGetVolumeScaling(MainWindow),7,1e-4,1e6);
		if (StringTemp == NIL)
			{
			 FailurePoint18:
				DisposeTextEdit(Window->VolumeEdit);
				goto FailurePoint17;
			}
		TextEditNewRawData(Window->VolumeEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->Bits8Button = NewRadioButton(Window->ScreenID,"8-Bit Output",
			BITS8BUTTONX,BITS8BUTTONY,BITS8BUTTONWIDTH,BITS8BUTTONHEIGHT);
		if (Window->Bits8Button == NIL)
			{
			 FailurePoint19:
				goto FailurePoint18;
			}

		Window->Bits16Button = NewRadioButton(Window->ScreenID,"16-Bit Output",
			BITS16BUTTONX,BITS16BUTTONY,BITS16BUTTONWIDTH,BITS16BUTTONHEIGHT);
		if (Window->Bits16Button == NIL)
			{
			 FailurePoint20:
				DisposeRadioButton(Window->Bits8Button);
				goto FailurePoint19;
			}

		Window->Bits24Button = NewRadioButton(Window->ScreenID,"24-Bit Output",
			BITS24BUTTONX,BITS24BUTTONY,BITS24BUTTONWIDTH,BITS24BUTTONHEIGHT);
		if (Window->Bits24Button == NIL)
			{
			 FailurePoint21:
				DisposeRadioButton(Window->Bits16Button);
				goto FailurePoint20;
			}

		Window->Bits32Button = NewRadioButton(Window->ScreenID,"32-Bit Output",
			BITS32BUTTONX,BITS32BUTTONY,BITS32BUTTONWIDTH,BITS32BUTTONHEIGHT);
		if (Window->Bits32Button == NIL)
			{
			 FailurePoint22:
				DisposeRadioButton(Window->Bits24Button);
				goto FailurePoint21;
			}

		switch (MainWindowGetOutputNumBits(MainWindow))
			{
				default:
					EXECUTE(PRERR(ForceAbort,
						"DoPlayPrefsDialog:  bad num bits value from MainWindow"));
					break;
				case eOutput8Bits:
					SetRadioButtonState(Window->Bits8Button,True);
					break;
				case eOutput16Bits:
					SetRadioButtonState(Window->Bits16Button,True);
					break;
				case eOutput24Bits:
					SetRadioButtonState(Window->Bits24Button,True);
					break;
				case eOutput32Bits:
					SetRadioButtonState(Window->Bits32Button,True);
					break;
			}

		Window->StereoButton = NewRadioButton(Window->ScreenID,"Stereo",
			STEREOBUTTONX,STEREOBUTTONY,STEREOBUTTONWIDTH,STEREOBUTTONHEIGHT);
		if (Window->StereoButton == NIL)
			{
			 FailurePoint23:
				DisposeRadioButton(Window->Bits32Button);
				goto FailurePoint22;
			}

		Window->MonoButton = NewRadioButton(Window->ScreenID,"Mono",
			MONOBUTTONX,MONOBUTTONY,MONOBUTTONWIDTH,MONOBUTTONHEIGHT);
		if (Window->MonoButton == NIL)
			{
			 FailurePoint24:
				DisposeRadioButton(Window->StereoButton);
				goto FailurePoint23;
			}

		if (MainWindowGetStereo(MainWindow))
			{
				SetRadioButtonState(Window->StereoButton,True);
			}
		 else
			{
				SetRadioButtonState(Window->MonoButton,True);
			}

		Window->InterpTimeButton = NewCheckBox(Window->ScreenID,"Interpolate Over Time",
			INTERPTIMEBUTTONX,INTERPTIMEBUTTONY,INTERPTIMEBUTTONWIDTH,INTERPTIMEBUTTONHEIGHT);
		if (Window->InterpTimeButton == NIL)
			{
			 FailurePoint25:
				DisposeRadioButton(Window->MonoButton);
				goto FailurePoint24;
			}
		SetCheckBoxState(Window->InterpTimeButton,
			MainWindowGetInterpolationOverTime(MainWindow));

		Window->InterpWaveButton = NewCheckBox(Window->ScreenID,"Interpolate Across Waves",
			INTERPWAVEBUTTONX,INTERPWAVEBUTTONY,INTERPWAVEBUTTONWIDTH,INTERPWAVEBUTTONHEIGHT);
		if (Window->InterpWaveButton == NIL)
			{
			 FailurePoint26:
				DisposeCheckBox(Window->InterpTimeButton);
				goto FailurePoint25;
			}
		SetCheckBoxState(Window->InterpWaveButton,
			MainWindowGetInterpolationAcrossWaves(MainWindow));

		Window->ScanningGapEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,SCANNINGGAPEDITX,SCANNINGGAPEDITY,SCANNINGGAPEDITWIDTH,
			SCANNINGGAPEDITHEIGHT);
		if (Window->ScanningGapEdit == NIL)
			{
			 FailurePoint27:
				DisposeCheckBox(Window->InterpWaveButton);
				goto FailurePoint26;
			}
		StringTemp = LongDoubleToString(MainWindowGetScanningGap(MainWindow),7,1e-4,1e6);
		if (StringTemp == NIL)
			{
			 FailurePoint28:
				DisposeTextEdit(Window->ScanningGapEdit);
				goto FailurePoint27;
			}
		TextEditNewRawData(Window->ScanningGapEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->DurationWidthEdit = NewTextEdit(Window->ScreenID,eTENoScrollBars,
			GetScreenFont(),9,BUFFERDURATIONEDITX,BUFFERDURATIONEDITY,BUFFERDURATIONWIDTH,
			BUFFERDURATIONHEIGHT);
		if (Window->DurationWidthEdit == NIL)
			{
			 FailurePoint29:
				goto FailurePoint28;
			}
		StringTemp = LongDoubleToString(MainWindowGetBufferDuration(MainWindow),5,1e-4,1e6);
		if (StringTemp == NIL)
			{
			 FailurePoint30:
				DisposeTextEdit(Window->DurationWidthEdit);
				goto FailurePoint29;
			}
		TextEditNewRawData(Window->DurationWidthEdit,StringTemp,SYSTEMLINEFEED);
		ReleasePtr(StringTemp);

		Window->ClipWarnButton = NewCheckBox(Window->ScreenID,"Clip Warning",CLIPWARNBUTTONX,
			CLIPWARNBUTTONY,CLIPWARNBUTTONWIDTH,CLIPWARNBUTTONHEIGHT);
		if (Window->ClipWarnButton == NIL)
			{
			 FailurePoint31:
				goto FailurePoint30;
			}
		SetCheckBoxState(Window->ClipWarnButton,MainWindowGetClipWarning(MainWindow));


		ActiveTextEdit = Window->SampleRateEdit;
		EnableTextEditSelection(ActiveTextEdit);
		TextEditDoMenuSelectAll(ActiveTextEdit);
	 JumpBackIntoLoopPoint:
		LoopFlag = True;
		while (LoopFlag)
			{
				OrdType							X;
				OrdType							Y;
				ModifierFlags				Modifiers;
				MenuItemType*				MenuItem;
				char								KeyPress;

				switch (GetAnEvent(&X,&Y,&Modifiers,NIL,&MenuItem,&KeyPress))
					{
						default:
							break;
						case eCheckCursor:
							if (TextEditIBeamTest(Window->SampleRateEdit,X,Y)
								|| TextEditIBeamTest(Window->EnvelopeRateEdit,X,Y)
								|| TextEditIBeamTest(Window->BeatsPerMinEdit,X,Y)
								|| TextEditIBeamTest(Window->VolumeEdit,X,Y)
								|| TextEditIBeamTest(Window->ScanningGapEdit,X,Y)
								|| TextEditIBeamTest(Window->DurationWidthEdit,X,Y))
								{
									SetIBeamCursor();
								}
							 else
								{
									SetArrowCursor();
								}
							goto UpdateCursorPoint;
							break;
						case eNoEvent:
						 UpdateCursorPoint:
							TextEditUpdateCursor(ActiveTextEdit);
							break;
						case eMenuStarting:
							EnableMenuItem(mPaste);
							if (TextEditIsThereValidSelection(ActiveTextEdit))
								{
									EnableMenuItem(mCut);
									EnableMenuItem(mCopy);
									EnableMenuItem(mClear);
								}
							EnableMenuItem(mSelectAll);
							if (TextEditCanWeUndo(ActiveTextEdit))
								{
									EnableMenuItem(mUndo);
								}
							EnableMenuItem(mPlayAIFFFile);
							break;
						case eMenuCommand:
							if (MenuItem == mPaste)
								{
									TextEditDoMenuPaste(ActiveTextEdit);
								}
							else if (MenuItem == mCut)
								{
									TextEditDoMenuCut(ActiveTextEdit);
								}
							else if (MenuItem == mCopy)
								{
									TextEditDoMenuCopy(ActiveTextEdit);
								}
							else if (MenuItem == mClear)
								{
									TextEditDoMenuClear(ActiveTextEdit);
								}
							else if (MenuItem == mUndo)
								{
									TextEditDoMenuUndo(ActiveTextEdit);
									TextEditShowSelection(ActiveTextEdit);
								}
							else if (MenuItem == mSelectAll)
								{
									TextEditDoMenuSelectAll(ActiveTextEdit);
								}
							else if (MenuItem == mPlayAIFFFile)
								{
									PlayAIFFFile();
								}
							else
								{
									EXECUTE(PRERR(AllowResume,
										"DoPlayPrefsDialog: Undefined menu option chosen"));
								}
							break;
						case eKeyPressed:
							if (KeyPress == 13)
								{
									/* no default button */
								}
							else if (KeyPress == 9)
								{
									DisableTextEditSelection(ActiveTextEdit);
									if ((eShiftKey & Modifiers) == 0)
										{
											/* tab forwards */
											if (ActiveTextEdit == Window->SampleRateEdit)
												{
													ActiveTextEdit = Window->EnvelopeRateEdit;
												}
											else if (ActiveTextEdit == Window->EnvelopeRateEdit)
												{
													ActiveTextEdit = Window->BeatsPerMinEdit;
												}
											else if (ActiveTextEdit == Window->BeatsPerMinEdit)
												{
													ActiveTextEdit = Window->VolumeEdit;
												}
											else if (ActiveTextEdit == Window->VolumeEdit)
												{
													ActiveTextEdit = Window->ScanningGapEdit;
												}
											else if (ActiveTextEdit == Window->ScanningGapEdit)
												{
													ActiveTextEdit = Window->DurationWidthEdit;
												}
											else
												{
													ActiveTextEdit = Window->SampleRateEdit;
												}
										}
									 else
										{
											/* tab backwards */
											if (ActiveTextEdit == Window->DurationWidthEdit)
												{
													ActiveTextEdit = Window->ScanningGapEdit;
												}
											if (ActiveTextEdit == Window->ScanningGapEdit)
												{
													ActiveTextEdit = Window->VolumeEdit;
												}
											else if (ActiveTextEdit == Window->VolumeEdit)
												{
													ActiveTextEdit = Window->BeatsPerMinEdit;
												}
											else if (ActiveTextEdit == Window->BeatsPerMinEdit)
												{
													ActiveTextEdit = Window->EnvelopeRateEdit;
												}
											else if (ActiveTextEdit == Window->EnvelopeRateEdit)
												{
													ActiveTextEdit = Window->SampleRateEdit;
												}
											else
												{
													ActiveTextEdit = Window->DurationWidthEdit;
												}
										}
									TextEditDoMenuSelectAll(ActiveTextEdit);
									EnableTextEditSelection(ActiveTextEdit);
								}
							else if (KeyPress == eCancelKey)
								{
									/* FlashButton(Window->CancelButton); */
									/* Operation = eCancelled; */
									/* LoopFlag = False; */
								}
							else
								{
									TextEditDoKeyPressed(ActiveTextEdit,KeyPress,Modifiers);
								}
							break;
						case eMouseDown:
							if (SimpleButtonHitTest(Window->CancelButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->CancelButton,X,Y,NIL,NIL))
										{
											Operation = eCancelled;
											LoopFlag = False;
										}
								}
							else if (SimpleButtonHitTest(Window->DontPlayButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->DontPlayButton,X,Y,NIL,NIL))
										{
											Operation = eDontPlay;
											LoopFlag = False;
										}
								}
							else if (SimpleButtonHitTest(Window->PlayAudioButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->PlayAudioButton,X,Y,NIL,NIL))
										{
											Operation = ePlayToDevice;
											LoopFlag = False;
										}
								}
							else if (SimpleButtonHitTest(Window->PlayDiskButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->PlayDiskButton,X,Y,NIL,NIL))
										{
											Operation = ePlayToDisk;
											LoopFlag = False;
										}
								}
							else if (TextEditHitTest(Window->SampleRateEdit,X,Y))
								{
									if (ActiveTextEdit != Window->SampleRateEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->SampleRateEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (TextEditHitTest(Window->EnvelopeRateEdit,X,Y))
								{
									if (ActiveTextEdit != Window->EnvelopeRateEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->EnvelopeRateEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (TextEditHitTest(Window->BeatsPerMinEdit,X,Y))
								{
									if (ActiveTextEdit != Window->BeatsPerMinEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->BeatsPerMinEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (TextEditHitTest(Window->VolumeEdit,X,Y))
								{
									if (ActiveTextEdit != Window->VolumeEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->VolumeEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (TextEditHitTest(Window->ScanningGapEdit,X,Y))
								{
									if (ActiveTextEdit != Window->ScanningGapEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->ScanningGapEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (TextEditHitTest(Window->DurationWidthEdit,X,Y))
								{
									if (ActiveTextEdit != Window->DurationWidthEdit)
										{
											DisableTextEditSelection(ActiveTextEdit);
											ActiveTextEdit = Window->DurationWidthEdit;
											EnableTextEditSelection(ActiveTextEdit);
										}
									TextEditDoMouseDown(ActiveTextEdit,X,Y,Modifiers);
								}
							else if (StringListHitTest(Window->TrackActivationList,X,Y))
								{
									/* double-click means nothing */
									StringListMouseDown(Window->TrackActivationList,X,Y,Modifiers);
								}
							else if (SimpleButtonHitTest(Window->SelectAllButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->SelectAllButton,X,Y,NIL,NIL))
										{
											ArrayTemp = TrackListGetListOfAllTracks(TrackList);
											if (ArrayTemp != NIL)
												{
													Limit = ArrayGetLength(ArrayTemp);
													for (Scan = 0; Scan < Limit; Scan += 1)
														{
															TrackObjectRec*		TheTrackObject;

															TheTrackObject = (TrackObjectRec*)ArrayGetElement(
																ArrayTemp,Scan);
															SelectStringListElement(Window->TrackActivationList,
																TheTrackObject);
														}
													DisposeArray(ArrayTemp);
												}
										}
								}
							else if (SimpleButtonHitTest(Window->SelectNoneButton,X,Y))
								{
									if (SimpleButtonMouseDown(Window->SelectNoneButton,X,Y,NIL,NIL))
										{
											DeselectAllStringListElements(Window->TrackActivationList);
										}
								}
							else if (RadioButtonHitTest(Window->Bits8Button,X,Y))
								{
									if (RadioButtonMouseDown(Window->Bits8Button,X,Y))
										{
											SetRadioButtonState(Window->Bits16Button,False);
											SetRadioButtonState(Window->Bits24Button,False);
											SetRadioButtonState(Window->Bits32Button,False);
										}
								}
							else if (RadioButtonHitTest(Window->Bits16Button,X,Y))
								{
									if (RadioButtonMouseDown(Window->Bits16Button,X,Y))
										{
											SetRadioButtonState(Window->Bits8Button,False);
											SetRadioButtonState(Window->Bits24Button,False);
											SetRadioButtonState(Window->Bits32Button,False);
										}
								}
							else if (RadioButtonHitTest(Window->Bits24Button,X,Y))
								{
									if (RadioButtonMouseDown(Window->Bits24Button,X,Y))
										{
											SetRadioButtonState(Window->Bits8Button,False);
											SetRadioButtonState(Window->Bits16Button,False);
											SetRadioButtonState(Window->Bits32Button,False);
										}
								}
							else if (RadioButtonHitTest(Window->Bits32Button,X,Y))
								{
									if (RadioButtonMouseDown(Window->Bits32Button,X,Y))
										{
											SetRadioButtonState(Window->Bits8Button,False);
											SetRadioButtonState(Window->Bits16Button,False);
											SetRadioButtonState(Window->Bits24Button,False);
										}
								}
							else if (RadioButtonHitTest(Window->StereoButton,X,Y))
								{
									if (RadioButtonMouseDown(Window->StereoButton,X,Y))
										{
											SetRadioButtonState(Window->MonoButton,False);
										}
								}
							else if (RadioButtonHitTest(Window->MonoButton,X,Y))
								{
									if (RadioButtonMouseDown(Window->MonoButton,X,Y))
										{
											SetRadioButtonState(Window->StereoButton,False);
										}
								}
							else if (CheckBoxHitTest(Window->InterpTimeButton,X,Y))
								{
									CheckBoxMouseDown(Window->InterpTimeButton,X,Y);
									if (!GetCheckBoxState(Window->InterpTimeButton))
										{
											SetCheckBoxState(Window->InterpWaveButton,False);
										}
								}
							else if (CheckBoxHitTest(Window->InterpWaveButton,X,Y))
								{
									CheckBoxMouseDown(Window->InterpWaveButton,X,Y);
									if (GetCheckBoxState(Window->InterpWaveButton))
										{
											SetCheckBoxState(Window->InterpTimeButton,True);
										}
								}
							else if (CheckBoxHitTest(Window->ClipWarnButton,X,Y))
								{
									CheckBoxMouseDown(Window->ClipWarnButton,X,Y);
								}
							break;
					}
			}

		{
			long							SamplingRate;
			long							EnvelopeRate;
			double						DefaultBeatsPerMinute;
			double						VolumeScaling;
			OutputNumBitsType	NumberOfBits;
			MyBoolean					StereoPlayback;
			MyBoolean					TimeInterpolation;
			MyBoolean					WaveInterpolation;
			double						ScanningGap;
			double						DurationWidth;
			ArrayRec*					PlayTrackList;
			MyBoolean					ClipWarning;

			char*							StringTemp;
			MyBoolean					MemOutErrorOccurred = False;

			StringTemp = TextEditGetRawData(Window->SampleRateEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					SamplingRate = StringToInteger(StringTemp,PtrSize(StringTemp));
					if (SamplingRate < MINSAMPLINGRATE)
						{
							SamplingRate = MINSAMPLINGRATE;
						}
					if (SamplingRate > MAXSAMPLINGRATE)
						{
							SamplingRate = MAXSAMPLINGRATE;
						}
					ReleasePtr(StringTemp);
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			StringTemp = TextEditGetRawData(Window->EnvelopeRateEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					EnvelopeRate = StringToInteger(StringTemp,PtrSize(StringTemp));
					ReleasePtr(StringTemp);
					if (EnvelopeRate < 1)
						{
							EnvelopeRate = 1;
						}
					if (EnvelopeRate > MAXSAMPLINGRATE)
						{
							EnvelopeRate = MAXSAMPLINGRATE;
						}
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			StringTemp = TextEditGetRawData(Window->BeatsPerMinEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					DefaultBeatsPerMinute = StringToLongDouble(StringTemp,PtrSize(StringTemp));
					ReleasePtr(StringTemp);
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			StringTemp = TextEditGetRawData(Window->VolumeEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					VolumeScaling = StringToLongDouble(StringTemp,PtrSize(StringTemp));
					ReleasePtr(StringTemp);
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			StringTemp = TextEditGetRawData(Window->ScanningGapEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					ScanningGap = StringToLongDouble(StringTemp,PtrSize(StringTemp));
					ReleasePtr(StringTemp);
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			StringTemp = TextEditGetRawData(Window->DurationWidthEdit,SYSTEMLINEFEED);
			if (StringTemp != NIL)
				{
					DurationWidth = StringToLongDouble(StringTemp,PtrSize(StringTemp));
					ReleasePtr(StringTemp);
				}
			 else
				{
					MemOutErrorOccurred = True;
				}

			if (GetRadioButtonState(Window->Bits8Button))
				{
					NumberOfBits = eOutput8Bits;
				}
			else if (GetRadioButtonState(Window->Bits16Button))
				{
					NumberOfBits = eOutput16Bits;
				}
			else if (GetRadioButtonState(Window->Bits24Button))
				{
					NumberOfBits = eOutput24Bits;
				}
			else if (GetRadioButtonState(Window->Bits32Button))
				{
					NumberOfBits = eOutput32Bits;
				}
			else
				{
					EXECUTE(PRERR(ForceAbort,"DoPlayPrefsDialog:  bits buttons problem"));
				}

			if (GetRadioButtonState(Window->StereoButton))
				{
					StereoPlayback = True;
				}
			else if (GetRadioButtonState(Window->MonoButton))
				{
					StereoPlayback = False;
				}
			else
				{
					EXECUTE(PRERR(ForceAbort,"DoPlayPrefsDialog:  stereo buttons problem"));
				}

			TimeInterpolation = GetCheckBoxState(Window->InterpTimeButton);

			WaveInterpolation = GetCheckBoxState(Window->InterpWaveButton);

			ClipWarning = GetCheckBoxState(Window->ClipWarnButton);

			PlayTrackList = GetListOfSelectedItems(Window->TrackActivationList);
			if (PlayTrackList == NIL)
				{
					MemOutErrorOccurred = True;
				}

			if (MemOutErrorOccurred)
				{
					AlertHalt("There is not enough memory available to continue.",NIL);
				}
			 else
				{
					long								Scan;
					ArrayRec*						TotalTrackList;

					switch (Operation)
						{
							default:
								EXECUTE(PRERR(ForceAbort,"DoPlayPrefsDialog:  Operation was not set"));
								break;
							case eCancelled:
								/* do nothing, including not saving the parameters */
								DisposeArray(PlayTrackList);
								break;
							case eDontPlay:
								PutMainWindowSamplingRate(MainWindow,SamplingRate);
								PutMainWindowEnvelopeRate(MainWindow,EnvelopeRate);
								PutMainWindowBeatsPerMinute(MainWindow,DefaultBeatsPerMinute);
								PutMainWindowVolumeScaling(MainWindow,VolumeScaling);
								PutMainWindowOutputNumBits(MainWindow,NumberOfBits);
								PutMainWindowStereo(MainWindow,StereoPlayback);
								PutMainWindowInterpolationOverTime(MainWindow,TimeInterpolation);
								PutMainWindowInterpolationAcrossWaves(MainWindow,WaveInterpolation);
								PutMainWindowScanningGap(MainWindow,ScanningGap);
								PutMainWindowBufferDuration(MainWindow,DurationWidth);
								PutMainWindowClipWarning(MainWindow,ClipWarning);
								/* first, we should save the information in PlayTrackList */
								TotalTrackList = TrackListGetListOfAllTracks(TrackList);
								if (TotalTrackList != NIL)
									{
										for (Scan = 0; Scan < ArrayGetLength(TotalTrackList); Scan += 1)
											{
												TrackObjectRec*		OneTrack;

												OneTrack = (TrackObjectRec*)ArrayGetElement(TotalTrackList,Scan);
												CheckPtrExistence(OneTrack);
												if (-1 != ArrayFindElement(PlayTrackList,OneTrack))
													{
														/* it's marked to be played */
														if (!TrackObjectShouldItBePlayed(OneTrack))
															{
																/* it has to be changed */
																ChangeTrackObjectShouldBePlayed(OneTrack,True);
															}
													}
												 else
													{
														/* it's marked to not be played */
														if (TrackObjectShouldItBePlayed(OneTrack))
															{
																/* it has to be changed */
																ChangeTrackObjectShouldBePlayed(OneTrack,False);
															}
													}
											}
										DisposeArray(TotalTrackList);
									}
								DisposeArray(PlayTrackList);
								break;
							case ePlayToDevice:
								/* play to the audio device, but don't save the parameters */
								if (ArrayGetLength(PlayTrackList) == 0)
									{
										AlertHalt("No tracks are selected.",NIL);
									}
								 else
									{
										SynthToSoundDevice(MainWindow,PlayTrackList,
											(TrackObjectRec*)ArrayGetElement(PlayTrackList,0),0,SamplingRate,
											EnvelopeRate,StereoPlayback,Double2LargeBCD(DefaultBeatsPerMinute),
											Double2LargeBCD(VolumeScaling),TimeInterpolation,
											WaveInterpolation,Double2LargeBCD(ScanningGap),NumberOfBits,
											Double2LargeBCD(DurationWidth),
											ClipWarning && ((eOptionKey & CheckModifiers()) == 0));
									}
								DisposeArray(PlayTrackList);
								goto JumpBackIntoLoopPoint;
							case ePlayToDisk:
								/* play to disk, but don't save the parameters */
								if (ArrayGetLength(PlayTrackList) == 0)
									{
										AlertHalt("No tracks are selected.",NIL);
									}
								 else
									{
										SynthToAIFFFile(MainWindow,PlayTrackList,
											(TrackObjectRec*)ArrayGetElement(PlayTrackList,0),0,SamplingRate,
											EnvelopeRate,StereoPlayback,Double2LargeBCD(DefaultBeatsPerMinute),
											Double2LargeBCD(VolumeScaling),TimeInterpolation,
											WaveInterpolation,Double2LargeBCD(ScanningGap),NumberOfBits,
											ClipWarning && ((eOptionKey & CheckModifiers()) == 0));
									}
								DisposeArray(PlayTrackList);
								goto JumpBackIntoLoopPoint;
						}
				}
		}

		DisposeStringList(Window->TrackActivationList);
		DisposeSimpleButton(Window->SelectAllButton);
		DisposeSimpleButton(Window->SelectNoneButton);
		DisposeSimpleButton(Window->CancelButton);
		DisposeSimpleButton(Window->DontPlayButton);
		DisposeSimpleButton(Window->PlayAudioButton);
		DisposeSimpleButton(Window->PlayDiskButton);
		DisposeTextEdit(Window->SampleRateEdit);
		DisposeTextEdit(Window->EnvelopeRateEdit);
		DisposeTextEdit(Window->BeatsPerMinEdit);
		DisposeTextEdit(Window->VolumeEdit);
		DisposeTextEdit(Window->ScanningGapEdit);
		DisposeTextEdit(Window->DurationWidthEdit);
		DisposeRadioButton(Window->Bits8Button);
		DisposeRadioButton(Window->Bits16Button);
		DisposeRadioButton(Window->Bits24Button);
		DisposeRadioButton(Window->Bits32Button);
		DisposeRadioButton(Window->StereoButton);
		DisposeRadioButton(Window->MonoButton);
		DisposeCheckBox(Window->InterpTimeButton);
		DisposeCheckBox(Window->InterpWaveButton);
		DisposeCheckBox(Window->ClipWarnButton);
		KillWindow(Window->ScreenID);
		ReleasePtr((char*)Window);
		/* no return value */
	}
