Mercurial > hg > ugly-duckling
comparison src/app/waveform/waveform.component.ts @ 96:42b29cdff5ef
Keep the time centered when zooming from where the pinch starts, and stop panning being so fast. Panning still isn't doing anything sensible.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 24 Feb 2017 13:54:53 +0000 |
parents | a335107e5246 |
children | f8436dd53e7f |
comparison
equal
deleted
inserted
replaced
95:332073276015 | 96:42b29cdff5ef |
---|---|
161 mainTrack.render(); | 161 mainTrack.render(); |
162 mainTrack.update(); | 162 mainTrack.update(); |
163 | 163 |
164 | 164 |
165 if ('ontouchstart' in window) { | 165 if ('ontouchstart' in window) { |
166 console.log('TOUCH!'); | |
167 const hammertime = new Hammer(this.trackDiv.nativeElement); | 166 const hammertime = new Hammer(this.trackDiv.nativeElement); |
168 const scroll = (ev) => { | 167 const scroll = (ev) => { |
169 const sign = ev.direction === Hammer.DIRECTION_LEFT ? -1 : 1; | 168 const sign = ev.direction === Hammer.DIRECTION_LEFT ? -1 : 1; |
170 let delta = this.timeline.timeContext.timeToPixel.invert(sign * ev.distance); | 169 let delta = this.timeline.timeContext.timeToPixel.invert(sign * ev.distance); |
171 if (Math.abs(ev.velocityX) < 2 /*arbitrary, it just felt a bit better than 1*/) { | 170 const speed: number = Math.abs(ev.velocityX); |
172 delta *= Math.abs(ev.velocityX); | 171 delta *= (speed > 0.075 ? 0.075 : speed); // this is completely made up to limit the max speed, TODO something sensible |
173 } | |
174 this.timeline.timeContext.offset += delta; | 172 this.timeline.timeContext.offset += delta; |
175 this.timeline.tracks.update(); | 173 this.timeline.tracks.update(); |
176 }; | 174 }; |
177 | 175 |
178 const zoom = (ev) => { | 176 const zoom = (ev) => { |
179 const minZoom = this.timeline.state.minZoom; | 177 const minZoom = this.timeline.state.minZoom; |
180 const maxZoom = this.timeline.state.maxZoom; | 178 const maxZoom = this.timeline.state.maxZoom; |
181 const initialZoom = this.timeline.timeContext.zoom; | 179 const initialZoom = this.timeline.timeContext.zoom; |
182 const targetZoom = initialZoom * ev.scale; | 180 const targetZoom = initialZoom * ev.scale; |
181 const lastCenterTime = this.timeline.timeContext.timeToPixel.invert(ev.center.x); | |
183 this.timeline.timeContext.zoom = Math.min(Math.max(targetZoom, minZoom), maxZoom); | 182 this.timeline.timeContext.zoom = Math.min(Math.max(targetZoom, minZoom), maxZoom); |
183 const newCenterTime = this.timeline.timeContext.timeToPixel.invert(ev.center.x); | |
184 this.timeline.timeContext.offset += newCenterTime - lastCenterTime; | |
184 this.timeline.tracks.update(); | 185 this.timeline.tracks.update(); |
185 }; | 186 }; |
186 const seek = (ev) => { | 187 const seek = (ev) => { |
187 this.audioService.seekTo( | 188 this.audioService.seekTo( |
188 this.timeline.timeContext.timeToPixel.invert(ev.center.x) - this.timeline.timeContext.offset | 189 this.timeline.timeContext.timeToPixel.invert(ev.center.x) - this.timeline.timeContext.offset |