Spaces:
Sleeping
Sleeping
File size: 1,149 Bytes
f23825d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import { IPoint } from "../geometry"
export default class TempoCoordTransform {
readonly pixelsPerTick: number
// グラフの描画領域の高さ
// Higher graph drawing area
readonly height: number
readonly maxBPM: number
constructor(pixelsPerTick: number, height: number, maxBPM = 320) {
this.pixelsPerTick = pixelsPerTick
this.height = height
this.maxBPM = maxBPM
}
getX(tick: number) {
return tick * this.pixelsPerTick
}
getY(bpm: number) {
return (1 - bpm / this.maxBPM) * this.height // 上下反転
}
getMaxY() {
return this.height
}
getTicks(pixels: number) {
return pixels / this.pixelsPerTick
}
getBPM(pixels: number) {
return (1 - pixels / this.height) * this.maxBPM
}
getDeltaBPM(pixels: number) {
return (-pixels / this.height) * this.maxBPM
}
equals(t: TempoCoordTransform) {
return (
this.pixelsPerTick === t.pixelsPerTick &&
this.height === t.height &&
this.maxBPM === t.maxBPM
)
}
fromPosition(position: IPoint) {
return {
tick: this.getTicks(position.x),
bpm: this.getBPM(position.y),
}
}
}
|