'From etoys2.2 of 24 September 2007 [latest update: #1719] on 20 October 2007 at 5:47:03 pm'! "Change Set: soundLibrary-kfr-sw Date: 20 October 2007 Author: Karl Ramberg, Scott Wallace A tool for browsing and managing the sound library. Consult class comment of SoundLibraryTool for details.."! AlignmentMorph subclass: #SoundLibraryTool instanceVariableNames: 'listBox button soundIndex currentSound' classVariableNames: '' poolDictionaries: '' category: 'Sound-Interface'! !SoundLibraryTool commentStamp: 'sw 10/20/2007 01:54' prior: 0! A tool for browsing and managing the sound library. Offers a self-updating, scrolling list of all the sounds in the library. Has a row of buttons to initiate various functions on the selected sound; the buttons are: Play Play the selected sound Stop Stop playing selected sound (if it is playing) Tile Hand the user a tile for the selected sound. Rename Rename the selected sound. Delete Delete the selected sound from the ibrary Load Load a sound into the sound library from a file. Additionally, a wave-editor can be invoked via an item in the tool's halo menu. The Sound Library tool can be launched from the Objects catalog, and also from the authoring-tools menu! !SampledSound class methodsFor: 'sound library' stamp: 'sw 10/19/2007 22:50'! renameSound: aString newName: newName "Rename the sound currently known by the first arg to be now known by the second arg." SoundLibrary at: newName put: (SoundLibrary at: aString). SoundLibrary removeKey: aString! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/20/2007 01:25'! addButtonRow "Add the row of control buttons." | row aButton | row := AlignmentMorph newRow vResizing: #shrinkWrap; color: Color transparent. #(('Play' play 'Play the selected sound') ('Stop' pause 'If the selected sound is playing, stop it') ('Tile' handMeATile 'Hands you a tile representing the selected sound') ('Rename' renameSound 'Rename the selected sound') ('Delete' deleteSound 'Delete the selected sound from the sound library') ('Load' loadSoundFromDisk 'Add a new sound to the sound library from a file')) translatedNoop do: [:triplet | row addVariableTransparentSpacer. aButton := SimpleButtonMorph new label: triplet first translated font: ScriptingSystem fontForEToyButtons; target: self; actionSelector: triplet second. aButton setBalloonText: triplet third translated. row addMorphBack: aButton]. row addVariableTransparentSpacer. self addMorphBack: row! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/19/2007 23:36'! addHeaderRow "Add the first row of the tool, containing dismiss and help icons and the interim name of the sound." | aMorph | aMorph := AlignmentMorph newRow. aMorph hResizing: #spaceFill. aMorph addMorphBack: self dismissButton. aMorph addVariableTransparentSpacer. aMorph addMorphBack: (StringMorph contents: 'Sound Library' translated font: ScriptingSystem fontForEToyButtons). aMorph addVariableTransparentSpacer. aMorph addMorphBack: self helpButton. self addMorphBack: aMorph! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/20/2007 00:08'! addSoundList "Add the sounds list to the tool." listBox _ PluggableListMorph on: self list: #soundList selected: #soundIndex changeSelected: #soundIndex:. listBox hResizing: #spaceFill. listBox hideMenuButton. listBox height: 240. listBox font: Preferences standardEToysFont. self addMorphBack: listBox! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/20/2007 02:15'! helpString "Answer help content." ^ 'This tool allows you to view and manage the "Sound Library", which is the list of named sounds that can be used in the tile-scripting system. Click on a sound name in the list to select it. The buttons at the top of the tool apply to the sound you have selected. Play button -- press this to start playing the selected sound. Stop button -- if the selected sound is playing, pressing this will stop it. Tile button -- Click on this to obtain a scripting tile representing the selected sound. Rename button -- allows you to rename the selected sound. Delete button -- allows you to delete the selected sound from the Sound Library. All tiles that formerly pointed to this sound will be changed to point to "croak" instead. Load button -- allows you to load a sound into the Sound Library from a file. You can also add sounds to the Sound library using the Sound Recorder, and also by dragging an external sound file (e.g. a file with extensions .wav or .aif) into etoys. Note: the "universal" sounds built in to the system cannot be renamed or deleted. Additionally, a command for opening a "wave editor" tool on the selected sound can be found in the tool''s halo menu.' translated! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/20/2007 01:41'! initialize "initialize the state of the receiver" super initialize. self hResizing: #shrinkWrap; vResizing: #shrinkWrap. self cellPositioning: #topLeft. self listDirection: #topToBottom. self borderWidth: 2; borderColor: Color black. self addHeaderRow. self addButtonRow. soundIndex := 1. self addSoundList. self soundIndex: 1. self on: #mouseEnter send: #verifyContents to: listBox! ! !SoundLibraryTool methodsFor: 'initialization' stamp: 'sw 10/20/2007 00:10'! presentHelp "Sent when a Help button is hit; provide the user with some form of help for the tool at hand" | aFlapTab | aFlapTab := ScriptingSystem assureFlapOfLabel: 'Sound Library' translated withContents: self helpString. aFlapTab showFlap! ! !SoundLibraryTool methodsFor: 'accessing' stamp: 'sw 10/20/2007 01:41'! handlesMouseOver: evt "Do I want to receive mouseEnter: and mouseLeave: when the button is up and the hand is empty? The default response is false, except if you have added sensitivity to mouseEnter: or mouseLeave:, using the on:send:to: mechanism." ^ true! ! !SoundLibraryTool methodsFor: 'accessing' stamp: 'kfr 9/23/2007 00:55'! soundIndex ^soundIndex! ! !SoundLibraryTool methodsFor: 'accessing' stamp: 'sw 10/19/2007 23:33'! soundIndex: aInteger "Set the sound index to the given integer." | name | soundIndex := aInteger. soundIndex = 0 ifFalse: [name := (listBox getList at: soundIndex ). currentSound := SampledSound soundNamed: name] ifTrue: [currentSound := nil]. self changed: #soundIndex.! ! !SoundLibraryTool methodsFor: 'accessing' stamp: 'sw 10/20/2007 17:30'! soundList "Answer the list of sound keys in the sound libraryi." ^ SampledSound soundLibrary keys asSortedArray! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'sw 10/20/2007 01:27'! addCustomMenuItems: aMenu hand: aHand "Add custom menu items to a menu" super addCustomMenuItems: aMenu hand: aHand. aMenu addTranslatedList: #( ('wave editor' edit 'open a tool which, operating with the selected sound as a point of departure, will allow you to construct a new "instrument"') ) translatedNoop! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'sw 10/19/2007 21:44'! deleteSound "Delete the selected sound, if appropriate." | name | soundIndex = 0 ifTrue: [^ self inform: 'No sound selected' translated]. name := listBox getList at: soundIndex. (SampledSound universalSoundKeys includes: name) ifTrue: [self inform: 'You can not delete this sound' translated] ifFalse: [ScriptingSystem removeFromSoundLibrary: name]. self soundIndex: 0. listBox updateList! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'kfr 9/23/2007 13:07'! edit "Open a WaveEditor on my samples." soundIndex > 0 ifTrue: [WaveEditor openOn: currentSound samples.] ! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'kfr 9/26/2007 23:55'! handMeATile | tile name | soundIndex = 0 ifTrue:[^nil]. name _ (listBox getList at: soundIndex ). tile _ SoundTile new literal: name. tile bounds: tile fullBounds. tile openInHand! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'sw 10/20/2007 02:11'! loadSoundFromDisk "Put up a file chooser dialog inviting the user to import a sound file; accept it" | aSound aName aFileStream fullName ext reply | aFileStream := FileList2 modalFileSelectorForSuffixes: #(#AIFF #aiff #Wave #wav #wave ). aFileStream ifNil: [^ self]. fullName := aFileStream name. ('*.AIFF' match: fullName) ifTrue: [aSound := SampledSound fromAIFFfileNamed: fullName] ifFalse: [aSound := SampledSound fromWaveStream: aFileStream]. aFileStream close. ext := FileDirectory extensionFor: fullName. aName := (FileDirectory on: fullName) pathParts last. ext size > 0 ifTrue: [aName := aName copyFrom: 1 to: (aName size - (ext size + 1))]. [reply := FillInTheBlank request: 'Please give a name for this sound' initialAnswer: aName. reply isEmptyOrNil ifTrue: [^ self]. (SampledSound soundLibrary includesKey: reply) ifTrue: [self inform: 'sorry, that name is already taken' translated. false] ifFalse: [true]] whileFalse. SampledSound addLibrarySoundNamed: reply samples: aSound samples samplingRate: aSound originalSamplingRate! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'kfr 9/23/2007 13:00'! pause soundIndex > 0 ifTrue: [currentSound pause]! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'kfr 9/23/2007 13:00'! play soundIndex > 0 ifTrue: [currentSound play]! ! !SoundLibraryTool methodsFor: 'menu' stamp: 'sw 10/19/2007 23:13'! renameSound "Rename the selected sound, if appropriate." | name newName | soundIndex = 0 ifTrue: [^ self inform: 'No sound selected' translated]. name := listBox getList at: soundIndex. (SampledSound universalSoundKeys includes: name) ifTrue: [^ self inform: 'You can not rename this sound' translated]. newName := FillInTheBlank request: 'New name for ' translated, name initialAnswer: name. (newName isEmptyOrNil or: [newName = name]) ifTrue: [^ self]. (SampledSound soundLibrary includesKey: newName) ifTrue: [^ self inform: 'sorry, that name is already used.' translated]. ScriptingSystem renameSound: name newName: newName. listBox updateList. self soundIndex: (listBox getList indexOf: newName)! ! !SoundLibraryTool methodsFor: 'miscellaneous' stamp: 'sw 10/19/2007 22:09'! setExtentFromHalo: anExtent "The user has dragged the grow box such that the receiver's extent would be anExtent. Do what's needed." submorphs third height: ((anExtent y - (submorphs first height + submorphs second height + 8)))! ! !SoundLibraryTool class methodsFor: 'parts bin' stamp: 'sw 10/20/2007 01:42'! descriptionForPartsBin "Answer a description of the receiver for use in a parts bin" ^ self partName: 'Sound Library' translatedNoop categories: {'Multimedia' translatedNoop} documentation: 'A tool for managing the sound library' translatedNoop! ! !StandardScriptingSystem methodsFor: 'sound library' stamp: 'sw 10/19/2007 21:43'! removeFromSoundLibrary: aSoundName "Allow the user to remove a user-added sound from the Sound library." | found | found := 0. SoundTile allInstances do: [:m | m literal = aSoundName ifTrue: [m literal: 'clink'. found := found + 1]]. SampledSound removeSoundNamed: aSoundName. found > 0 ifTrue: [self inform: found printString, ' tiles reverted to "clink"' translated]! ! !StandardScriptingSystem methodsFor: 'sound library' stamp: 'sw 10/19/2007 23:16'! renameSound: aSoundName newName: aNewName "Change the name of a given sound " | found | found := 0. SampledSound renameSound: aSoundName newName: aNewName. SoundTile allInstances do: [:m | m literal = aSoundName ifTrue: [m literal: aNewName. found := found + 1]]. found > 0 ifTrue: [self inform: found printString, ' tile(s) changed to "' translated, aNewName]! ! !TheWorldMenu methodsFor: '*flexibleVocabularies-construction' stamp: 'sw 10/20/2007 01:18'! fullScriptingMenu "Build the authoring-tools menu for the world. This method offeres all the item historically offered in the full etoy system; when eToyFriendly is on, most of the items are suppressed." ^ self fillIn: (self menu: 'authoring tools...') from: { { 'objects (o)' translated. { #myWorld . #activateObjectsTool }. 'A searchable source of new objects.' translated}. nil. "----------" { 'view trash contents' translated. { #myWorld . #openScrapsBook:}. 'The place where all your trashed morphs go.' translated}. { 'empty trash can' translated. { Utilities . #emptyScrapsBookGC}. 'Empty out all the morphs that have accumulated in the trash can.' translated}. nil. "----------" { 'sound library' translated. { SoundLibraryTool. #newInHand}.'A tool that lets you see and manage all the sounds in the sound library' translated}. { 'new scripting area' translated. { #myWorld . #detachableScriptingSpace}. 'A window set up for simple scripting.' translated}. nil. "----------" { 'status of scripts' translated. {#myWorld . #showStatusOfAllScripts}. 'Lets you view the status of all the scripts belonging to all the scripted objects of the project.' translated}. { 'summary of scripts' translated. {#myWorld . #printScriptSummary}. 'Produces a summary of scripted objects in the project, and all of their scripts.' translated}. { 'browser for scripts' translated. {#myWorld . #browseAllScriptsTextually}. 'Allows you to view all the scripts in the project in a traditional programmers'' "browser" format' translated}. nil. { 'gallery of players' translated. {#myWorld . #galleryOfPlayers}. 'A tool that lets you find out about all the players used in this project' translated}. " { 'gallery of scripts' translated. {#myWorld . #galleryOfScripts}. 'Allows you to view all the scripts in the project' translated}." { 'etoy vocabulary summary' . {#myWorld . #printVocabularySummary }. 'Displays a summary of all the pre-defined commands and properties in the pre-defined EToy vocabulary.' translated}. { 'attempt misc repairs' translated. {#myWorld . #attemptCleanup}. 'Take measures that may help fix up some things about a faulty or problematical project.' translated}. { 'remove all viewers' translated. {#myWorld . #removeAllViewers}. 'Remove all the Viewers from this project.' translated}. { 'refer to masters' translated. {#myWorld . #makeAllScriptEditorsReferToMasters }. 'Ensure that all script editors are referring to the first (alphabetically by external name) Player of their type' translated}. nil. "----------" { 'unlock locked objects' translated. { #myWorld . #unlockContents}. 'If any items on the world desktop are currently locked, unlock them.' translated}. { 'unhide hidden objects' translated. { #myWorld . #showHiders}. 'If any items on the world desktop are currently hidden, make them visible.' translated}. }! ! !TheWorldMenu methodsFor: '*flexibleVocabularies-construction' stamp: 'sw 10/20/2007 01:17'! scriptingMenu "Build the authoring-tools menu for the world. If eToyFriendly is set, a reduced menu is offered." Preferences eToyFriendly ifFalse: [^ self fullScriptingMenu]. ^ self fillIn: (self menu: 'authoring tools...') from: { { 'objects (o)' translated. { #myWorld . #activateObjectsTool }. 'A searchable source of new objects.' translated}. nil. "----------" { 'view trash contents' translated. { #myWorld . #openScrapsBook:}. 'The place where all your trashed morphs go.' translated}. { 'empty trash can' translated. { Utilities . #emptyScrapsBookGC}. 'Empty out all the morphs that have accumulated in the trash can.' translated}. nil. "----------" { 'sound library' translated. { SoundLibraryTool. #newInHand}.'A tool that lets you see and manage all the sounds in the sound library' translated}. "{ 'new scripting area' translated. { #myWorld . #detachableScriptingSpace}. 'A window set up for simple scripting.' translated}. nil. ""----------" { 'status of scripts' translated. {#myWorld . #showStatusOfAllScripts}. 'Lets you view the status of all the scripts belonging to all the scripted objects of the project.' translated}. "{ 'summary of scripts' translated. {#myWorld . #printScriptSummary}. 'Produces a summary of scripted objects in the project, and all of their scripts.'}." "{ 'browser for scripts' translated. {#myWorld . #browseAllScriptsTextually}. 'Allows you to view all the scripts in the project in a traditional programmers'' ""browser"" format'}." { 'gallery of players' translated. {#myWorld . #galleryOfPlayers}. 'A tool that lets you find out about all the players used in this project' translated}. nil. " { 'gallery of scripts' translated. {#myWorld . #galleryOfScripts}. 'Allows you to view all the scripts in the project' translated}." "{ 'etoy vocabulary summary' translated. {#myWorld . #printVocabularySummary }. 'Displays a summary of all the pre-defined commands and properties in the pre-defined EToy vocabulary.' translated}." "{ 'attempt misc repairs' translated. {#myWorld . #attemptCleanup}. 'Take measures that may help fix up some things about a faulty or problematical project.' translated}." { 'remove all viewers' translated. {#myWorld . #removeAllViewers}. 'Remove all the Viewers from this project.' translated}. "{ 'refer to masters' translated. {#myWorld . #makeAllScriptEditorsReferToMasters }. 'Ensure that all script editors are referring to the first (alphabetically by external name) Player of their type' translated}. " "nil." "----------" "{ 'unlock locked objects' translated. { #myWorld . #unlockContents}. 'If any items on the world desktop are currently locked, unlock them.' translated}." "{ 'unhide hidden objects' translated. { #myWorld . #showHiders}. 'If any items on the world desktop are currently hidden, make them visible.' translated}." }! !