'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 13 August 2008 at 1:40:23 pm'!

!AIFFFileReader methodsFor: 'reading' stamp: 'jmv 8/13/2008 12:59'!
readFromFile: fileName mergeIfStereo: mergeFlag skipDataChunk: skipDataFlag
	"Read the AIFF file of the given name. See comment in readFromStream:mergeIfStereo:skipDataChunk:."
	"AIFFFileReader new readFromFile: 'test.aiff' mergeIfStereo: false skipDataChunk: true"

	| f |
	f _ (FileStream readOnlyFileNamed: fileName) binary.
	[ self readFromStream: f mergeIfStereo: mergeFlag skipDataChunk: skipDataFlag ]
		ensure: [ f close ]
! !


!AbstractSound methodsFor: 'file i/o' stamp: 'jmv 8/13/2008 13:00'!
storeAIFFOnFileNamed: fileName
	"Store this sound as a AIFF file of the given name."

	| f |
	f _ (FileStream fileNamed: fileName) binary.
	[ self storeAIFFSamplesOn: f ]
		ensure: [ f close ]
! !

!AbstractSound methodsFor: 'file i/o' stamp: 'jmv 8/13/2008 13:00'!
storeSunAudioOnFileNamed: fileName
	"Store this sound as an uncompressed Sun audio file of the given name."

	| f |
	f _ (FileStream fileNamed: fileName) binary.
	[ self storeSunAudioSamplesOn: f]
		ensure: [ f close ]! !

!AbstractSound methodsFor: 'file i/o' stamp: 'jmv 8/13/2008 13:00'!
storeWAVOnFileNamed: fileName
	"Store this sound as a 16-bit Windows WAV file of the given name."

	| f |
	f _ (FileStream fileNamed: fileName) binary.
	[ self storeWAVSamplesOn: f ]
		ensure: [ f close ]! !


!AbstractSound class methodsFor: 'sound library-file in/out' stamp: 'jmv 8/13/2008 13:01'!
fileInSoundLibraryNamed: fileName
	"File in the sound library with the given file name, and add its contents to the current sound library."

	| s newSounds |
	s _ FileStream oldFileNamed: fileName.
	[ newSounds _ s fileInObjectAndCode ]
		ensure: [ s close ].
	newSounds associationsDo: [:assoc | 
		self storeFiledInSound: assoc value named: assoc key].
	AbstractSound updateScorePlayers.
	Smalltalk garbageCollect.  "Large objects may have been released"
! !

!AbstractSound class methodsFor: 'sound library-file in/out' stamp: 'jmv 8/13/2008 13:02'!
fileOutSoundLibrary: aDictionary
	"File out the given dictionary, which is assumed to contain sound and instrument objects keyed by their names."
	"Note: This method is separated out so that one can file out edited sound libraries, as well as the system sound library. To make such a collection, you can inspect AbstractSound sounds and remove the items you don't want. Then do: 'AbstractSound fileOutSoundLibrary: self' from the Dictionary inspector."

	| fileName refStream |
	(aDictionary isKindOf: Dictionary)
		ifFalse: [self error: 'arg should be a dictionary of sounds'].
	fileName _ FillInTheBlank request: 'Sound library file name?'.
	fileName isEmptyOrNil ifTrue: [^ self].
	refStream _ SmartRefStream fileNamed: fileName, '.sounds'.
	[ refStream nextPut: aDictionary ]
		ensure: [ refStream close ]! !


!Archive methodsFor: 'archive operations' stamp: 'jmv 8/13/2008 13:02'!
writeToFileNamed: aFileName
	| stream |
	"Catch attempts to overwrite existing zip file"
	(self canWriteToFileNamed: aFileName)
		ifFalse: [ ^self error: (aFileName, ' is needed by one or more members in this archive') ].
	stream _ StandardFileStream forceNewFileNamed: aFileName.
	[ self writeTo: stream ]
		ensure: [ stream close ]! !

