'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992 on 6 June 1992 at 10:47:20 pm'!



!MusicMagnitude class methodsFor: 'examples'!

MODEExampleList
	"Answer a list of all of the example methods in the MODE categories"
	"MusicMagnitude MODEExampleList inspect"

	| aCollection |
	aCollection := OrderedCollection new.
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'Music-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'Music-']])
	do: [ :catName |
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				aCollection add: selectedClass class name , ' ' , selector ]]].
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'MusicUI-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'MusicUI-']])
	do: [ :catName | 
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				aCollection add: selectedClass class name , ' ' , selector ]]].
	^aCollection! !

!MusicMagnitude class methodsFor: 'examples'!

MODEExampleListView
	"Open a message list browser on all of the example methods in the MODE 
	categories--note the LeftShiftHack on the list view menu adding 'do it' 
	and 'browse class' items."
	"MusicMagnitude MODEExampleListView"

	| aCollection |
	aCollection := OrderedCollection new.
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'Music-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'Music-']])
	do: [ :catName |
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				aCollection add: selectedClass class name , ' ' , selector ]]].
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'MusicUI-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'MusicUI-']])
	do: [ :catName | 
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				aCollection add: selectedClass class name , ' ' , selector ]]].
	MethodListBrowser
		openListBrowserOn: aCollection 
		label: 'MODE 1.1 Examples'.  	"Browse collection."! !

!MusicMagnitude class methodsFor: 'examples'!

MODEExampleMenu
	"Start up a menu of the examples and execute the selection, 
		possibly inspecting the result."
	"MusicMagnitude MODEExampleMenu"

	| classes messages labels selection returnValue |
	classes := OrderedCollection new.
	messages := OrderedCollection new.
	labels := OrderedCollection new.
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'Music-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'Music-']])
	do: [ :catName |
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				(selector includes: $:) ifFalse:
					[labels add: (selectedClass name, ' ', selector).
					classes add: selectedClass name.
					messages add: selector]]]].
	selection := (PopUpMenu labelArray: labels) startUp.
	selection = 0 ifTrue: [^nil].
"	selection := DialogView show: (PopUpMenu labelArray: labels) 
			withLabel: 'MODE 1.1 Examples'.
	selection = nil ifTrue: [^nil]."
	returnValue := (Smalltalk at: (classes at: selection)) 
			perform: (messages at: selection).
	returnValue == nil ifFalse: 
		[(returnValue isKindOf: Behavior)
			ifTrue: [Transcript show: 'Returned: ', returnValue printString; cr]
			ifFalse: [returnValue inspect]]! !

!MusicMagnitude class methodsFor: 'examples'!

modeRootName
	"Answer the directory name of the base of the MODE release fileset."
	"You may want to edit this to './' if your image is in that directory."
	"MusicMagnitude modeRootName"

	^'./mode/'! !

!MusicMagnitude class methodsFor: 'examples'!

MODEUIExampleListView
	"Open a message list browser on all of the example methods in the MODE 
	categories--note the LeftShiftHack on the list view menu adding 'do it' 
	and 'browse class' items."
	"MusicMagnitude MODEUIExampleListView"

	| aCollection |
	aCollection := OrderedCollection new.
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'MusicUI-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'MusicUI-']])
	do: [ :catName | 
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				aCollection add: selectedClass class name , ' ' , selector ]]].
	MethodListBrowser
		openListBrowserOn: aCollection 
		label: 'MODE 1.1 Examples'.  	"Browse collection."! !

!MusicMagnitude class methodsFor: 'examples'!

MODEUIExampleMenu
	"Start up a menu of the UI examples and execute the selection, 
		possibly inspecting the result."
	"MusicMagnitude MODEUIExampleMenu"

	| classes messages labels selection returnValue |
	classes := OrderedCollection new.
	messages := OrderedCollection new.
	labels := OrderedCollection new.
	(Smalltalk organization categories select: [ :cat | | siz |
		siz := 'MusicUI-' size.
		(cat size >= siz) and: [(cat copyFrom: 1 to: siz) = 'MusicUI-']])
	do: [ :catName | 
		 (Smalltalk organization superclassOrder: catName) do:	"For all classes"
			[ :selectedClass | 		"If #examples category"
			(selectedClass class organization listAtCategoryNamed: #examples) do:
				[ :selector | 		"Collect selectors"
				(selector includes: $:) ifFalse:
					[labels add: (selectedClass name, ' ', selector).
					classes add: selectedClass name.
					messages add: selector]]]].
	selection := (PopUpMenu labelArray: labels) startUp.
	selection = 0 ifTrue: [^nil].
"	selection := DialogView show: (PopUpMenu labelArray: labels) 
			withLabel: 'MODE 1.1 Examples'.
	selection = nil ifTrue: [^nil].
"	returnValue := (Smalltalk at: (classes at: selection)) 
			perform: (messages at: selection).
	returnValue == nil ifFalse: 
		[(returnValue isKindOf: Behavior)
			ifTrue: [Transcript show: 'Returned: ', returnValue printString; cr]
			ifFalse: [returnValue inspect]]! !

!MusicMagnitude class methodsFor: 'examples'!

MusicConstantDictionary
	"Answer the global music constants (mostly icons)."
	"MusicMagnitude MusicConstantDictionary inspect"
	"Browser browseAllCallsOn:
		(Smalltalk associationAt: #MusicConstants)"

	^MusicConstants! !

!MusicMagnitude class methodsFor: 'examples'!

utilityMessages
	"Select these utilities, inspect..."
	
"	MusicMagnitude MusicConstantDictionary
	(Browser browseAllCallsOn:
		(Smalltalk associationAt: #MusicConstants))
	RemoteSocketServer allInstances
	Voices
	EventLists
	MIDIVoice allInstances
	MIDIDevice
	SunMIDIPort instanceCount
	MIDIPort instanceCount
	ProPort instanceCount
	SunMIDIPort allNotesOff
	MIDIPort allNotesOff
	ProPort allSoundOff
	SampledSound allSubInstances
	EventListEditor allSubInstances
	Undeclared		DependentsFields
	AbstractEvent allSubInstances size
	DisplayItem allSubInstances
	DisplayListView allSubInstances
	Semaphore allInstances
	Semaphore instanceCount
	Process instanceCount
	Process allInstances

"! !

!Duration class methodsFor: 'examples'!

example
	"Print a simple message to the transcript demonstrating the various types."
	"Duration example"

	| me |
	me := Duration value: 1/4.
	Transcript show: me printString; cr;
		show: me asMS printString; cr.
	me inspect! !

!Amplitude class methodsFor: 'examples'!

example
	"Print a simple message to the transcript demonstrating the various types."
	"SymbolicLoudness nameMap inspect"
	"Amplitude example"

	| me |
	me := Amplitude value: #mf.
	Transcript show: me printString; cr;
		show: me asRatio printString; cr;
		show: me asMIDI printString; cr.
	me inspect! !

!Pitch class methodsFor: 'examples'!

example
	"Print a simple message to the transcript demonstrating the various types."
	"SymbolicPitch nameMap inspect"
	"Pitch example"

	| me |
	me := Pitch value: 'c3'.
	Transcript show: me printString; cr;
		show: me asHertz printString; cr;
		show: me asMIDI printString; cr.
	me inspect! !

!Length class methodsFor: 'examples'!

example
	"Demonstrate the use of an OrdinalMagnitude with a scale of length."
	"Length example"

	| a b c d e f |		"define six values with names."
	Length useTable.
	a := Length value: #sip.
	b := Length value: #gasp.
	c := Length value: #focus.
	d := Length value: #inhale.
	e := Length value: #gesture.
	f := Length value: #breath.
					"put them in some order."
	a << b.	b << c.	c << d.	d << e.	e << f.
					"now ask some queries and let them extrapolate."
	Transcript show: '(f > e) ', (f > e) printString; cr.
	Transcript show: '(f > b) ', (f > b) printString; cr.
	Transcript show: '(f =? f) ', (f =? f) printString; cr.
	Transcript show: '(f =? a) ', (f =? a) printString; cr.
	Transcript show: '(f >= a) ', (f >= a) printString; cr.
	Transcript show: '(d >= b) ', (d >= b) printString; cr.
	Transcript show: '(b >= d) ', (b >= d) printString; cr.
	Transcript show: '(f < a) ', (f < a) printString; cr.
	Transcript show: '(a < f) ', (a < f) printString; cr.
					"inspect them if you hold down <LEFT-SHIFT>"
	InputState default  leftShiftDown ifTrue: [self halt].
	Length allInstances asSortedCollection inspect! !

!Sharpness class methodsFor: 'examples'!

example
	"Demonstrate the use of an OrdinalMagnitude with a scale of sharpness."
	"Sharpness example"

	| a b c d e f |		"define six values with names."
	a := Sharpness value: #soft.
	b := Sharpness value: #nasal.
	c := Sharpness value: #round.
	d := Sharpness value: #high.
	e := Sharpness value: #loud.
	f := Sharpness value: #shrill.
					"put them in some order."
	a << b.	b << c.	c << d.	d << e.	e << f.
					"now ask some queries and let them extrapolate."
	Transcript show: '(f > e) ', (f > e) printString; cr.
	Transcript show: '(f > b) ', (f > b) printString; cr.
	Transcript show: '(f =? f) ', (f =? f) printString; cr.
	Transcript show: '(f =? a) ', (f =? a) printString; cr.
	Transcript show: '(f >= a) ', (f >= a) printString; cr.
	Transcript show: '(d >= b) ', (d >= b) printString; cr.
	Transcript show: '(b >= d) ', (b >= d) printString; cr.
	Transcript show: '(f < a) ', (f < a) printString; cr.
	Transcript show: '(a < f) ', (a < f) printString; cr.
					"inspect them if you hold down <LEFT-SHIFT>"
	InputState default  leftShiftDown ifTrue: [self halt].
	Sharpness values inspect! !

!ConditionalDuration class methodsFor: 'examples'!

example
	"Print a simple message to the transcript demonstrating the various types."
	"ConditionalDuration example"

	| t0 t me |
	t0 := Time millisecondClockValue.		"get the time"
					"make a duration 'until the argument is > 3000'"
	me := ConditionalDuration value: [ :x | x > 3000].
	Transcript cr; show: t0 printString; cr.
					"use it to wait 3000 msec."
	me waitUntil: [Time millisecondClockValue - t0].
	t := Time millisecondClockValue.	
	Transcript show: (t - t0) printString; cr.
					"make a duration 'until 3 seconds from now'"
	me := ConditionalDuration value: [ :x | Time millisecondClockValue > (t + 3000)].
					"wait it out."
	me waitUntil: [].
	t := Time millisecondClockValue.	
	Transcript show: (t - t0) printString; cr.
	me inspect! !

!AbstractEvent class methodsFor: 'examples'!

eventInspectExample
	"Demonstrate the creation of an AEvent."
	"AbstractEvent example"

	((AbstractEvent new) color: #green; shape: #round) inspect! !

!AbstractEvent class methodsFor: 'examples'!

example
	"Demonstrate the creation of an AEvent."
	"AbstractEvent example inspect"

	^(AbstractEvent new) color: #green; shape: #round! !

!DurationEvent class methodsFor: 'examples'!

eventInspectExample
	"Demonstrate the creation of a DEvent."
	"DurationEvent example inspect"

	(DurationEvent dur: 250 msec voice: #flute) inspect! !

!DurationEvent class methodsFor: 'examples'!

example
	"Demonstrate the creation of a DEvent."
	"DurationEvent example"

	^DurationEvent dur: 250 msec voice: #flute! !

!EventList class methodsFor: 'examples'!

creationExamples
	"Select the expressions below one-at-a-time and inspect the results."

"	EventList named: (EventList nextName) 
		fromPitches: #(36 38 40 43 45).
"
	(EventList named: (EventList nextName) 
		fromStartTimes: #(0 500 1000 1500 2000 2500 3000)) inspect.

"	(440 Hz, 250 msec, (#voice -> #flute)), 
		((1/4) => (471 Hz, (1/4) beat, (#voice -> #flute)))"! !

!EventList class methodsFor: 'examples'!

randomExample
	"Create an event list with random data."
	"EventList randomExample"
	"PitchTimeView randomExample"
	"(EventList newNamed: #pRand)
			addAll: (EventList randomExample);
			addAll: (EventList randomExample)"

	| rand size arr1 arr2 arr3 arr4 |
	rand := Random new.
	size := 32.
	arr1 := Array new: size.
	arr2 := Array new: size.
	arr3 := Array new: size.
	arr4 := Array new: size.
	1 to: size do: [ :i | arr1 at: i put: (rand nextIntFrom: 200 to: 250)].
	1 to: size do: [ :i | arr2 at: i put: (rand nextIntFrom: 32 to: 80)].
	1 to: size do: [ :i | arr3 at: i put: (rand nextIntFrom: 1 to: 5)].
	1 to: size do: [ :i | arr4 at: i put: (rand nextIntFrom: 48 to: 60)].
	^EventList named: 'random1'  
		fromSelectors: #(duration: loudness: voice: pitch:) 
		values: (Array with: arr1 with: arr2 with: arr3 with: arr4)! !

!EventList class methodsFor: 'examples'!

randomExample: length
	"Create an event list with random data."
	"EventList randomExample: 200"
	"PitchTimeView randomExample"

	| rand arr1 arr2 arr3 arr4 |
	rand := Random new.
	arr1 := Array new: length.
	arr2 := Array new: length.
	arr3 := Array new: length.
	arr4 := Array new: length.
	1 to: length do: [ :i | arr1 at: i put: (rand nextIntFrom: 200 to: 250)].
	1 to: length do: [ :i | arr2 at: i put: (rand nextIntFrom: 32 to: 80)].
	1 to: length do: [ :i | arr3 at: i put: (rand nextIntFrom: 1 to: 5)].
	1 to: length do: [ :i | arr4 at: i put: (rand nextIntFrom: 48 to: 60)].
	^EventList named: 'random1'  
		fromSelectors: #(duration: loudness: voice: pitch:) 
		values: (Array with: arr1 with: arr2 with: arr3 with: arr4)! !

!EventList class methodsFor: 'examples'!

randomExample: length from: data
	"Create an event list with random data."
	"(EventList randomExample: 64 
		from: ((#duration: -> (100@200)), (#pitch: -> (36@60)),
				(#ampl: -> (48@64)), (#voice: -> (1@4)))) edit"

	| rand arr sels i |
	rand := Random new.
	arr := Array new: data size.
	sels := Array new: data size.
	i := 1.
	data associationsDo: [ :item | | a |
		a := Array new: length.
		1 to: length do: [ :c | 
			a at: c put: (rand nextIntFrom: item value x to: item value y)].
		arr at: i put: a.
		sels at: i put: item key.
		i := i + 1.].
	^EventList named: EventList nextName
		fromSelectors: sels 
		values: arr! !

!EventList class methodsFor: 'examples'!

randomSWSSExample
	"Create an event list with random data appropriate for software sound synthesis."
	"EventList randomSWSSExample edit"
	"(EventList newNamed: #sRand)
			addAll: (EventList randomSWSSExample);
			addAll: (EventList randomSWSSExample)"

	| rand size params data |
	rand := Random new.
	size := 128.
	params := 9.
	data := Array new: params.
	1 to: params do:
		[ :i | data at: i put: (Array new: size)].
	1 to: size do: 
		[ :i | (data at: 1) at: i put: (rand nextIntFrom: 200 to: 450)].	"dur"
	1 to: size do: 
		[ :i | (data at: 2) at: i put: (rand nextFrom: 0.3 to: 0.7)].		"ampl"
	1 to: size do: 
		[ :i | (data at: 3) at: i put: (rand nextFrom: 60 to: 500)].		"pitch"
	1 to: size do: 
		[ :i | (data at: 4) at: i put: (rand nextIntFrom: 1.0 to: 5.0)].	"ratio"
	1 to: size do: 
		[ :i | (data at: 5) at: i put: (rand nextFrom: 1.0 to: 8.0)].		"index"
	1 to: size do: 
		[ :i | (data at: 6) at: i put: (rand nextFrom: 0.05 to: 0.1)].	"attack"
	1 to: size do: 
		[ :i | (data at: 7) at: i put: (rand nextFrom: 0.05 to: 0.1)].	"decay"
	1 to: size do: 
		[ :i | (data at: 8) at: i put: (rand nextFrom: 0.01 to: 0.1)].	"i_attack"
	1 to: size do: 
		[ :i | (data at: 9) at: i put: (rand nextFrom: 0.05 to: 0.1)].	"i_decay"
	^EventList named: #SWSSExample
		fromSelectors: #(duration: loudness: pitch: cmratio: index: 
					attack: decay: iAttack: iDecay:) 
		values: data! !

!EventList class methodsFor: 'examples'!

randomSWSSExample2
	"Create an event list with random data appropriate for software sound synthesis."
	"EventList randomSWSSExample2 edit"
	"((EventList newNamed: #sRand)
			addAll: (EventList randomSWSSExample2);
			addAll: (EventList randomSWSSExample2)) edit"

	| rand size params data |
	rand := Random new.
	size := 64.
	params := 6.
	data := Array new: params.
	1 to: params do:
		[ :i | data at: i put: (Array new: size)].
	1 to: size do: 
		[ :i | (data at: 1) at: i put: (rand nextIntFrom: 300 to: 750)].	"dur"
	1 to: size do: 
		[ :i | (data at: 2) at: i put: (rand nextFrom: 0.35 to: 1.0)].		"ampl"
	1 to: size do: 
		[ :i | (data at: 3) at: i 
					put: ((rand nextIntFrom: 42 to: 72) truncateTo: 2)].	"pitch"
	1 to: size do: 
		[ :i | (data at: 4) at: i put: (LinearFunction exampleEnvelope)].	"envelope"
	1 to: size do: 
		[ :i | (data at: 5) at: i put: (rand nextFrom: 0.0 to: 1.0)].		"position"
	1 to: size do: 
		[ :i | (data at: 6) at: i put: (rand nextFrom: 0.3 to: 1.0)].		"duty"
	^EventList named: #SWSSExample
		fromSelectors: #(duration: loudness: pitch: envelope: position: duty:) 
		values: data! !

!EventList class methodsFor: 'examples'!

scaleExampleFrom: start to: stop in: dur
	"Answer an event list with a scale."
	"EventList scaleExampleFrom: 48 to: 60 in: 1500"
	"MIDIDevice MIDIPlayExample2"

	| size arr4 ndur |
	size := stop - start.
	ndur := (dur / size) truncated.
	arr4 := Array new: size.
	0 to: size-1 do: [ :i | arr4 at: i+1 put: (start + i)].
	^EventList named: EventList nextName  
		fromSelectors: #(duration: loudness: voice: pitch:) 
		values: (Array with: ndur with: 72 with: 1 with: arr4)! !

!EventList class methodsFor: 'examples'!

sentenceExample
	"Create an event list for a beautiful sentence."
	"EventList sentenceExample"

	EventList named: 'phrase2'  
		fromSelectors: #(duration: loudness: phoneme:) 
		values: (Array with: #(420 420 720 354    408 420 615 570 
					369 312 369    690 462 477 660 ) 
				with: #(0.4 0.3 0.9 0.6    0.42 0.32 0.8 0.5 
					0.44 0.52 0.2   0.94 0.62 0.46 0.34 ) 
				with: #(#und #die #fra #gen    #sind #die #sae #tze 
					#die #ich #nicht    #aus #spre #chen #kann)).
	(EventList named: 'phrase2') inspect! !

!EventList class methodsFor: 'examples'!

wordExample
	"Create an event list for a long word."
	"EventList wordExample"

	EventList named: 'phrase1'  
		fromSelectors: #(duration: loudness: phoneme:) 
		values: (Array with: #(595 545 545 540 570 800 540) 
				with: #(0.8 0.4 0.5 0.3 0.2 0.7 0.1) 
				with: #(#dun #kel #kam #mer #ge #sprae #che)).
	(EventList named: 'phrase1') inspect! !

!MusicEvent class methodsFor: 'examples'!

eventInspectExample
	"Demonstrate the terse format of event description."
	"MusicEvent eventInspectExample"

	(440 Hz, 250 msec, (#voice -> #flute), 0.7071 ampl) inspect
"	((880 Hz, 250 msec, (#voice -> #flute), 0.7071 ampl) accent: #sfz) inspect"! !

!MusicEvent class methodsFor: 'examples'!

example
	"Demonstrate the terse format of event description."
	"MusicEvent example inspect"

	^(440 Hz, 250 msec, (#voice -> #flute), 0.7071 ampl)
"	((880 Hz, 250 msec, (#voice -> #flute), 0.7071 ampl) accent: #sfz) inspect"! !

!Function class methodsFor: 'examples'!

averagedFunctionFileExample
	"Function usage example; read a function from a binary file and view it."
	"Function averagedFunctionFileExample"

	FunctionView onFunction: ((Function readFloatsFrom: 'snd/yy/ec/syl/y2.env') averagedTo: 32)! !

!Function class methodsFor: 'examples'!

fileExample
	"Function usage example; read a function from a binary file and view it."
	"Function fileExample inspect"

	^Function readFloatsFrom: 'snd/yy/ec/syl/y2.env'! !

!Function class methodsFor: 'examples'!

functionFileExample
	"Function usage example; read a function from a binary file and view it."
	"Function functionFileExample"

	FunctionView onFunction: Function default! !

!Function class methodsFor: 'examples'!

functionPlayExample
	"Function usage example; make a roll-type eventList and apply a crescendo/decrescendo to it"
	"Function functionPlayExample"

	| temp fcn |
	temp := EventList newNamed: #test3.
	(0 to: 4000 by: 50) do: 	"4 seconds, 20 notes per second"
			[ :index |			"add the same note"
			temp add: (MusicEvent dur: 100 pitch: 36 ampl: 100) 
					at: index].
	fcn := LinearFunction from: #((0 @ 0) (0.5 @ 1) (1 @ 0)).
	temp applyFunction: fcn to: #loudness.
	temp play! !

!Function class methodsFor: 'examples'!

functionViewExample
	"Function usage example; make a z-z function and view it."
	"Function functionViewExample"

	FunctionView onFunction: (Function from: #( 0 1 0 0.5 1.0 0.5 0 1 0 0.3 0.6 0.9 1 0 1 0))! !

!Function class methodsFor: 'examples'!

maxedFunctionFileExample
	"Function usage example; read a function from a binary file and view it."
	"Function maxedFunctionFileExample"

	FunctionView onFunction: ((Function readFloatsFrom: 'snd/yy/ec/syl/y2.env') maxTo: 128 win: 32)! !

!Function class methodsFor: 'examples'!

randomViewExample
	"Function usage example; make a random walk fcn and view it."
	"Function randomViewExample"

	FunctionView onFunction: (Function randomOfSize: 64 from: 0.2 to: 0.9)! !

!Function class methodsFor: 'examples'!

randomViewExample2
	"Function usage example; make a random walk fcn and view it."
	"Function randomViewExample2"

	FunctionView onFunction: (Function randomWalkSize: 128 from: 0.3 to: 0.7)! !

!LinearFunction class methodsFor: 'examples'!

exampleEnvelope
	"Answer a LinSeg of a typical envelope function."
	"LinearFunction exampleEnvelope"
	"FunctionView onFunction: (LinearFunction from: pts)"

	| rand pts size x y |
	rand := Random new.
	size := rand nextIntFrom: 4 to: 7.
	pts := Array new: size.
	pts at: 1 put: 0@0.
	pts at: size put: 1@0.
	x := 0.
	y := 0.8.
	2 to: size - 1 do:
		[ :i |
		x := x + (rand nextFrom: 0.1 to: 0.25).
		y := ((y + (rand nextFrom: -0.3 to: 0.3)) min: 1.0) max: 0.0.
		x < 0.95 ifTrue: [pts at: i put: (x@y)]].
	^LinearFunction from: pts! !

!LinearFunction class methodsFor: 'examples'!

linearExample
	"Make a LinSeg and answer a value."
	"LinearFunction linearExample"

	| fcn |
	fcn := LinearFunction ofSize: 2.
	fcn add: (0@0.5); add: (1@1).
	Transcript show: (fcn at: 0.14) printString; cr.
	fcn inspect! !

!LinearFunction class methodsFor: 'examples'!

linearViewExample
	"Make a LinSeg and open a view on its form."
	"LinearFunction linearViewExample"

	FunctionView onFunction: 
		(LinearFunction from: #((0 0) (0.2 1) (0.8 0.5) (1 0)))! !

!SplineFunction class methodsFor: 'examples'!

splineExample
	"Make a SplineSeg."
	"SplineFunction splineExample"

	| fcn |
	fcn := SplineFunction from: #((0 1) (0.35 1.3) (0.65 0.7) (1 1)).
	fcn inspect.
"	^fcn at: 0.14 
"! !

!SplineFunction class methodsFor: 'examples'!

splineViewExample
	"Make a SplineSeg and open a view on its form."
	"SplineFunction splineSegViewExample"

	FunctionView onFunction: 
		(SplineFunction from: #((0 0.5) (0.35 0.7) (0.65 0.2) (1 0.5)))! !

!ExponentialFunction class methodsFor: 'examples'!

expADSRViewExample
	"Make an exp seg and open a view on its form."
	"ExponentialFunction expsegViewExample"

	FunctionView onFunction: 
		(ExponentialFunction from: #((0 0 -5) (0.2 1 -3) (0.8 0.5 -2) (1 0)))! !

!ExponentialFunction class methodsFor: 'examples'!

expASRViewExample
	"Make an exp seg and open a view on its form."
	"ExponentialFunction expASRViewExample"

	FunctionView onFunction: 
		(ExponentialFunction from: #((0 0 -3) (0.3 0.9 0) (0.7 0.9 -3) (1 0)))! !

!ExponentialFunction class methodsFor: 'examples'!

expsegViewExample
	"Make an exp seg and open a view on its form."
	"ExponentialFunction expsegViewExample"

	FunctionView onFunction: 
		(ExponentialFunction from: #((0 0 -3) (0.2 1 -5) (0.6 0.5 -1) (1 0)))! !

!FourierSummation class methodsFor: 'examples'!

fourierExample
	"Make a Sine summation that approaches a square wave"
	"FourierSummation fourierExample"

	| fcn |
	fcn := FourierSummation from: #((1 1 0) (3 0.3 0) (5 0.2 0) 
							(7 0.15 0) (9 0.11 0) (11 0.09 0)).
	Transcript show: (fcn at: 0.14) printString; cr.
	fcn inspect! !

!FourierSummation class methodsFor: 'examples'!

fourierViewExample
	"Make a Sine summation that approaches a square wave and open a view on it."
	"FourierSummation fourierViewExample"

	FunctionView onFunction: (FourierSummation from: #((1 0.5 0) (3 0.3 0) (5 0.2 0) 
							(7 0.17 0) (9 0.15 0) (11 0.1 0)))! !

!MIDIVoice class methodsFor: 'examples'!

MIDIPlayExample1
	"Play some random notes on a voice on a device on a port."
	"MIDIVoice MIDIPlayExample1"
	"MIDIPort allNotesOff"

	| voice device port scale |
	port := MIDIPort default writeStream.
	device := MIDIDevice on: port.
	voice := MIDIVoice on: device.
	scale := EventList scaleExampleFrom: 48 to: 60 in: 2000.
"	scale eventsDo: [ :e | e duration: (e duration * 3)]."
	voice play: scale; close! !

!MIDIVoice class methodsFor: 'examples'!

MIDIPlayExample2
	"Play some random notes on a voice on a device on a port."
	"MIDIVoice MIDIPlayExample2"
	"MIDIPort allNotesOff"
	"MIDIVoice instanceCount"
	"MIDIDevice instanceCount"
	"SunMIDIPort instanceCount"

	| events voice |
	events := (EventList randomExample: 256 
		from: ((#duration: -> (60@150)), (#pitch: -> (48@60)),
				(#ampl: -> (64@94)), (#voice: -> (1@1)))).
	voice := MIDIVoice default.
	voice play: events.
	(Delay forSeconds: 8) wait.
	voice close! !

!MIDIVoice class methodsFor: 'examples'!

MIDIVoiceInspectExample
	"MIDIVoice MIDIVoiceInspectExample"

	(MIDIVoice on: (MIDIDevice on: (MIDIPort default writeStream))) inspect! !

!CsoundVoice class methodsFor: 'examples'!

randomExampleToFileAndEdit
	"Set up a CsoundVoice printing to the named file and play some random notes."
	"CsoundVoice randomExampleToFileAndEdit"

	self randomExampleToFileNamed: 'rand.sco'! !

!CsoundVoice class methodsFor: 'examples'!

randomExampleToFileNamed: fname
	"Set up a CmusicVoice printing to the named file and play some random notes."
	"CsoundVoice randomExampleToFileNamed: 'rand.sco'"

	 | file list rand voice |
	file := fname asFilename writeStream.
	rand := Random new.
	list := EventList randomExample: 64.
	list do: [ :ass | | ev |
		ev := ass event.
		ev at: #pos put: rand next.
		ev at: #prop1 put: (rand nextFrom: 320 to: 480).
		ev at: #prop2 put: (rand nextIntFrom: 12000 to: 23000)].
	voice := CsoundVoice newNamed: '1' onStream: file.
	voice addMap: #pos.
	voice addMap: [ :e | ((e at: #prop1) / 1000) printString].
	voice addMap: #prop2.
	voice play: list.
	file close.
	(Filename named: fname) edit! !

!CmixVoice class methodsFor: 'examples'!

randomExampleToFileAndEdit
	"Set up a CmixVoice printing to the named file and play some random notes."
	"CmixVoice randomExampleToFileAndEdit"

	self randomExampleToFileNamed: 'rand.m'! !

!CmixVoice class methodsFor: 'examples'!

randomExampleToFileNamed: fname
	"Set up a CmixVoice printing to the named file and play some random notes."
	"CmixVoice randomExampleToFileNamed: 'rand.m'"

	 | file list rand voice |
	file := fname asFilename writeStream.
	rand := Random new.
	list := EventList randomExample: 64.
	list do: [ :ass | | ev |
		ev := ass event.
		ev at: #pos put: rand next.
		ev at: #prop1 put: (rand nextFrom: 320 to: 480).
		ev at: #prop2 put: (rand nextIntFrom: 12000 to: 23000)].
	voice := CmixVoice newNamed: 'fm_two' onStream: file.
	voice addMap: #pos.
	voice addMap: [ :e | ((e at: #prop1) / 1000) printString].
	voice addMap: #prop2.
	voice play: list.
	file close.
	(Filename named: fname) edit! !

!CmusicVoice class methodsFor: 'examples'!

randomExampleToFileAndEdit
	"Set up a CmusicVoice printing to the named file and play some random notes."
	"CmusicVoice randomExampleToFileAndEdit"

	self randomExampleToFileNamed: 'rand.sc'! !

!CmusicVoice class methodsFor: 'examples'!

randomExampleToFileNamed: fname
	"Set up a CmusicVoice printing to the named file and play some random notes."
	"CmusicVoice randomExampleToFileNamed: 'rand.sc'"

	 | file list rand voice |
	file := fname asFilename writeStream.
	rand := Random new.
	list := EventList randomExample: 64.
	list do: [ :ass | | ev |		"add a few extra properties"
		ev := ass event.
		ev at: #pos put: rand next.
		ev at: #prop1 put: (rand nextFrom: 320 to: 480).
		ev at: #prop2 put: (rand nextIntFrom: 12000 to: 23000)].
	voice := CmusicVoice newNamed: 'violin' onStream: file.
	voice parameterMap at: 3 put: [ :e | #(in1 in2 in3 in4) at: e voice].
	voice addMap: [ :e | (e pitch asHz value printString clipTo: 5), 'Hz'].
	voice addMap: #pos.
	voice addMap: [ :e | ((e at: #prop1) / 10) truncated printString].
	voice addMap: #prop2.
	voice play: list.
	file close.
	(Filename named: fname) edit! !

!CmusicVoice class methodsFor: 'examples'!

randomExampleToTranscript
	"Set up a CmusicVoice printing to the Transcript and play some random notes."
	"CmusicVoice randomExampleToTranscript"

	 (CmusicVoice newNamed: 'violin' onStream: Transcript) 
			play: (EventList randomExample: 8)! !

!OpcodeVoice2 class methodsFor: 'examples'!

midiFileExample
	"Read and edit a midi file dump."
	"OpcodeVoice2 midiFileExample"

	(OpcodeVoice2 newOn: MusicMagnitude modeRootName, 'scores/fuga1.midi') loadOnto: (EventList newNamed: #fuga1).
	(EventList named: #fuga1) edit! !

!SampledSound class methodsFor: 'examples'!

defaultName
	"Answer the default file name."

	^MusicMagnitude modeRootName, 'data/kombination.snd'! !

!SampledSound class methodsFor: 'examples'!

fileExample
	"Answer a typical sound read in from a file."
	"SampledSound fileExample inspect"

	^SampledSound fromFile: SampledSound defaultName! !

!SampledSound class methodsFor: 'examples'!

fileExampleInspect
	"Answer a typical sound read in from a file; inspect it."
	"SampledSound fileExampleInspect"

	(SampledSound fromFile: SampledSound defaultName) inspect! !

!SampledSound class methodsFor: 'examples'!

immediateInspect
	"Answer a sampled sound from immediate data; inspect it."
	"SampledSound immediateInspect"

	| t |
	 t := Array new: 64000. 
	 0 to: 255 do: 
		[ :i | 1 to: 250 do:
			[ :j | t at: ((i * 250) + j) 
			put: (j / 250 * 32000 - 16000) asInteger]].
	(SampledSound fromData: t named: 'ramp' 
			rate: 32000 channels: 1 format: #lin16Bit) inspect! !

!SampledSound class methodsFor: 'examples'!

rmsViewExample
	"Read a sampled sound from the file, take the rms into 64 values, and edit that."
	"SampledSound rmsViewExample"

	| arr snd |
	arr := Array new: 128 withAll: 0.0.
	snd := SampledSound fileExample.
	snd sampleMaxFrom: 1 to: snd size into: arr.
	(Function from: arr) edit.! !

!SampledSound class methodsFor: 'examples'!

sawtooth
	"Create a file named 'data.out' with raw sawtooth samples."
	"SampledSound sawtooth"

	| sr dur freq stream waveLen incr samps |
	sr := 16000.
	dur := 4.
	freq := 800.
	waveLen := sr // freq.
	incr := 32767 // waveLen.
	samps := sr * dur.
	stream := 'data.out' asFilename writeStream binary.
	0 to: samps do: 
		[ :i | | index |
		index := i \\ waveLen.
		stream nextWordPut: (index * incr) asInteger].
	stream close! !

!SampledSound class methodsFor: 'examples'!

sawtoothDataFile
	"Create a file named 'data.out' with raw sawtooth samples."
	"SampledSound sawtoothDataFile"

	| sr dur freq stream waveLen incr samps |
	sr := 16000.
	dur := 4.
	freq := 800.
	waveLen := sr // freq.
	incr := 32767 // waveLen.
	samps := sr * dur.
	stream := 'data.out' asFilename writeStream binary.
	0 to: samps do: 
		[ :i | | index |
		index := i \\ waveLen.
		stream nextWordPut: (index * incr) asInteger].
	stream close! !

!ProPort class methodsFor: 'examples'!

SoundOff
	"Turn all sound off."
	"ProPort MIDIOff"

	ProPort allSoundOff! !

!ProPort class methodsFor: 'examples'!

soundOutputExample
	"Play a soundfile."
	"ProPort soundOutputExample"

	SoundPort default playFile: (SampledSound fileExample)! !

!EventGenerator class methodsFor: 'examples'!

randomExample
	"Play random examples from the set of examples in my subclasses"
	"[Sensor anyButtonPressed] whileFalse: [EventGenerator randomExample]"

	((Smalltalk at: 
			(#(Cloud DynamicCloud SelectionCloud DynamicSelectionCloud "Peal") 
					atRandom)) 
		randomExample) play! !

!Cluster class methodsFor: 'examples'!

example1
	"Cluster example1"
	"play a low 2 second cluster"

	(Cluster  dur: 2.0
		list: (EventList named: #clus1)
		ampl: (80 to: 100) 
		voice: 6) eventList edit "playPrim" "inspect"! !

!Cluster class methodsFor: 'examples'!

example2
	"Cluster example2"
	"play a low 2 second cluster"

	(Cluster  dur: 2.0
		pitchSet: #(48 49 50 51 52 53 54 55)
		ampl: 100
		voice: 6) edit "play"! !

!Roll class methodsFor: 'examples'!

rollExample
	"create and edit some rolls"

	"((Roll length: 2000 rhythm: 100 note: 48) ampl: 100) eventList"
	"((Roll length: 2000 rhythm: 100 note: 48) ampl: 100) eventList edit"
	"((Roll length: 2000 rhythm: 50 note: 60) ampl: 100) eventList playPrim"! !

!Chord class methodsFor: 'examples'!

example
	"Create and edit some chords"

	"(Chord majorTriadOn: 'c3' inversion: 0) inspect"

	"((Chord majorTetradOn: 'f2' inversion: 2) duration: 1.0) inspect"

	"((Chord majorTetradOn: 'g2' inversion: 1) duration: 1.0) inspect"! !

!Ostinato class methodsFor: 'examples'!

ostinatoExamples
	"create and edit some ostinati"

	"Ostinato onList: (EventList named: #scale1)"
	"Ostinato onList: (EventList named: #scale1) edit"
	"Ostinato newNamed: #scaleO onList: (EventList named: #scale1)"
	"(Ostinato named: #scaleO) play"
	"(Ostinato named: #scaleO) playOn: 1 at: 0"
	"(Ostinato named: #scaleO) stop"! !

!MIDIEcho class methodsFor: 'examples'!

arpeggiateMIDI
	"MIDIEcho arpeggiateMIDI"

	((MIDIEcho new) 
		process: 
			[ :e | 
			^((Arpeggio on: 
				((Chord majorTetradOn: (e pitch) inversion: 0)
					duration: 1.0)
				delay: 0.1) eventList)]) 
		play! !

!MIDIEcho class methodsFor: 'examples'!

chordMIDI
	"MIDIEcho chordMIDI"

	((MIDIEcho new) 
		process: 
			[ :e | 
			^(((Chord majorTetradOn: (e pitch) inversion: 0)
					duration: 1000; loudness: 80) "eventList")]) 
		play! !

!MIDIEcho class methodsFor: 'examples'!

echoMIDI
	"MIDIEcho echoMIDI"

	MIDIEcho new play! !

!MIDIEcho class methodsFor: 'examples'!

transposeMIDI
	"MIDIEcho transposeMIDI"

	((MIDIEcho new) 
		process: 
			[ :e | 
			e pitch: (MIDIPitch value: (e pitch value + 24)). e]) 
		play! !

!Cloud class methodsFor: 'examples'!

dictionaryExample
	"Answer an initialized Cloud generated from the given property map dictionary."
	"Cloud dictionaryExample"

	(Cloud fromDictionary: ((#duration -> 5000), 
			(#pitch -> (48 to: 70)),
			(#loudness -> (50 to: 100)), 
			(#voice -> (1 to: 4)), 
			(#density -> 15))) eventList edit! !

!Cloud class methodsFor: 'examples'!

example1
	"Create a low 6 second stochastic cloud with 5 events per second"
	"Cloud example1"

	(Cloud  dur: 6
		pitch: (48 to: 60)  
		ampl: (80 to: 120) 
		voice: (1 to: 4)
		density: 5) eventList edit "asScore" "play" "inspect"! !

!Cloud class methodsFor: 'examples'!

randomExample
	"Create a stochastic cloud with random properties."
	"Cloud randomExample"

	| rand pBase score |
	rand := Random new.
	pBase := 20 + (rand next * 60) rounded.
	score := (Cloud  dur: (2 + (rand next * 6) asInteger)
		pitch: (pBase to: (pBase + (rand next * 40)) rounded)  
		ampl: (80 to: 120) 
		voice: (1 to: 8)
		density: (rand next * 20)) eventList.
"	Processor yield.
	score play.
	(Delay forMilliseconds: (score duration + 1000)) wait
"
"	score inspect
"
	score edit! !

!Cloud class methodsFor: 'examples'!

randomExample2
	"Create a stochastic cloud with random properties."
	"Cloud randomExample2"

	| rand pBase score |
	rand := Random new.
	pBase := 20 + (rand next * 60) rounded.
	score := (Cloud  dur: (2 + (rand next * 6))
		pitch: (pBase to: (pBase + (rand next * 40)) rounded)  
		ampl: (80 to: 120) 
		voice: (1 to: 8)
		density: (rand next * 20)) eventList.
	score edit! !

!SelectionCloud class methodsFor: 'examples'!

example1
	"Create a low 4 second cloud selecting pitch, amp and voice from value arrays."
	"SelectionCloud example1"

	(SelectionCloud  dur: 4  
		pitch: #(48 50 52 55 57 )
		ampl: #(80 80 120)
		voice: #(1 2 3 4)
		density: 8) eventList edit "play" "inspect"! !

!SelectionCloud class methodsFor: 'examples'!

exampleRand
	"SelectionCloud exampleRand"
	"play a selection cloud"

	| rand pBase pArray aArray score |
	rand := Random new.
	pBase := 20 + (rand next * 40) rounded.
	pArray := Array new: 2 + ((rand next * 4) rounded).
	1 to: pArray size do: [:ind | pArray at: ind put: (pBase+(rand  next * 12) rounded)].
	pBase := 20 + (rand next * 60) rounded.
	aArray := Array new: 2 + ((rand next * 6) rounded).
	1 to: aArray size do: [:ind | aArray at: ind put: (pBase+(rand  next * (120 - pBase)) rounded)].
	score := (SelectionCloud  dur: (3 + (rand next * 4) rounded)
		pitch: pArray
		ampl: aArray
		voice: (1 to: 8)
		density: (3 + (rand next * 15) rounded)) eventList.
	score inspect.
"	score play.
	(Delay forMilliseconds: (score duration + 1000)) wait
"! !

!SelectionCloud class methodsFor: 'examples'!

randomExample
	"Create a selection cloud with random properties."
	"SelectionCloud randomExample"

	| rand pBase pArray aArray score |
	rand := Random new.
	pBase := 20 + (rand next * 40) rounded.
	pArray := Array new: 2 + ((rand next * 4) rounded).
	1 to: pArray size do: [:ind | pArray at: ind put: (pBase+(rand  next * 12) rounded)].
	pBase := 20 + (rand next * 60) rounded.
	aArray := Array new: 2 + ((rand next * 6) rounded).
	1 to: aArray size do: [:ind | aArray at: ind put: (pBase+(rand  next * (120 - pBase)) rounded)].
	score := (SelectionCloud  dur: (3 + (rand next * 4) rounded)
		pitch: pArray
		ampl: aArray
		voice: (1 to: 8)
		density: (3 + (rand next * 15) rounded)) eventList.
	score inspect.
"	score play.
	(Delay forMilliseconds: (score duration + 1000)) wait
"! !

!DynamicSelectionCloud class methodsFor: 'examples'!

example1
	"Create a selection cloud that focuses onto a trill."
	"DynamicSelectionCloud example1"

	(DynamicSelectionCloud  dur: 4
		pitch: #( #(36 38 40 43 45) #(53 54) )
		ampl: #(80 80 120)
		voice: #(1 3 5 7)
		density: 16) eventList "edit" "asScore" "playPrim" inspect! !

!DynamicSelectionCloud class methodsFor: 'examples'!

example2
	"Create a selection cloud that makes a transition from one pair of notes to another"
	"DynamicSelectionCloud example2"

	(DynamicSelectionCloud dur: 4
		pitch: #( #(60 62 64) #(72 74 76) )
		ampl: #(80 80 120)
		voice: #(1 3 5 7)
		density: 12) eventList edit "inspect" "play"! !

!DynamicSelectionCloud class methodsFor: 'examples'!

randomExample
	"Answer a dynamic selection cloud with random properties."
	"DynamicSelectionCloud randomExample"

	| rand pBase pArray1 pArray2 aArray1 score |
	rand := Random new.
	pBase := rand nextIntFrom: 42 to: 54.
	pArray1 := Array new: (rand nextIntFrom: 2 to: 4).
	1 to: pArray1 size do: 
			[:ind | pArray1 at: ind put: (rand nextIntFrom: pBase to: pBase + 12)].
	pBase := rand nextIntFrom: 60 to: 72.
	pArray2 := Array new: (rand nextIntFrom: 4 to: 8).
	1 to: pArray2 size do: 
			[:ind | pArray2 at: ind put: (rand nextIntFrom: pBase to: pBase + 12)].
	pBase := rand nextIntFrom: 40 to: 60.
	aArray1 := Array new: (rand nextIntFrom: 2 to: 6).
	1 to: aArray1 size do: 
			[:ind | aArray1 at: ind put: (rand nextIntFrom: pBase to: pBase + 50)].
	Transcript cr; show: 'DynSelCloud: ', pArray1 printString; cr; 
			show: pArray2 printString; cr; cr.
	score := (DynamicSelectionCloud  dur: 8
		pitch: (Array with: pArray1 with: pArray2)
		ampl: aArray1
		voice: (1 to: 8)
		density: (rand nextIntFrom: 5 to: 15)) eventList.
"	score inspect.
"
"	score play.
	(Delay forMilliseconds: (score duration + 1000)) wait
"
	score edit! !

!DynamicCloud class methodsFor: 'examples'!

crescendoExample
	"Create an 8-second cloud that goes from soft to loud on the same pitch."
	"DynamicCloud crescendoExample"

	(DynamicCloud  dur: 8  
		pitch: (20 to: 20)
		ampl: #((20 to: 30) (80 to: 120))
		voice: (1 to: 1)
		density: 20) eventList "edit" play "inspect"! !

!DynamicCloud class methodsFor: 'examples'!

example1
	"Create a 6-second cloud that goes from low to high and soft to loud."
	"DynamicCloud example1"

	(DynamicCloud  dur: 6  
		pitch: #((30 to: 44) (50 to: 50))
		ampl: #((20 to: 40) (90 to: 120))
		voice: (1 to: 4)
		density: 20) eventList edit "play" "inspect"! !

!DynamicCloud class methodsFor: 'examples'!

example4
	"DynamicCloud example4"
	"play a 6 second cloud that focuses on its center"

	(DynamicCloud  dur: 6  
		pitch: #((30 to: 54) (40 to: 40))
		ampl: #((20 to: 40) (90 to: 120))
		voice: (1 to: 8)
		density: 10) eventList "edit" "play" inspect! !

!DynamicCloud class methodsFor: 'examples'!

focusExample
	"Create a 6-second cloud that focuses on its center."
	"DynamicCloud focusExample"

	(DynamicCloud  dur: 6  
		pitch: #((30 to: 54) (40 to: 40))
		ampl: #((20 to: 40) (90 to: 120))
		voice: (1 to: 8)
		density: 10) eventList edit "play" "inspect"! !

!DynamicCloud class methodsFor: 'examples'!

randomExample
	"Create a dynamic second cloud with random properties."
	"DynamicCloud randomExample edit"

	| rand |
	rand := Random new.
"	^DynamicCloud  dur: 6
		pitch: #((30 to: 54) (40 to: 40))
		ampl: #((20 to: 40) (90 to: 120))
		voice: (1 to: 8)
		density: 10)
"
	^DynamicCloud  dur: (rand nextIntFrom: 3 to: 8)  
		pitch: (Array with: ((rand nextIntFrom: 24 to: 48) 
					to: (rand nextIntFrom: 24 to: 54))
				with: ((rand nextIntFrom: 48 to: 60)
					to: (rand nextIntFrom: 60 to: 72)))
		ampl: (Array with: ((rand nextIntFrom: 24 to: 36)
					to: (rand nextIntFrom: 36 to: 48))
				with: ((rand nextIntFrom: 72 to: 88)
					to: (rand nextIntFrom: 80 to: 112)))
		voice: (1 to: 4)
		density: (rand nextIntFrom: 4 to: 16)! !

!SunMIDIPort class methodsFor: 'examples'!

MIDIOff
	"Turn all notes off."
	"SunMIDIPort MIDIOff"

	MIDIPort allNotesOff! !

!SunMIDIPort class methodsFor: 'examples'!

MIDIPlayExample1
	"Play a few notes out MIDI from the port level."
	"SunMIDIPort MIDIPlayExample1"
	"MIDIPort allNotesOff"
	"SunMIDIPort initialize"
	"MStream inspect"

	| port del |
	port := MIDIPort default writeStream.
	del := 150.		"ticks/note."
	#(36 38 40 41 43 45 47 48) do: [ :p |
		port play: p at: 0 amp: 84 voice: 1.
		port play: p at: del amp: 0 voice: 1].
	(Delay forMilliseconds: (9*del)) wait.
	port close! !

!SunMIDIPort class methodsFor: 'examples'!

MIDIPlayExample2
	"Play a few notes out MIDI from the port level."
	"SunMIDIPort MIDIPlayExample2"
	"MIDIPort allNotesOff"
	"SunMIDIPort initialize"
	"MStream inspect"

	| port del |
	port := MIDIPort default writeStream.
	del := 150.		"ticks/note."
	#(36 38 40 41 43 45 47 48) do: [ :p |
		port play: p at: del dur: 450 amp: 84 voice: 1].
	port notesOff.
	(Delay forMilliseconds: (9*del+ 450)) wait.
	port close! !

!MIDIDevice class methodsFor: 'examples'!

MIDIPlayExample1
	"Play a few notes out MIDI from the device level."
	"MIDIDevice MIDIPlayExample1"
	"MIDIPort allNotesOff"
	"MIDIDevice initialize"
	"MStream inspect"

	| device port scale t0 |
	port := MIDIPort default writeStream.
	device := MIDIDevice on: port.
	scale := EventList scaleExampleFrom: 48 to: 60 in: 2500.
	scale eventsDo: [ :e | e duration: (e duration * 3)].
	t0 := 0.
	scale events do: [ :ass |
		device play: ass value at: (ass key value - t0).
		t0 := ass key value].
	port notesOff.
	(Delay forMilliseconds: 3000) wait.
	device close.
	Transcript show: ' done.'; cr.
"	MIDIPort allNotesOff"! !

!MIDIDevice class methodsFor: 'examples'!

MIDIPlayExample2
	"Play a few notes out MIDI from the device level."
	"MIDIDevice MIDIPlayExample2"
	"MIDIPort allNotesOff"
	"MIDIDevice initialize"
	"MStream inspect"

	| device port scale t0 |
	port := MIDIPort default writeStream.
	device := MIDIDevice on: port.
	scale := EventList scaleExampleFrom: 28 to: 103 in: 2500.
	t0 := 0.
	scale events do: [ :ass |
		device play: ass value at: (ass key value - t0).
		t0 := ass key value].
	port notesOff.
	(Delay forMilliseconds: 3000) wait.
	device close.
	Transcript show: ' done.'; cr.
"	MIDIPort allNotesOff"! !

!DisplayList class methodsFor: 'examples'!

exampleHierarchical
	"Create and answer a large display list with a lines, strings, and visuals."
	"(DisplayList exampleHierarchical) display"

	| dl1 dl2 dl3 dl4 dl5 dl6 rand size |
	size := 100.
	dl1 := DisplayList new.
	dl2 := DisplayList new.
	dl3 := DisplayList new.
	dl4 := DisplayList new.
	dl5 := DisplayList new.
	dl6 := DisplayList new.
	rand := Random new.
	10 timesRepeat:
		[ | pt |
		pt := (rand next * size) rounded @ ((rand next * size) rounded).
		dl1 add: ((DisplayString string: (pt printString) 
				offset: pt) color: (ColorValue random: rand))].
	10 timesRepeat:
		[ | x y w h |
		x := (rand next * size) rounded.		y := (rand next * size) rounded.
		w := (rand next * size) rounded.		h :=  (rand next * size) rounded.
		dl2 add: ((DisplayRectangle offset: (x@y) extent: (w@h))
				color: (ColorValue random: rand); fill: true)].
	10 timesRepeat:
		[ | x y w h |
		x := (rand next * size) rounded.		y := (rand next * size) rounded.
		w := (rand next * size) rounded.		h :=  (rand next * size) rounded.
		dl3 add: ((DisplayRectangle offset: (x@y) extent: (w@h))
				color: (ColorValue random: rand); fill: true)].
	10 timesRepeat:
		[ | pt |
		pt := (rand next * size) rounded @ ((rand next * size) rounded).
		dl4 add: ((DisplayString string: (pt printString) 
				offset: pt) color: (ColorValue random: rand))].
	dl5 add: dl1; 
		add: dl2 at: (250@0); 
		add: dl3 at: (0@250); 
		add: dl4 at: (250@250).
	dl6 add: dl5 at: (50@50).
	^dl6! !

!DisplayList class methodsFor: 'examples'!

gridExample
	"Create and answer a large display list with lines and strings."
	"(DisplayList gridExample) display"
	"DisplayListView example"

	| dList rand ext step |
	ext := 1000.
	step := 50.
	dList := DisplayList new.
	0 to: (ext/step) do:
		[ :i |
		dList add: (DisplayLine offset: (i*step)@0 extent: 0@ext).
		dList add: (DisplayLine offset: 0@(i*step) extent: ext@0)].
	rand := Random new.
	1 to: 50 do:
		[ :i | | pt |
		pt := (rand next * 500) rounded @ ((rand next * 500) rounded).
		dList add: (DisplayString string: (pt printString) offset: pt)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

gridExampleX: x byY: y
	"Create and answer a large display list with lines and strings."
	"(DisplayList gridExampleX: 3000 byY: 500) display"
	"DisplayListView example"

	| dList rand step |
	step := 50.
	dList := DisplayList new.
	0 to: (x/step) do:
		[ :i |
		dList add: (DisplayLine offset: (i*step)@0 extent: 0@y)].
	0 to: (y/step) do:
		[ :i |
		dList add: (DisplayLine offset: 0@(i*step) extent: x@0)].
	rand := Random new.
	1 to: (x * y / 20000) do:
		[ :i | | pt |
		pt := (rand next * x) rounded @ ((rand next * y) rounded).
		dList add: (DisplayString string: (pt printString) offset: pt)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

polylineExample
	"Answer a display list with randomly-placed random-color polylines over the given extent."
	"DisplayList polylineExample"

	(DisplayList polylinesX: 600 byY: 600 items: 100) display! !

!DisplayList class methodsFor: 'examples'!

polylineExampleHuge
	"Answer a display list with randomly-placed random-color polylines over the given (very large) extent."
	"DisplayList polylineExampleHuge"

	(DisplayList polylinesX: 6000 byY: 2000 items: 2000) displayNonCached! !

!DisplayList class methodsFor: 'examples'!

polylinesX0: x byY: y
	"Answer a display list with randomly-placed random-color polylines over the given extent."
	"(DisplayList polylinesX: 600 byY: 600) display"

	| dList rand xArr yArr inset scale   x0 y0 size pointArray |
	inset := 64.
	scale := 32.
	dList := DisplayList new.
	rand := Random new.
	x0 := rand nextIntFrom: inset to: x-inset.
	y0 := rand nextIntFrom: inset to: y-inset.
	((x/30) + (y/30)) timesRepeat:
		[size := rand nextIntFrom: 3 to: 7.
		pointArray := Array new: size.
		pointArray at: 1 put: x0.
		yArr at: 1 put: y0.
		xArr at: size put: x0.
		yArr at: size put: y0.
		1 to: size do: [ :i |
			xArr at: i put: x0.
			yArr at: i put: y0.
			x0 := x0 + (rand nextIntFrom: 8 to: scale).
			y0 := y0 + (rand nextIntFrom: 8 to: scale)].
		dList add: ((DisplayPolyline
				offset: ((rand nextIntFrom: inset to: x-inset)
						@(rand nextIntFrom: inset to: y-inset)))
				color: ColorValue random);
				vertices: pointArray].
	^dList! !

!DisplayList class methodsFor: 'examples'!

polylinesX: x byY: y
	"Answer a display list with randomly-placed random-color polylines over the given extent."
	"(DisplayList polylinesX: 600 byY: 600) display"

	| dList rand inset scale x0 y0 size pointArray |
	inset := 16.
	scale := 128.
	dList := DisplayList new.
	rand := Random new.
	x0 := rand nextIntFrom: inset to: x-inset.
	y0 := rand nextIntFrom: inset to: y-inset.
	((x/20) + (y/20)) timesRepeat:
		[size := rand nextIntFrom: 3 to: 7.
		pointArray := Array new: size.
		pointArray at: 1 put: (0@0).
		pointArray at: size put: (0@0).
		x0 := y0 := 0.
		2 to: size-1 do: [ :i |
			pointArray at: i put: (x0 @ y0).
			x0 := x0 + (rand nextIntFrom: scale negated to: scale).
			y0 := y0 + (rand nextIntFrom: scale negated to: scale)].
		dList add: ((DisplayPolyline
				offset: ((rand nextIntFrom: inset to: x-inset)
						@(rand nextIntFrom: inset to: y-inset)))
				color: ColorValue random;
				vertices: pointArray)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

polylinesX: x byY: y items: num
	"Answer a display list with randomly-placed random-color polylines over the given extent."
	"(DisplayList polylinesX: 600 byY: 600 items: 1000) display"

	| dList rand inset scale x0 y0 size pointArray |
	inset := 16.
	scale := 128.
	dList := DisplayList new.
	rand := Random new.
	x0 := rand nextIntFrom: inset to: x-inset.
	y0 := rand nextIntFrom: inset to: y-inset.
	num timesRepeat:
		[size := rand nextIntFrom: 3 to: 7.
		pointArray := Array new: size.
		pointArray at: 1 put: (0@0).
		pointArray at: size put: (0@0).
		x0 := y0 := 0.
		2 to: size-1 do: [ :i |
			pointArray at: i put: (x0 @ y0).
			x0 := x0 + (rand nextIntFrom: scale negated to: scale).
			y0 := y0 + (rand nextIntFrom: scale negated to: scale)].
		dList add: ((DisplayPolyline
				offset: ((rand nextIntFrom: inset to: x-inset)
						@(rand nextIntFrom: inset to: y-inset)))
				color: ColorValue random;
				vertices: pointArray)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

postScriptExample
	"Create and answer a large display list with a lines, strings, and visuals."
	"DisplayList postScriptExample"

	| dList psRenderer file |
	dList := (DisplayList stringsX: 600 byY: 900) "DisplayList example2".
	file := 'temp.ps' asFilename writeStream.
	psRenderer := PostScriptPrinter new.
	psRenderer file: file; start: nil.
"	psRenderer scale: 10@10."
	dList displayPostScriptOn: psRenderer.
	psRenderer endNoPrint: nil. 		"this prints it."
"	'temp.ps' asFilename edit."! !

!DisplayList class methodsFor: 'examples'!

randomExample
	"Create and answer a large display list with a lines, strings, and visuals."
	"(DisplayList randomExample) display"

	| dList rand ext size |
	ext := 1000.
	size := ext / 2.
	dList := DisplayList new.
	rand := Random new.
	10 timesRepeat:
		[ | x y w h |					"add rectangles"
		x := (rand next * size) rounded.
		y := (rand next * size) rounded.
		w := (rand next * size/10) rounded.
		h :=  (rand next * size/10) rounded.
		dList add: ((DisplayRectangle
				offset: (x@y)
				extent: (w@h))
				color: ColorValue random; fill: true)].
	10 timesRepeat:
		[ | pt1 pt2 |					"add lines"
		pt1 := (rand next * size) rounded @ ((rand next * size) rounded).
		pt2 := (rand next * size) rounded @ ((rand next * size) rounded).
		dList add: ((DisplayLine offset: pt2 extent: (pt1 - pt2))
				color: ColorValue random)].
	20 timesRepeat:
		[ | pt |						"add strings"
		pt := (rand next * size) rounded @ ((rand next * size) rounded).
		dList add: ((DisplayString string: (pt printString) 
				offset: pt) color: ColorValue random)].
	10 timesRepeat:
		[ | pt coll |					"add visuals"
		coll := Cursor allInstances.
		pt := (rand next * ext) rounded @ ((rand next * ext) rounded).
		dList add: ((DisplayVisual visual: (coll atRandom image) 
				offset: pt) color: ColorValue random)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

rectangleExample
	"Answer a display list with randomly-placed random-color rectangles over the given extent."
	"DisplayList rectangleExample"

	(DisplayList rectanglesX: 600 byY: 600) display! !

!DisplayList class methodsFor: 'examples'!

rectanglesX: x byY: y
	"Answer a display list with randomly-placed random-color rectangles over the given extent."
	"(DisplayList rectanglesX: 600 byY: 600) display"

	| dList rand x0 y0 x1 y1 scale w h |
	dList := DisplayList new.
	rand := Random new.
	scale := 20.
	x0 := x - (scale * 2).
	y0 := y - (scale * 2).
	((x/30) + (y/30)) timesRepeat:
		[x1 := scale + (rand next * x0) rounded.
		y1 := scale + (rand next * y0) rounded.
		w := ((rand next * 0.5 * (x0-x1) abs) rounded).
		h :=  ((rand next * 0.5 * (y0-y1) abs) rounded).
		dList add: ((DisplayRectangle
				offset: (x1@y1)
				extent: (w@h))
				color: ColorValue random; fill: true)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

stringExample
	"Open a display list view with randomly-placed random-color strings over the given extent."
	"DisplayString stringExample"

	(DisplayList stringsX: 600 byY: 600) display! !

!DisplayList class methodsFor: 'examples'!

stringsX: x byY: y
	"Answer a display list with randomly-placed random-color strings over the given extent."
	"(DisplayList stringsX: 600 byY: 600) display"

	| dList rand inset |
	inset := 16.
	dList := DisplayList new.
	rand := Random new.
	((x/10) + (y/10)) timesRepeat:
		[dList add: ((DisplayString
				string: (rand nextIntFrom: 10 to: 100000) printString
				offset: ((rand nextIntFrom: inset to: x-inset)
						@(rand nextIntFrom: inset to: y-inset)))
				color: ColorValue random)].
	^dList! !

!DisplayList class methodsFor: 'examples'!

visualsX: x byY: y
	"Answer a display list with randomly-placed random-color visuals over the given extent."
	"(DisplayList visualsX: 600 byY: 600) display"

	| dList rand inset |
	inset := 16.
	dList := DisplayList new.
	rand := Random new.
	((x/10) + (y/10)) timesRepeat:
		[dList add: ((DisplayVisual
				visual: (rand nextIntFrom: 10 to: 100000) printString
				offset: ((rand nextIntFrom: inset to: x-inset)
						@(rand nextIntFrom: inset to: y-inset)))
				color: ColorValue random)].
	^dList! !

!DisplayRectangle class methodsFor: 'examples'!

rectangleExample
	"Open a display list view with randomly-placed random-color rectangles over the given extent."
	"DisplayRectangle rectangleExample"

	(DisplayList rectanglesX: 600 byY: 600) display! !

!DisplayPolyline class methodsFor: 'examples'!

polylineExample
	"Open a display list view with randomly-placed random-color polylines over the given extent."
	"DisplayPolyline polylineExample"

	(DisplayList polylinesX: 600 byY: 600) display! !

!DisplayString class methodsFor: 'examples'!

stringExample
	"Open a display list view with randomly-placed random-color strings over the given extent."
	"DisplayString stringExample"

	(DisplayList stringsX: 600 byY: 600) display! !

!DisplayVisual class methodsFor: 'examples'!

visualExample
	"Open a display list view with randomly-placed random-color visuals over the given extent."
	"DisplayVisual visualExample"

	(DisplayList visualsX: 600 byY: 600) display! !

!DisplayListView class methodsFor: 'examples'!

classListExample
	"DisplayListView classListExample"

	IndentedListLayoutManager listExample display! !

!DisplayListView class methodsFor: 'examples'!

classTreeExample
	"DisplayListView classTreeExample"

	(IndentedTreeLayoutManager listExample) display! !

!DisplayListView class methodsFor: 'examples'!

colorClassListExample
	"DisplayListView colorClassListExample"

	IndentedListLayoutManager colorListExample! !

!DisplayListView class methodsFor: 'examples'!

example
	"DisplayListView example"

	self onList: DisplayList gridExample! !

!DisplayListView class methodsFor: 'examples'!

exampleGridded
	"Open an example of a gridded-background display list view on the example hierarchical display list."
	"DisplayListView exampleGridded"

	DisplayListView onList: (DisplayList exampleHierarchical)
			size: 400@300
			withGrid: 32@32
			inColor: ColorValue lightGray! !

!DisplayListView class methodsFor: 'examples'!

exampleHierarchical
	"DisplayListView exampleHierarchical"

	self onList: (DisplayList exampleHierarchical) size: 400@400! !

!DisplayListView class methodsFor: 'examples'!

test1
	"DisplayListView test1"

	| window container me wrapper dlist dled |
	window := ScheduledWindow new.
	window label: 'Display List Editor'.
	window minimumSize: 400@300.
	container := CompositePart new.
	dlist := DisplayList example2.
	dled := DisplayListEditor on: dlist.
	me := self on: dled.
	self addButtonOn: me labeled: 'File'
		doing: [:model :value | dled doFile] 
		in: (LayoutFrame new leftFraction: 0.0;		topFraction: 0.0; 
							rightFraction: 0.2;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Edit'
		doing: [:model :value | dled doEdit] 
		in: (LayoutFrame new leftFraction: 0.2;		topFraction: 0.0; 
							rightFraction: 0.4;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Inspect'
		doing: [:model :value | "me inspect." dled doInspect] 
		in: (LayoutFrame new leftFraction: 0.4;		topFraction: 0.0; 
							rightFraction: 0.6;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Display'
		doing: [:model :value | dled doDisplay] 
		in: (LayoutFrame new leftFraction: 0.6;		topFraction: 0.0; 
							rightFraction: 0.8;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Zoom'
		doing: [:model :value | dled doZoom] 
		in: (LayoutFrame new leftFraction: 0.8;		topFraction: 0.0; 
							rightFraction: 1.0;	bottomFraction: 0.1) 
		to: container.
	wrapper := LookPreferences edgeDecorator on: me.
	wrapper useHorizontalScrollBar.
	container add: wrapper
			borderedIn: (0@0.1 extent: 1.0@0.9).
	window component: container.	
	window open! !

!DisplayListView class methodsFor: 'examples'!

test3
	"DisplayListView test3"

	| window container me wrapper dlist dled |
	window := ScheduledWindow new.
	window label: 'Display List Editor'.
	window minimumSize: 300@300.
	container := CompositePart new.
	dlist := DisplayList rectanglesX: 600 byY: 600.
	dled := DisplayListEditor on: dlist.
	me := self on: dled.
	self addButtonOn: me labeled: 'File'
		doing: [:model :value | dled doFile] 
		in: (LayoutFrame new leftFraction: 0.0;		topFraction: 0.0; 
							rightFraction: 0.2;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Edit'
		doing: [:model :value | dled doEdit] 
		in: (LayoutFrame new leftFraction: 0.2;		topFraction: 0.0; 
							rightFraction: 0.4;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Inspect'
		doing: [:model :value | "me inspect." dled doInspect] 
		in: (LayoutFrame new leftFraction: 0.4;		topFraction: 0.0; 
							rightFraction: 0.6;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Display'
		doing: [:model :value | dled doDisplay] 
		in: (LayoutFrame new leftFraction: 0.6;		topFraction: 0.0; 
							rightFraction: 0.8;	bottomFraction: 0.1) 
		to: container.
	self addButtonOn: me labeled: 'Zoom'
		doing: [:model :value | dled doZoom] 
		in: (LayoutFrame new leftFraction: 0.8;		topFraction: 0.0; 
							rightFraction: 1.0;	bottomFraction: 0.1) 
		to: container.
	wrapper := LookPreferences edgeDecorator on: me.
	wrapper useHorizontalScrollBar.
	container add: wrapper
			borderedIn: (0@0.1 extent: 1.0@0.9).
	window component: container.	
	window open! !

!BinaryTreeLayoutManager class methodsFor: 'examples'!

listExample
	"BinaryTreeLayoutManager listExample display"

	| acc me |
	acc := TreeAccessor subject: BTreeNode treeExample2
			terminalQuery: [ :c | (c isTreeNode not) or: [c children size = 0]]
			childAccessor: #children
			itemGenerator: [ :c | (DisplayString new)
							model: c; 
							string: c printString; 
							color: ColorValue white].
	me := (self new) accessor: acc; xStep: 32; yStep: 64.
	^me displayList! !

!IndentedListLayoutManager class methodsFor: 'examples'!

colorListExample
	"IndentedListLayoutManager colorListExample display"

	| acc me |
	acc := TreeAccessor subject: MusicMagnitude
			terminalQuery: [ :c | c subclasses size = 0]
			childAccessor: #sortedSubclasses
			itemGenerator: [ :c | (DisplayString new)
									model: c;
									string: c name;
									color: [c color]].
	me := (self new) accessor: acc; xStep: 16; yStep: 16.
	^me displayList display! !

!IndentedListLayoutManager class methodsFor: 'examples'!

listExample
	"IndentedListLayoutManager listExample display"
	"DisplayListView classListExample"

	| acc me |
	acc := TreeAccessor subject: Magnitude
			terminalQuery: [ :c | c subclasses size = 0]
			childAccessor: #sortedSubclasses
			itemGenerator: [ :c | (DisplayString new)
									model: c;
									string: c name;
									color: ColorValue white].
	me := (self new) accessor: acc; xStep: 16; yStep: 16.
	^me displayList! !

!IndentedTreeLayoutManager class methodsFor: 'examples'!

listExample
	"IndentedTreeLayoutManager listExample display"
	"DisplayListView classTreeExample"

	| acc me |
	acc := TreeAccessor subject: "View" Magnitude
			terminalQuery: [ :c | c subclasses size = 0]
			childAccessor: #sortedSubclasses
			itemGenerator: [ :c | (DisplayString new)
							model: c; 
							string: c name; 
							color: ColorValue white].
	me := (self new) accessor: acc; xStep: 16; yStep: 12.
	^me displayList! !

!TimeSequenceView class methodsFor: 'examples'!

bachExample
	"Open a sequence view on the Bach fugue theme."
	"SequenceView bachExample"

	TimeSequenceView openOn:
		((EventListEditor new) list: (EventList named: #Bach2) copy)! !

!TimeSequenceView class methodsFor: 'examples'!

randomExample
	"Open a sequence view on a random event list."
	"SequenceView randomExample"

	TimeSequenceView openOn:
		((EventListEditor new) list: EventList randomExample)! !

!PitchTimeView class methodsFor: 'examples'!

bachExample
	"Open a PTView on the event list named Bach2."
	"PitchTimeView bachExample"

	PitchTimeView openOn:
			((EventListEditor new) list: (EventList named: #Bach2) copy)! !

!PitchTimeView class methodsFor: 'examples'!

randomExample
	"Open a p-t view on a random event list."
	"PitchTimeView randomExample"

	PitchTimeView openOn:
		((EventListEditor new) list: EventList randomExample)! !

!CMNView class methodsFor: 'examples'!

example
	"CMNView example"

	CMNView openOn:
			((EventListEditor new) list: (EventList named: #scale2) copy)! !

!HauerSteffensView class methodsFor: 'examples'!

bachExample
	"Open a HSView on the event list named Bach2."
	"HauerSteffensView bachExample"

	HauerSteffensView openOn:
			((EventListEditor new) list: (EventList named: #Bach2) copy)! !

!HauerSteffensView class methodsFor: 'examples'!

randomExample
	"Open a HSView on two merged random event lists."
	"HauerSteffensView randomExample"

	HauerSteffensView openOn:
			((EventListEditor new) list: ((EventList newNamed: #pRand)
				addAll: (EventList randomExample);
				addAll: (EventList randomExample)))! !

!HauerSteffensView class methodsFor: 'examples'!

randomSWSSExample
	"Open a HSView on two merged random event lists."
	"HauerSteffensView randomSWSSExample"

	HauerSteffensView openOn:
			((EventListEditor new) list: ((EventList newNamed: #sRand)
			addAll: (EventList randomSWSSExample2);
"			addAll: (EventList randomSWSSExample2);"
			addAll: (EventList randomSWSSExample2)))! !

!PhraseView class methodsFor: 'examples'!

example
	"PhraseView example"

	PhraseView openOn:
		((EventListEditor new) list: (EventList named: #phrase1) copy)! !

!FunctionView class methodsFor: 'examples'!

example
	"FunctionView example"

	FunctionView multiFunctionExample! !

!FunctionView class methodsFor: 'examples'!

expSegExample
	"Demonstrate an ExpSeg function with different weights."
	"FunctionView expSegExample"

	FunctionView onFunction: (ExponentialFunction from: #((0 0 3) (0.3 1 5) (0.6 0.3 0) (1 0)))! !

!FunctionView class methodsFor: 'examples'!

fileExample
	"Read an extracted envelope as floating-point data from a file."
	"FunctionView fileExample"

	FunctionView onFunction: (Function readFloatsFrom: 'snd/yy/ec/syl/y2.env')
"	FunctionView onFunction: (Function readFloatsFrom: 'snd/yy/ec/syl/y2.2.env')"! !

!FunctionView class methodsFor: 'examples'!

linSegExample
	"FunctionView linSegExample"

	FunctionView onFunction: (LinearFunction from: #((0 0) (0.15 1.0) (0.25 0.75) (0.75 0.5) (1 0)))! !

!FunctionView class methodsFor: 'examples'!

multiFunctionExample
	"Open a function editor on 4 different functions."
	"FunctionView multiFunctionExample"

	FunctionView 
		onFunction: (LinearFunction from: #((0 0) (0.12 1) (0.17 0.74) 
				(0.35 0.5) (0.9 0.4) (1 0) )) 
		and: (LinearFunction from: #((0 0.1) (0.3 0.5) (0.7 0.3) (1 0))) 
		and: (ExponentialFunction from: #((0 0 5) (0.05 1 -5) (0.2 0.25 -1) (1 0))) 
		and: (SplineFunction from: #((0 0.5) (0.212891 0.429687) (0.35 0.7) (0.65 0.35) (0.845703 0.6875) (1 0.5))) 
		x: 512 y: 256! !

!FunctionView class methodsFor: 'examples'!

multiFunctionExample2
	"Open a function editor on 4 different functions."
	"FunctionView multiFunctionExample2"

	FunctionView 
		onFunction: (LinearFunction from: #((0 0) (0.12 1) (0.17 0.74) 
				(0.35 0.5) (0.9 0.4) (1 0) )) 
		and: (Function readFloatsFrom: 'snd/yy/ec/syl/y2.env') 
		and: (ExponentialFunction from: #((0 0 5) (0.05 1 -5) (0.2 0.25 -1) (1 0))) 
		and: (SplineFunction default) 
		x: 384 y: 192! !

!FunctionView class methodsFor: 'examples'!

smallFileExample
	"Read an extracted envelope as floating-point data from a file."
	"FunctionView smallFileExample"

	FunctionView smallOnFunction: (Function readFloatsFrom: 'snd/yy/ec/syl/y2.env')
"	FunctionView smallOnFunction: (Function readFloatsFrom: 'snd/yy/ec/syl/y2.2.env')"! !

!FunctionView class methodsFor: 'examples'!

smallMultiFunctionExample
	"Open a function editor on 4 different functions."
	"FunctionView smallMultiFunctionExample"

	 
	FunctionView onFunctions: (Array 
			with: (LinearFunction from: #((0 0) (0.12 1) (0.17 0.74) 
					(0.35 0.5) (0.9 0.4) (1 0)))
			with: (LinearFunction from: #((0 0.1) (0.3 0.5) (0.7 0.3) (1 0)))
			with: (ExponentialFunction from: #((0 0 5) (0.05 1 -5) (0.2 0.25 -1) (1 0)))
			with: (SplineFunction default))
		withColors: self defaultColors
		x: 384 y: 192! !

!SoundView class methodsFor: 'examples'!

example1
	"Open a sound view on the example sound file."
	"SoundView example1"

"	| fileName |	
	fileName := FillInTheBlank request: 'name of soundfile to edit:'
					initialAnswer: '/usr/stp/snd/test'.
	fileName size = 0 ifTrue: [^self].
	SoundView1 openOn: 
			(SampledSound fromFile: fileName)
"

	SoundView openOn: (SampledSound fileExample)! !

!SoundView class methodsFor: 'examples'!

example2
	"Open a sound view on the an empty sound."
	"SoundView example2"

	SoundView openOn: (SampledSound new initialize)! !

!MixView class methodsFor: 'examples'!

randomExample
	"Open a MixView on the random mix event list."
	"MixView randomExample"

	MixView openOn: ((EventListEditor new) list: Mix randomExample)! !

!MixView class methodsFor: 'examples'!

randomExample2
	"Open a MixView on the random mix event list."
	"MixView randomExample2"

	MixView openOn:
			((EventListEditor new) list: ((Mix newNamed: #mRand)
					addAll: (Mix randomExample);
					addAll: (Mix randomExample)))! !

!Mix class methodsFor: 'examples'!

randomExample
	"Create an event list with random data."
	"Mix randomExample"
	"MixView randomExample"
	"(Mix newNamed: #mRand)
			addAll: (Mix randomExample);
			addAll: (Mix randomExample)"

	| rand size arrArray |
	rand := Random new.
	size := 16.
	arrArray := Array new: 7.
	1 to: 7 do: [ :i | arrArray at: i put: (Array new: size)].
	1 to: size do: [ :i | (arrArray at: 1) at: i put: (rand next * 8.0)].
	1 to: size do: [ :i | (arrArray at: 2) at: i put: (rand nextFrom: 1.0 to: 4.0)].
	1 to: size do: [ :i | (arrArray at: 3) at: i put: rand next].
	1 to: size do: [ :i | (arrArray at: 4) at: i put: (rand nextIntFrom: 1 to: 7)].
	1 to: size do: [ :i | (arrArray at: 5) at: i put: (rand nextFrom: 0.1 to: 0.3)].
	1 to: size do: [ :i | (arrArray at: 6) at: i put: (rand nextFrom: 0.1 to: 0.4)].
	1 to: size do: [ :i | (arrArray at: 7) at: i put: 
		(#('y1.2c4' 'y1.4a3b' 'y1.4a1' 'y1.2b2b' 'y1.2b1' 'y1.2c2a' 'y1.2a2' 'y1.4b2') 
				atRandom: rand)].
	^Mix named: 'random1'  
		fromSelectors: #(start: duration: loudness: voice: fadeIn: fadeOut: name:) 
		values: arrArray! !

!Mix class methodsFor: 'examples'!

randomExample1
	"Create an event list with random data."
	"Mix randomExample"
	"MixView randomExample"
	"(Mix newNamed: #mRand)
			addAll: (Mix randomExample);
			addAll: (Mix randomExample)"

	| rand size arr1 arr2 arr3 arr4 |
	rand := Random new.
	size := 8.
	arr1 := Array new: size.
	arr2 := Array new: size.
	arr3 := Array new: size.
	arr4 := Array new: size.
	1 to: size do: [ :i | arr1 at: i put: (rand next * 15.0)].
	1 to: size do: [ :i | arr2 at: i put: (rand nextFrom: 1.0 to: 4.0)].
	1 to: size do: [ :i | arr3 at: i put: rand next].
	1 to: size do: [ :i | arr4 at: i put: (rand nextIntFrom: 1 to: 4)].
	^Mix named: 'random1'  
		fromSelectors: #(start: duration: loudness: voice:) 
		values: (Array with: arr1 with: arr2 with: arr3 with: arr4)! !

!BTreeNode class methodsFor: 'examples'!

treeExample1
	"BTreeNode treeExample1 inspect"
	"TreeView on: (BTreeNode treeExample1)"

	^(BTreeNode left: (BTreeNode left: 1 right: 2)
				right: (BTreeNode left: 3 
							right: (BTreeNode left: 4 right: 5)))! !

!BTreeNode class methodsFor: 'examples'!

treeExample2
	"BTreeNode treeExample2"
	"TreeView on: (BTreeNode treeExample2)"

	^BTreeNode name: #root
		left: (BTreeNode name: #l
				left: (BTreeNode name: #ll left: 0 right: 1)
				right: (BTreeNode name: #lr 
						left: 3
						right: (BTreeNode name: #lrr left: 5 right: 6)))
		right: (BTreeNode name: #r
					left: (BTreeNode name: #rl left: 8 right: 9) 
					right: (BTreeNode name: #rr 
							left: (BTreeNode name: #rrl left: 12 right: 13)
							right: 15))! !

!TRTreeNode class methodsFor: 'examples'!

treeExample3
	"TRTreeNode treeExample3"
	"TreeView openOn: TRTreeNode treeExample3"

	| arr |
"	arr := #(6 1 7 4 3 5 2) asOrderedCollection.
"	arr := #(5 7 1 8 4 6 3 9 2 10) asOrderedCollection.
	^TreeEditor new root: (TRTreeNode fromValues: arr copy);
					leaves: arr! !

!LPCFrameData class methodsFor: 'examples'!

example
	"Open up a demo LPC frame view"
	"LPCFrameData example"

	LPCFrameView openOn: 
		((LPCFrameData new: 100) 
				readFromFileNamed: 'music/lpc/sampledata/sampledataset.lpc')! !

!LPCFrameView class methodsFor: 'examples'!

example
	"Open up a demo LPC frame view"
	"LPCFrameView example"

	LPCFrameView openOn: 
		((LPCFrameData new: 100) 
				readFromFileNamed: 'music/lpc/sampledata/sampledataset.lpc')! !

!PhaseVocFrameData class methodsFor: 'examples'!

example
	"Open up a demo LPC frame view"
	"PhaseVocFrameData example"

	PhaseVocFrameView openOn: 
		((PhaseVocFrameData new: 100) 
				readFromFileNamed: '/usr/stp/snd/ec/syl/ywe1a.pv')! !