setWriter

Help Contents Communication File opening setWriter
setReader Reader

setWriter filename
setWriter anintarray
setWriter anint16array


command. Makes the named file, anintarray or anint16array the write stream, used for print, etc. The file must already be open with openWrite, openAppend, or openUpdate. If the input is the empty list, then the write stream becomes the terminal, as usual. Changing the write stream does not close the file that was previously the write stream, so it is possible to alternate between files. On writing to anintarray or anint16array it need not to be opened before this command.

Examples:

openWrite "temp.txt
setWriter "temp.txt
pr [This is a temp file]
setWriter []
close "temp.txt

to makewav3
	rate=44100
	size=rate
	wavHeaderType=(list
		[ChunkID Word RIFF]
		[wavfilesize Int]
		[RIFFtype Word 4]	;the last item is the string length

		[formatChunkID Word fmt\ ]
		[formatChunkSize Int 16]
		[compressionCode Int16 1]
		[NumberOfChannels Int16 1]
		(list "SampleRate "Int rate)
		(list "BytesPerSecond "Int rate*2)
		[BlockAlign Int16 2]
		[BitsPerSample Int16 16]

		[DataChunkID word data]
		(list "DataChunkSize "Int size*2)
	)
	wavHeader=struct wavHeaderType
	wavsize=(SizeOf wavHeader)+size*2
	wavHeader'RIFFtype=[WAVE]	;example for setting a string
	wavHeader'wavfilesize=wavsize
	pr wavHeader
	wav=Int16Array int wavsize/2
	setWriter wav
	typeBin wavHeader
	repeat size
	[	phi=360*repcount/rate
		typebin Int16 16383*( (sin 40*phi)
							- (sin 41*phi) )
	]
	setWriter []
	setReader wav
	wh=readStructBin wavHeaderType
	pr wh
	setReader []
	playWave wav 1+8
	ignore readChar
	playWave [] 0
end

Examples:

References:

setReader Reader