A new version of EnvelopeEditorRevival was added to project Etoys Inbox:
http://source.squeak.org/etoysinbox/EnvelopeEditorRevival-kfr.5.mcz ==================== Summary ==================== Name: EnvelopeEditorRevival-kfr.5 Author: kfr Time: 29 April 2014, 11:37 am UUID: 2abf9084-7a95-2a4d-a449-b652a7198e64 Ancestors: EnvelopeEditorRevival-kfr.4 More work to enable EnvelopeEditor to work in Etoys =============== Diff against EnvelopeEditorRevival-kfr.2 =============== Item was changed: RectangleMorph subclass: #EnvelopeEditorMorph + instanceVariableNames: 'sound soundName envelope hScale vScale graphArea pixPerTick limits limitXs limitHandles line prevMouseDown sampleDuration showAllEnvelopes denominator keyboard topRow flex' - instanceVariableNames: 'sound soundName envelope hScale vScale graphArea pixPerTick limits limitXs limitHandles line prevMouseDown sampleDuration showAllEnvelopes denominator keyboard' classVariableNames: '' poolDictionaries: '' category: 'EnvelopeEditorRevival'! Item was changed: ----- Method: EnvelopeEditorMorph>>addControls (in category 'construction') ----- addControls + | chooser aUpdatingString aWrapper aString | + aWrapper := AlignmentMorph newRow. + aString := StringMorph new contents: 'Editing: ' translated; + font: Preferences standardEToysButtonFont. + aWrapper addMorphBack: aString. - | chooser | chooser := PopUpChoiceMorph new extent: 200 @ 20; + contentsClipped: envelope name; - contentsClipped: 'Editing: ' , envelope name; target: self; actionSelector: #chooseFrom:envelopeItem:; getItemsSelector: #curveChoices. chooser arguments: (Array with: chooser). + aWrapper addMorphBack: chooser. + aString := StringMorph new contents: 'Timbre: ' translated; + font: Preferences standardEToysButtonFont. + aWrapper addMorphBack: aString. - self addMorph: chooser. - chooser align: chooser bounds topLeft with: graphArea bounds bottomLeft + (0 @ 5). chooser := PopUpChoiceMorph new extent: 250 @ 20; + contentsClipped: soundName; - contentsClipped: 'Timbre: ' , soundName; target: self; actionSelector: #chooseFrom:soundItem:; getItemsSelector: #soundChoices. chooser arguments: (Array with: chooser). + + aWrapper addMorphBack: chooser. + aString := StringMorph new contents: 'Vertical scale: ' translated; + font: Preferences standardEToysButtonFont. + aWrapper addMorphBack: aString. + + aUpdatingString := UpdatingStringMorph new target: self; + getSelector: #envelopeVerticalScale; + putSelector: #adjustScale:; + font: Preferences standardEToysButtonFont; + growable: false; + width: 70; + step. + aWrapper addMorphBack: aUpdatingString. + + self addMorph: aWrapper + fullFrame: (LayoutFrame fractions: (0@0.6 extent: 1@0.1)). + ! - self addMorph: chooser. - chooser align: chooser bounds topRight with: graphArea bounds bottomRight + (-50 @ 5)! Item was changed: ----- Method: EnvelopeEditorMorph>>addCurves (in category 'construction') ----- addCurves | aLine verts | sound envelopes do: [:env | (showAllEnvelopes or: [env == envelope]) ifTrue: [verts := env points collect: [:p | (self xFromMs: p x) @ (self yFromValue: p y)]. + aLine := EnvelopeLineMorph basicNew - aLine := EnvelopeLineMorph basicNew vertices: verts borderWidth: 1 + borderColor: (self colorForEnvelope: env) + editor: self. - borderColor: (self colorForEnvelope: env). env == envelope ifTrue: [aLine borderWidth: 2. line := aLine] ifFalse: [aLine on: #mouseUp send: #clickOn:evt:from: to: self withValue: env. + graphArea addMorph: aLine]]]. + graphArea addMorph: line! - self addMorph: aLine]]]. - self addMorph: line! Item was changed: ----- Method: EnvelopeEditorMorph>>addCustomMenuItems:hand: (in category 'menu') ----- addCustomMenuItems: menu hand: aHandMorph super addCustomMenuItems: menu hand: aHandMorph. menu addLine. envelope updateSelector = #ratio: ifTrue: [menu add: 'choose denominator...' translated action: #chooseDenominator:]. + - menu add: 'adjust scale...' translated action: #adjustScale:. SoundPlayer isReverbOn ifTrue: [menu add: 'turn reverb off' translated target: SoundPlayer selector: #stopReverb] ifFalse: [menu add: 'turn reverb on' translated target: SoundPlayer selector: #startReverb]. menu addLine. menu add: 'get sound from lib' translated action: #chooseSound:. menu add: 'put sound in lib' translated action: #saveSound:. menu add: 'read sound from disk...' translated action: #readFromDisk:. menu add: 'save sound on disk...' translated action: #saveToDisk:. menu add: 'save library on disk...' translated action: #saveLibToDisk:! Item was changed: ----- Method: EnvelopeEditorMorph>>addEnvelopeNamed: (in category 'editing') ----- addEnvelopeNamed: envName | points env | points := OrderedCollection new. points add: 0 @ 0.0; add: (envelope points at: envelope loopStartIndex) x @ 1.0; add: (envelope points at: envelope loopEndIndex) x @ 1.0; add: envelope points last x @ 0.0. envName = 'volume' ifTrue: [env := VolumeEnvelope points: points loopStart: 2 loopEnd: 3. env target: sound; scale: 0.7]. envName = 'modulation' ifTrue: [env := Envelope points: (points collect: [:p | p x @ 0.5]) loopStart: 2 loopEnd: 3. env target: sound; updateSelector: #modulation:; + scale:( (sound modulation * 2.0) max:0.1)]. - scale: sound modulation * 2.0]. envName = 'pitch' ifTrue: [env := PitchEnvelope points: (points collect: [:p | p x @ 0.5]) loopStart: 2 loopEnd: 3. env target: sound; updateSelector: #pitch:; scale: 0.5]. envName = 'random pitch:' ifTrue: [env := RandomEnvelope for: #pitch:. points := OrderedCollection new. points add: 0 @ (env delta * 5 + 0.5); add: (envelope points at: envelope loopStartIndex) x @ (env highLimit - 1 * 5 + 0.5); add: (envelope points at: envelope loopEndIndex) x @ (env highLimit - 1 * 5 + 0.5); add: envelope points last x @ (env lowLimit - 1 * 5 + 0.5). env setPoints: points loopStart: 2 loopEnd: 3. env target: sound]. envName = 'ratio' ifTrue: [denominator := 9999. env := Envelope points: (points collect: [:p | p x @ 0.5]) loopStart: 2 loopEnd: 3. env target: sound; updateSelector: #ratio:; + scale:( (sound modulation * 2.0) max:0.1)]. - scale: sound ratio * 2.0]. env ifNotNil: [sound addEnvelope: env. self editEnvelope: env]! Item was added: + ----- Method: EnvelopeEditorMorph>>addHandles (in category 'construction') ----- + addHandles + | handle | + handle := PolygonMorph + vertices: (Array + with: 0 @ 0 + with: 12 @ 0 + with: 6 @ 12) + color: Color orange + borderWidth: 1 + borderColor: Color black. + handle + addMorph: ((RectangleMorph + newBounds: ((self handleOffset: handle) + - (2 @ 0) extent: 1 @ (graphArea height - 2)) + color: Color orange) + borderWidth: 0). + limitHandles := Array + with: handle + with: handle veryDeepCopy + with: handle veryDeepCopy. + 1 + to: limitHandles size + do: [:i | + handle := limitHandles at: i. + handle + on: #mouseDown + send: #limitHandleMove:event:from: + to: self + withValue: i. + handle + on: #mouseMove + send: #limitHandleMove:event:from: + to: self + withValue: i. + graphArea addMorph: handle. + handle position: (self xFromMs: (envelope points + at: (limits at: i)) x) + @ graphArea top + - (self handleOffset: handle)]! Item was removed: - ----- Method: EnvelopeEditorMorph>>addHandlesIn: (in category 'construction') ----- - addHandlesIn: frame - | handle | - handle := PolygonMorph - vertices: (Array - with: 0 @ 0 - with: 8 @ 0 - with: 4 @ 8) - color: Color orange - borderWidth: 1 - borderColor: Color black. - handle - addMorph: ((RectangleMorph - newBounds: ((self handleOffset: handle) - - (2 @ 0) extent: 1 @ (graphArea height - 2)) - color: Color orange) - borderWidth: 0). - limitHandles := Array - with: handle - with: handle veryDeepCopy - with: handle veryDeepCopy. - 1 - to: limitHandles size - do: [:i | - handle := limitHandles at: i. - handle - on: #mouseDown - send: #limitHandleMove:event:from: - to: self - withValue: i. - handle - on: #mouseMove - send: #limitHandleMove:event:from: - to: self - withValue: i. - self addMorph: handle. - handle position: (self xFromMs: (envelope points - at: (limits at: i)) x) - @ graphArea top - - (self handleOffset: handle)]! Item was changed: ----- Method: EnvelopeEditorMorph>>addKeyboard (in category 'construction') ----- addKeyboard + keyboard := PianoKeyboardMorph new. + + self addMorph:keyboard + fullFrame: (LayoutFrame fractions: (0 @ 0.7 extent: 1 @ 0.3)). + keyboard vResizing: #rigid; hResizing: #rigid! - keyboard := PianoKeyboardMorph new soundPrototype: sound. - keyboard align: keyboard bounds bottomCenter with: bounds bottomCenter - (0 @ 4). - self addMorph: keyboard! Item was changed: ----- Method: EnvelopeEditorMorph>>adjustScale: (in category 'menu') ----- + adjustScale: aFloat + | oldScale baseValue | - adjustScale: evt - | scaleString oldScale baseValue | oldScale := envelope scale. + envelope scale: aFloat. - scaleString := UIManager default request: 'Enter the new full-scale value...' initialAnswer: oldScale printString. - scaleString isEmpty - ifTrue: [^ self]. - envelope scale: (Number readFrom: scaleString) asFloat. baseValue := envelope updateSelector = #pitch: ifTrue: [0.5] ifFalse: [0.0]. envelope setPoints: (envelope points collect: [:p | p x @ (p y - baseValue * oldScale / envelope scale + baseValue min: 1.0 max: 0.0)]) loopStart: limits first loopEnd: limits second. self buildView! Item was added: + ----- Method: EnvelopeEditorMorph>>buildGraphArea (in category 'construction') ----- + buildGraphArea + | r y | + (envelope updateSelector = #pitch: + and: [envelope scale <= 2.0]) + ifTrue: [r := graphArea innerBounds. + 0.0 + to: 1.0 + by: 1.0 / 12.0 / envelope scale + do: [:val | + y := self yFromValue: val. + graphArea + addMorph: ((RectangleMorph + newBounds: (r left @ y extent: r width @ 1) + color: Color blue) + borderWidth: 0)]]. + (envelope updateSelector = #ratio: + and: [denominator ~= 9999]) + ifTrue: [r := graphArea innerBounds. + (0.0 to: 1.0 by: 1.0 / denominator / envelope scale) + do: [:v | + y := self yFromValue: v. + graphArea + addMorph: ((RectangleMorph + newBounds: (r left @ y extent: r width @ 1) + color: Color blue) + borderWidth: 0)]]! Item was removed: - ----- Method: EnvelopeEditorMorph>>buildGraphAreaIn: (in category 'construction') ----- - buildGraphAreaIn: frame - | r y | - graphArea := RectangleMorph - newBounds: (frame left + 60 @ (frame top + 60) corner: frame right + 1 @ (frame bottom - 120)) - color: Color lightGreen lighter lighter. - graphArea borderWidth: 1; - borderColor: Color black. - self addMorph: graphArea. - (envelope updateSelector = #pitch: - and: [envelope scale <= 2.0]) - ifTrue: [r := graphArea innerBounds. - 0.0 - to: 1.0 - by: 1.0 / 12.0 / envelope scale - do: [:val | - y := self yFromValue: val. - graphArea - addMorph: ((RectangleMorph - newBounds: (r left @ y extent: r width @ 1) - color: Color veryLightGray) - borderWidth: 0)]]. - (envelope updateSelector = #ratio: - and: [denominator ~= 9999]) - ifTrue: [r := graphArea innerBounds. - (0.0 to: 1.0 by: 1.0 / denominator / envelope scale) - do: [:v | - y := self yFromValue: v. - graphArea - addMorph: ((RectangleMorph - newBounds: (r left @ y extent: r width @ 1) - color: Color veryLightGray) - borderWidth: 0)]]! Item was added: + ----- Method: EnvelopeEditorMorph>>buildScales (in category 'construction') ----- + buildScales + | env hmajortick hminortick | + env := envelope. + pixPerTick := graphArea width // (self maxTime // 10) max: 1. + hminortick := 1 + (self maxTime // 800) * 10. + hmajortick := 1 + (self maxTime // 800) * 100. + hScale start: 0 + stop: self maxTime + direction: #left + minorTick: hminortick + minorTickLength: 3 + majorTick: hmajortick + majorTickLength: 10 + caption: 'milliseconds' + tickPrintBlock: [:v | v printString]. + + vScale width: graphArea height; height:hScale left - self left. + + env name = 'pitch' + ifTrue: [env scale >= 2.0 + ifTrue: [vScale + start: 0 + stop: env scale + direction: #left + minorTick: env scale / 24 + minorTickLength: 3 + majorTick: env scale / 2.0 + majorTickLength: 10 + caption: 'pitch (octaves)' + tickPrintBlock: [:v | (v - (env scale / 2)) asInteger printString]] + ifFalse: [vScale + start: 0 + stop: env scale + direction: #left + minorTick: 1.0 / 48.0 + minorTickLength: 3 + majorTick: 1.0 / 12.0 + majorTickLength: 10 + caption: 'pitch (half-steps)' + tickPrintBlock: [:v | (v - (env scale / 2) * 12) rounded printString]]] + ifFalse: [env name = 'random pitch:' + ifTrue: [vScale + start: 0.9 + stop: 1.1 + direction: #left + minorTick: 0.2 / 50.0 + minorTickLength: 3 + majorTick: 0.2 / 5.0 + majorTickLength: 10 + caption: env name + tickPrintBlock: [:v | v printString]] + ifFalse: [vScale start: 0 + stop: env scale + direction: #left + minorTick: env scale / 50.0 + minorTickLength: 3 + majorTick: env scale / 5.0 + majorTickLength: 10 + caption: env name + tickPrintBlock: [:v | v printString]]]. + flex scale: 1 + ! Item was removed: - ----- Method: EnvelopeEditorMorph>>buildScalesIn: (in category 'construction') ----- - buildScalesIn: frame - | env hmajortick hminortick | - env := envelope. - pixPerTick := graphArea width // (self maxTime // 10) max: 1. - hminortick := 1 + (self maxTime // 800) * 10. - hmajortick := 1 + (self maxTime // 800) * 100. - hScale := (ScaleMorph - newBounds: (graphArea left @ frame top corner: (self xFromMs: self maxTime) - @ (graphArea top - 1))) - start: 0 - stop: self maxTime - minorTick: hminortick - minorTickLength: 3 - majorTick: hmajortick - majorTickLength: 10 - caption: 'milliseconds' - tickPrintBlock: [:v | v printString]. - self addMorph: hScale. - vScale := ScaleMorph - newBounds: (0 @ 0 extent: graphArea height @ (graphArea left - frame left)). - env name = 'pitch' - ifTrue: [env scale >= 2.0 - ifTrue: [vScale - start: 0 - stop: env scale - minorTick: env scale / 24 - minorTickLength: 3 - majorTick: env scale / 2.0 - majorTickLength: 10 - caption: 'pitch (octaves)' - tickPrintBlock: [:v | (v - (env scale / 2)) asInteger printString]] - ifFalse: [vScale - start: 0 - stop: env scale - minorTick: 1.0 / 48.0 - minorTickLength: 3 - majorTick: 1.0 / 12.0 - majorTickLength: 10 - caption: 'pitch (half-steps)' - tickPrintBlock: [:v | (v - (env scale / 2) * 12) rounded printString]]] - ifFalse: [env name = 'random pitch:' - ifTrue: [vScale - start: 0.9 - stop: 1.1 - minorTick: 0.2 / 50.0 - minorTickLength: 3 - majorTick: 0.2 / 5.0 - majorTickLength: 10 - caption: env name - tickPrintBlock: [:v | v printString]] - ifFalse: [vScale - start: 0 - stop: env scale - minorTick: env scale / 50.0 - minorTickLength: 3 - majorTick: env scale / 5.0 - majorTickLength: 10 - caption: env name - tickPrintBlock: [:v | v printString]]]. - vScale := TransformationMorph new asFlexOf: vScale. - vScale angle: Float pi / 2.0. - self addMorph: vScale. - vScale position: frame left @ (graphArea top - 1) - (2 @ 1)! Item was changed: ----- Method: EnvelopeEditorMorph>>buildView (in category 'construction') ----- buildView + | | + + graphArea removeAllMorphs. + + self buildGraphArea. + self buildScales. + self addHandles. - | frame | - self color: Color lightGreen. - self removeAllMorphs. - frame := self innerBounds. - self buildGraphAreaIn: frame. - self buildScalesIn: frame. - self addHandlesIn: frame. self addCurves. line addHandles. + ! - self addControls. - self addKeyboard! Item was changed: ----- Method: EnvelopeEditorMorph>>deletePoint: (in category 'editing') ----- deletePoint: ix + "(limits includes: ix) + ifTrue: [^ false]." + Transcript show: ix asString; cr. - (limits includes: ix) - ifTrue: [^ false]. 1 to: limits size do: [:i | (limits at: i) + >= ix + ifTrue: [limits at: i put: (limits at: i)- 1]]. + Transcript show: limits asString; cr. - > ix - ifTrue: [limits at: i put: (limits at: i) - - 1]]. envelope setPoints: (envelope points copyReplaceFrom: ix to: ix with: Array new) loopStart: limits first loopEnd: limits second. ^ true! Item was added: + ----- Method: EnvelopeEditorMorph>>envelopeVerticalScale (in category 'as yet unclassified') ----- + envelopeVerticalScale + ^envelope scale! Item was removed: - ----- Method: EnvelopeEditorMorph>>extent: (in category 'geometry') ----- - extent: newExtent - super - extent: (newExtent max: (self maxTime // 10 * 3 + 700 max: 500) - @ 350). - self buildView! Item was changed: ----- Method: EnvelopeEditorMorph>>initialize (in category 'initialization') ----- initialize + | | super initialize. prevMouseDown := false. showAllEnvelopes := true. + self layoutPolicy: ProportionalLayout new. + self extent: 730@500. + graphArea := RectangleMorph new color: Color lightGreen lighter lighter. + graphArea borderWidth: 1; + borderColor: Color black. + self addMorph: graphArea + fullFrame: (LayoutFrame fractions: (0.1@0.1 extent: 0.9@0.5)). + hScale := (ScaleMorph + new width: graphArea width). + self addMorph: hScale + fullFrame: (LayoutFrame fractions: (0.1@0 extent: 0.9@0.1)). + hScale goBehind. + vScale := ScaleMorph + new width: graphArea height. + flex := TransformationMorph new asFlexOf: vScale. + flex angle: Float pi / 2.0. + + self addMorph: flex + fullFrame: (LayoutFrame fractions: (0@0.1 extent: 0.1@0.5)). + flex goBehind. + + self addKeyboard. soundName ifNil: [soundName := 'test']. self editSound: (sound ifNil: [FMSound brass1 copy]). sound duration: 0.25. denominator := 7. + self addControls. + + ! - self extent: 10 @ 10! Item was changed: ----- Method: EnvelopeLineMorph>>dragVertex:event:fromHandle: (in category 'editing') ----- dragVertex: ix event: evt fromHandle: handle | p | super dragVertex: ix event: evt fromHandle: handle. + p := editor acceptGraphPoint: evt cursorPoint at: ix. - p := owner acceptGraphPoint: evt cursorPoint at: ix. self verticesAt: ix put: p! Item was changed: ----- Method: EnvelopeLineMorph>>dropVertex:event:fromHandle: (in category 'editing') ----- dropVertex: ix event: evt fromHandle: handle | oldVerts | oldVerts := vertices. super dropVertex: ix event: evt fromHandle: handle. vertices = oldVerts + ifFalse: [editor deletePoint: ix]! - ifFalse: [owner deletePoint: ix]! Item was added: + ----- Method: EnvelopeLineMorph>>editor: (in category 'initialization') ----- + editor: aEditor + editor := aEditor! Item was changed: ----- Method: EnvelopeLineMorph>>newVertex:event:fromHandle: (in category 'editing') ----- newVertex: ix event: evt fromHandle: handle + (editor insertPointAfter: ix) - (owner insertPointAfter: ix) ifFalse: [^ self]. super newVertex: ix event: evt fromHandle: handle. self verticesAt: ix + 1 + put: (editor acceptGraphPoint: evt cursorPoint at: ix + 1)! - put: (owner acceptGraphPoint: evt cursorPoint at: ix + 1)! Item was removed: - ----- Method: EnvelopeLineMorph>>vertices:borderWidth:borderColor: (in category 'as yet unclassified') ----- - vertices: verts borderWidth: bw borderColor: bc - super initialize. - vertices := verts. - borderWidth := bw. - borderColor := bc. - closed := false. - arrows := #none. - self computeBounds! Item was added: + ----- Method: EnvelopeLineMorph>>vertices:borderWidth:borderColor:editor: (in category 'as yet unclassified') ----- + vertices: verts borderWidth: bw borderColor: bc editor: aEditor + super initialize. + vertices := verts. + borderWidth := bw. + borderColor := bc. + editor := aEditor. + closed := false. + arrows := #none. + self computeBounds! Item was changed: RectangleMorph subclass: #ScaleMorph + instanceVariableNames: 'caption start stop minorTick minorTickLength majorTick majorTickLength tickPrintBlock direction' - instanceVariableNames: 'caption start stop minorTick minorTickLength majorTick majorTickLength tickPrintBlock' classVariableNames: 'ClassVarName1 ClassVarName2' poolDictionaries: '' category: 'EnvelopeEditorRevival'! Item was changed: ----- Method: ScaleMorph>>initialize (in category 'as yet unclassified') ----- initialize super initialize. borderWidth := 0. color := Color lightGreen. + direction := #left. start := 0. stop := 100. minorTick := 1. majorTick := 10. minorTickLength := 3. majorTickLength := 10. caption := 'sample'. tickPrintBlock := [:v | v printString]! Item was added: + ----- Method: ScaleMorph>>start:stop:direction:minorTick:minorTickLength:majorTick:majorTickLength:caption:tickPrintBlock: (in category 'as yet unclassified') ----- + start: strt stop: stp direction: dir minorTick: mnt minorTickLength: mntLen majorTick: mjt majorTickLength: mjtLen caption: cap tickPrintBlock: blk + start := strt. + stop := stp. + direction := dir. + minorTick := mnt. + minorTickLength := mntLen. + majorTick := mjt. + majorTickLength := mjtLen. + caption := cap. + tickPrintBlock := blk fixTemps. + self buildLabels! Item was removed: - ----- Method: ScaleMorph>>start:stop:minorTick:minorTickLength:majorTick:majorTickLength:caption:tickPrintBlock: (in category 'as yet unclassified') ----- - start: strt stop: stp minorTick: mnt minorTickLength: mntLen majorTick: mjt majorTickLength: mjtLen caption: cap tickPrintBlock: blk - start := strt. - stop := stp. - minorTick := mnt. - minorTickLength := mntLen. - majorTick := mjt. - majorTickLength := mjtLen. - caption := cap. - tickPrintBlock := blk fixTemps. - self buildLabels! Item was added: + ----- Method: ScaleMorph>>stop (in category 'as yet unclassified') ----- + stop + ^stop! Item was added: + ----- Method: ScaleMorph>>stop: (in category 'as yet unclassified') ----- + stop: aNumber + stop := aNumber. + self buildLabels! _______________________________________________ etoys-dev mailing list [hidden email] http://lists.squeakland.org/mailman/listinfo/etoys-dev |
Free forum by Nabble | Edit this page |