'From etoys2.2 of 24 September 2007 [latest update: #1715] on 20 October 2007 at 2:31:02 am'! "Change Set: kbdMorphForInput-kfr Date: 21 October 2007 Author: Karl Ramberg, tweaked by Scott Wallace Use the bigger font for the buttons on the KeyboardMorphForInput, and fix the bug that stopAllSounds, sent to such a keyboard, would generate an error."! PianoKeyboardMorph subclass: #KeyboardMorphForInput instanceVariableNames: 'pianoRoll duration durationModifier articulation buildingChord insertMode prevSelection startOfNextNote numberOfKeys' classVariableNames: '' poolDictionaries: '' category: 'Sound-Scores'! !KeyboardMorphForInput methodsFor: 'initialization' stamp: 'sw 10/18/2007 20:42'! addRecordingControls "Add chord, rest and delete buttons" | button switch playRow durRow articRow modRow | playRow _ AlignmentMorph newRow. playRow color: color; borderWidth: 0; layoutInset: 0. playRow hResizing: #shrinkWrap; vResizing: #shrinkWrap; extent: 5@5. switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. playRow addMorphBack: (switch label: 'chord' translated font: Preferences standardEToysButtonFont; actionSelector: #buildChord:). button _ SimpleButtonMorph new target: self; borderColor: #raised; borderWidth: 2; color: color. playRow addMorphBack: (button label: ' rest ' translated font: Preferences standardEToysButtonFont; actionSelector: #emitRest). button _ SimpleButtonMorph new target: self; borderColor: #raised; borderWidth: 2; color: color. playRow addMorphBack: (button label: 'del' translated font: Preferences standardEToysButtonFont; actionSelector: #deleteNotes). playRow cellInset: 6@4. self addMorphBack: playRow. playRow align: playRow fullBounds topCenter with: self fullBounds bottomCenter. "Add note duration buttons" durRow _ AlignmentMorph newRow. durRow color: color; borderWidth: 0; layoutInset: 0. durRow hResizing: #shrinkWrap; vResizing: #shrinkWrap; extent: 5@5. switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. durRow addMorphBack: (switch label: 'whole' translated font: Preferences standardEToysButtonFont; actionSelector: #duration:onOff:; arguments: #(1)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. durRow addMorphBack: (switch label: 'half' translated font: Preferences standardEToysButtonFont; actionSelector: #duration:onOff:; arguments: #(2)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. durRow addMorphBack: (switch label: 'quarter' translated font: Preferences standardEToysButtonFont; actionSelector: #duration:onOff:; arguments: #(4)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. durRow addMorphBack: (switch label: 'eighth' translated font: Preferences standardEToysButtonFont; actionSelector: #duration:onOff:; arguments: #(8)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. durRow addMorphBack: (switch label: 'sixteenth' translated font: Preferences standardEToysButtonFont; actionSelector: #duration:onOff:; arguments: #(16)). durRow cellInset: 4@4. self addMorphBack: durRow. durRow align: durRow fullBounds topCenter with: playRow fullBounds bottomCenter. "Add note duration modifier buttons" modRow _ AlignmentMorph newRow. modRow color: color; borderWidth: 0; layoutInset: 0. modRow hResizing: #shrinkWrap; vResizing: #shrinkWrap; extent: 5@5. switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. modRow addMorphBack: (switch label: 'dotted' translated font: Preferences standardEToysButtonFont; actionSelector: #durMod:onOff:; arguments: #(dotted)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. modRow addMorphBack: (switch label: 'normal' translated font: Preferences standardEToysButtonFont; actionSelector: #durMod:onOff:; arguments: #(normal)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. modRow addMorphBack: (switch label: 'triplets' translated font: Preferences standardEToysButtonFont; actionSelector: #durMod:onOff:; arguments: #(triplets)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. modRow addMorphBack: (switch label: 'quints' translated font: Preferences standardEToysButtonFont; actionSelector: #durMod:onOff:; arguments: #(quints)). modRow cellInset: 6@4. self addMorphBack: modRow. modRow align: modRow fullBounds topCenter with: durRow fullBounds bottomCenter. "Add articulation buttons" articRow _ AlignmentMorph newRow. articRow color: color; borderWidth: 0; layoutInset: 0. articRow hResizing: #shrinkWrap; vResizing: #shrinkWrap; extent: 5@5. switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. articRow addMorphBack: (switch label: 'legato' translated font: Preferences standardEToysButtonFont; actionSelector: #articulation:onOff:; arguments: #(legato)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. articRow addMorphBack: (switch label: 'normal' translated font: Preferences standardEToysButtonFont; actionSelector: #articulation:onOff:; arguments: #(normal)). switch _ SimpleSwitchMorph new target: self; borderWidth: 2; offColor: color; onColor: (Color r: 1.0 g: 0.6 b: 0.6); setSwitchState: false. articRow addMorphBack: (switch label: 'staccato' translated font: Preferences standardEToysButtonFont; actionSelector: #articulation:onOff:; arguments: #(staccato)). articRow cellInset: 6@4. self addMorphBack: articRow. articRow align: articRow fullBounds topCenter with: modRow fullBounds bottomCenter. self bounds: (self fullBounds expandBy: (0@0 extent: 0@borderWidth)) ! ! !KeyboardMorphForInput methodsFor: 'initialization' stamp: 'sw 10/19/2007 00:47'! initialize "initialize the state of the receiver" super initialize. numberOfKeys := submorphs size. "Before adding the controls." buildingChord _ false. self addRecordingControls. self duration: 4 onOff: true. self durMod: #normal onOff: true. self articulation: #normal onOff: true. insertMode _ false! ! !KeyboardMorphForInput methodsFor: 'private' stamp: 'sw 10/18/2007 22:41'! numberOfKeys "Answer the number of keys the receiver has. If, in grandfathered content, the numberOfKeys instance var is not set, compute it at this time." | firstPast | ^ numberOfKeys ifNil: [firstPast := submorphs detect: [:m | m isAlignmentMorph] ifNone: [nil]. numberOfKeys := firstPast ifNil: [submorphs size] ifNotNil: [(submorphs indexOf: firstPast) - 1]]! ! !KeyboardMorphForInput methodsFor: 'private' stamp: 'sw 10/18/2007 22:35'! stopAllSound "Stop all sounds associated with any of my keys." 1 to: self numberOfKeys do: [:i | self stopSoundAt: i] ! !