🔀 merge(C5): the equalizer grew into its window — ten draggable bands, numbers you can read, bells you can see
Browse files at this commit2 changed files +526 -96
- crates/app/src/keymap.rs +27 -2
- crates/app/src/main.rs +499 -94
crates/app/src/keymap.rsmodified+27 -2
| @@ -333,7 +333,7 @@ pub struct Fixed { | |||
| 333 | pub category: Category, | 333 | pub category: Category, |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | -pub const FIXED: [Fixed; 21] = [ | 336 | +pub const FIXED: [Fixed; 26] = [ |
| 337 | // Not a chord at all but a way of pressing one, and the only place the | 337 | // Not a chord at all but a way of pressing one, and the only place the |
| 338 | // editor can say so: holding a key that moves a *value* runs it, and | 338 | // editor can say so: holding a key that moves a *value* runs it, and |
| 339 | // holding anything else still does what one press did. | 339 | // holding anything else still does what one press did. |
| @@ -401,7 +401,7 @@ pub const FIXED: [Fixed; 21] = [ | |||
| 401 | // its own: a band nothing but a drag can reach is a band half the users of | 401 | // its own: a band nothing but a drag can reach is a band half the users of |
| 402 | // this editor cannot move at all. Card-local, so none of them is bindable. | 402 | // this editor cannot move at all. Card-local, so none of them is bindable. |
| 403 | Fixed { | 403 | Fixed { |
| 404 | - chord: "1–5", | 404 | + chord: "1–9, 0", |
| 405 | label: "Pick an equalizer band", | 405 | label: "Pick an equalizer band", |
| 406 | category: Category::Audio, | 406 | category: Category::Audio, |
| 407 | }, | 407 | }, |
| @@ -415,6 +415,31 @@ pub const FIXED: [Fixed; 21] = [ | |||
| 415 | label: "Lower the picked band 1 dB", | 415 | label: "Lower the picked band 1 dB", |
| 416 | category: Category::Audio, | 416 | category: Category::Audio, |
| 417 | }, | 417 | }, |
| 418 | + Fixed { | ||
| 419 | + chord: "← / →", | ||
| 420 | + label: "Move the picked band down or up in frequency", | ||
| 421 | + category: Category::Audio, | ||
| 422 | + }, | ||
| 423 | + Fixed { | ||
| 424 | + chord: "shift ← / →", | ||
| 425 | + label: "Widen or narrow the picked band (its Q)", | ||
| 426 | + category: Category::Audio, | ||
| 427 | + }, | ||
| 428 | + Fixed { | ||
| 429 | + chord: "a", | ||
| 430 | + label: "Add an equalizer band beside the picked one", | ||
| 431 | + category: Category::Audio, | ||
| 432 | + }, | ||
| 433 | + Fixed { | ||
| 434 | + chord: "x", | ||
| 435 | + label: "Remove the picked equalizer band", | ||
| 436 | + category: Category::Audio, | ||
| 437 | + }, | ||
| 438 | + Fixed { | ||
| 439 | + chord: "f", | ||
| 440 | + label: "Flatten the picked band (double-click does the same)", | ||
| 441 | + category: Category::Audio, | ||
| 442 | + }, | ||
| 418 | Fixed { | 443 | Fixed { |
| 419 | chord: "r", | 444 | chord: "r", |
| 420 | label: "Flatten every band", | 445 | label: "Flatten every band", |
crates/app/src/main.rsmodified+499 -94
| @@ -569,6 +569,36 @@ const EQ_FREQ_HIGH: f32 = 20_000.; | |||
| 569 | /// and short enough that the card still fits a 360 px window. | 569 | /// and short enough that the card still fits a 360 px window. |
| 570 | const EQ_GRAPH_H: f32 = 132.; | 570 | const EQ_GRAPH_H: f32 = 132.; |
| 571 | 571 | ||
| 572 | +/// How wide the equalizer card is allowed to get. It is the one card that is a | ||
| 573 | +/// *graph*: every pixel across is frequency resolution, and at the 320 px the | ||
| 574 | +/// other cards use, a third of an octave was a couple of pixels. Past this the | ||
| 575 | +/// curve stops gaining anything and the card starts reading as a wall. | ||
| 576 | +const EQ_W_MAX: f32 = 720.; | ||
| 577 | + | ||
| 578 | +/// The gap the card leaves either side of it, so it reads as a card on a scrim | ||
| 579 | +/// rather than as a second window: it takes the width it can get inside that. | ||
| 580 | +const EQ_W_MARGIN: f32 = 32.; | ||
| 581 | + | ||
| 582 | +/// How many bands one clip's equalizer may carry from this card. Ten because | ||
| 583 | +/// the keyboard picks a band with a digit and a keyboard has ten of them -- | ||
| 584 | +/// past that a band would be reachable by pointer only. The engine itself caps | ||
| 585 | +/// nothing (`EqParams::bands` is a plain `Vec`), so a file may still carry more | ||
| 586 | +/// and this card will draw and edit every one it finds. | ||
| 587 | +const EQ_BANDS_MAX: usize = 10; | ||
| 588 | + | ||
| 589 | +/// One press of the frequency keys, as a factor: a sixth of an octave, so a | ||
| 590 | +/// band walks the whole axis in about sixty presses and still lands close | ||
| 591 | +/// enough to a named frequency to aim at one. | ||
| 592 | +const EQ_FREQ_STEP: f32 = 1.122_462; | ||
| 593 | + | ||
| 594 | +/// One press of the Q keys, as a factor, and the range they move in. Below the | ||
| 595 | +/// bottom a peak is barely a peak any more; above the top it is a whistle on | ||
| 596 | +/// one frequency. 0.707 -- the flat-shelf value, and the default -- sits inside | ||
| 597 | +/// them, so nothing a file carries has to be dragged into range first. | ||
| 598 | +const EQ_Q_STEP: f32 = 1.25; | ||
| 599 | +const EQ_Q_LOW: f32 = 0.3; | ||
| 600 | +const EQ_Q_HIGH: f32 = 12.; | ||
| 601 | + | ||
| 572 | /// How many points the curve is drawn from. One per ~3 px across the card: | 602 | /// How many points the curve is drawn from. One per ~3 px across the card: |
| 573 | /// past that the line is smooth and the extra biquad evaluations are wasted. | 603 | /// past that the line is smooth and the extra biquad evaluations are wasted. |
| 574 | const EQ_CURVE_STEPS: usize = 96; | 604 | const EQ_CURVE_STEPS: usize = 96; |
| @@ -617,6 +647,11 @@ const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |||
| 617 | /// its weight: it is what makes a boost read as a hill rather than as a wire. | 647 | /// its weight: it is what makes a boost read as a hill rather than as a wire. |
| 618 | const EQ_FILL_INK: u32 = 0x4a9eff26; | 648 | const EQ_FILL_INK: u32 = 0x4a9eff26; |
| 619 | 649 | ||
| 650 | +/// One band's own response, drawn under the sum: a dim thread per band, so a | ||
| 651 | +/// boost pushed against a cut can be *seen* as two bands rather than as the | ||
| 652 | +/// flat line their total makes. | ||
| 653 | +const EQ_BELL_INK: u32 = 0x4a9eff66; | ||
| 654 | + | ||
| 620 | /// The colour card's four controls, in the order it lists them: what each is | 655 | /// The colour card's four controls, in the order it lists them: what each is |
| 621 | /// called and the range it moves in. The order is `ColorParams`' own, which is | 656 | /// called and the range it moves in. The order is `ColorParams`' own, which is |
| 622 | /// what [`color_band`] indexes. | 657 | /// what [`color_band`] indexes. |
| @@ -2034,41 +2069,78 @@ impl Player { | |||
| 2034 | cx.notify(); | 2069 | cx.notify(); |
| 2035 | } | 2070 | } |
| 2036 | 2071 | ||
| 2037 | - /// Moves one band and says whether anything changed. Live only: the write | 2072 | + /// Changes the picked band in place and says whether anything moved. Every |
| 2038 | - /// is [`commit_eq`](Player::commit_eq)'s. | 2073 | + /// edit of a band goes through here -- the drag, each key, each stepper |
| 2039 | - fn set_band(&mut self, band: usize, gain_db: f32) -> bool { | 2074 | + /// button -- so the card has exactly one place that clamps a band into what |
| 2040 | - let gain_db = gain_db.clamp(-EQ_GAIN_LIMIT, EQ_GAIN_LIMIT); | 2075 | + /// the graph can draw, and no caller has to remember the limits. |
| 2041 | - match self.eq_params.bands.get_mut(band) { | 2076 | + fn set_band(&mut self, change: impl FnOnce(&mut Band)) -> bool { |
| 2042 | - Some(b) if b.gain_db != gain_db => { | 2077 | + let Some(band) = self.eq_params.bands.get_mut(self.eq_band) else { |
| 2043 | - b.gain_db = gain_db; | 2078 | + return false; |
| 2044 | - true | 2079 | + }; |
| 2045 | - } | 2080 | + let was = *band; |
| 2046 | - _ => false, | 2081 | + change(band); |
| 2082 | + band.freq_hz = band.freq_hz.clamp(EQ_FREQ_LOW, EQ_FREQ_HIGH); | ||
| 2083 | + band.gain_db = band.gain_db.clamp(-EQ_GAIN_LIMIT, EQ_GAIN_LIMIT); | ||
| 2084 | + band.q = band.q.clamp(EQ_Q_LOW, EQ_Q_HIGH); | ||
| 2085 | + *band != was | ||
| 2086 | + } | ||
| 2087 | + | ||
| 2088 | + /// The keyboard's and the buttons' version of a drag: one step on the picked | ||
| 2089 | + /// band, committed straight away -- neither has a release to wait for. | ||
| 2090 | + fn nudge_band(&mut self, change: impl FnOnce(&mut Band), cx: &mut Context<Self>) { | ||
| 2091 | + if self.set_band(change) { | ||
| 2092 | + self.commit_eq(cx); | ||
| 2047 | } | 2093 | } |
| 2048 | } | 2094 | } |
| 2049 | 2095 | ||
| 2050 | - /// The keyboard's version of a drag: one step on the picked band, committed | 2096 | + /// Where the pointer sits in the graph, as the picked band's frequency and |
| 2051 | - /// straight away -- a keystroke has no release to wait for. | 2097 | + /// gain: across is the frequency axis and down is the gain one, so the |
| 2052 | - fn nudge_band(&mut self, by: f32, cx: &mut Context<Self>) { | 2098 | + /// handle follows the hand both ways rather than sliding up a rail. Called |
| 2053 | - let gain = self | 2099 | + /// on every pointer sample, so the curve bends under it; the write is the |
| 2054 | - .eq_params | 2100 | + /// release's ([`commit_eq`](Player::commit_eq)). |
| 2055 | - .bands | 2101 | + fn drag_band(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) { |
| 2056 | - .get(self.eq_band) | 2102 | + let bounds = self.eq_graph.get(); |
| 2057 | - .map_or(0., |b| b.gain_db); | 2103 | + let gain = (0.5 - frac_down(at.y, bounds)) * 2. * EQ_GAIN_LIMIT; |
| 2058 | - if self.set_band(self.eq_band, gain + by) { | 2104 | + let freq = eq_freq(frac_along(at.x, bounds)); |
| 2059 | - self.commit_eq(cx); | 2105 | + if self.set_band(|b| { |
| 2106 | + b.gain_db = gain; | ||
| 2107 | + b.freq_hz = freq; | ||
| 2108 | + }) { | ||
| 2109 | + cx.notify(); | ||
| 2060 | } | 2110 | } |
| 2061 | } | 2111 | } |
| 2062 | 2112 | ||
| 2063 | - /// Where the pointer sits down the graph, as a gain on the picked band: the | 2113 | + /// A band added beside the picked one, at the frequency with the most room |
| 2064 | - /// middle is flat and the top and bottom edges are the limit either way. | 2114 | + /// around it ([`inserted_band`]), and picked so the next keystroke moves the |
| 2065 | - /// Called on every pointer sample, so the curve bends under the hand; the | 2115 | + /// band that was just made. Refused rather than silently ignored at the cap. |
| 2066 | - /// write is the release's ([`commit_eq`](Player::commit_eq)). | 2116 | + fn add_band(&mut self, cx: &mut Context<Self>) { |
| 2067 | - fn drag_band(&mut self, y: Pixels, cx: &mut Context<Self>) { | 2117 | + if self.eq_params.bands.len() >= EQ_BANDS_MAX { |
| 2068 | - let gain = (0.5 - frac_down(y, self.eq_graph.get())) * 2. * EQ_GAIN_LIMIT; | 2118 | + self.notice = Some( |
| 2069 | - if self.set_band(self.eq_band, gain) { | 2119 | + format!( |
| 2120 | + "EQUALIZER FULL — {EQ_BANDS_MAX} bands is all this card holds; move one instead" | ||
| 2121 | + ) | ||
| 2122 | + .into(), | ||
| 2123 | + ); | ||
| 2070 | cx.notify(); | 2124 | cx.notify(); |
| 2125 | + return; | ||
| 2071 | } | 2126 | } |
| 2127 | + let band = inserted_band(&self.eq_params.bands, self.eq_band); | ||
| 2128 | + self.eq_band = (self.eq_band + 1).min(self.eq_params.bands.len()); | ||
| 2129 | + self.eq_params.bands.insert(self.eq_band, band); | ||
| 2130 | + self.commit_eq(cx); | ||
| 2131 | + } | ||
| 2132 | + | ||
| 2133 | + /// Takes the picked band out. The last one stays: an equalizer of no bands | ||
| 2134 | + /// is a card with nothing to edit, and flattening is what "off" means here. | ||
| 2135 | + fn remove_band(&mut self, cx: &mut Context<Self>) { | ||
| 2136 | + if self.eq_params.bands.len() <= 1 { | ||
| 2137 | + self.notice = Some("LAST BAND — flatten it instead (r), or close the card".into()); | ||
| 2138 | + cx.notify(); | ||
| 2139 | + return; | ||
| 2140 | + } | ||
| 2141 | + self.eq_params.bands.remove(self.eq_band); | ||
| 2142 | + self.eq_band = self.eq_band.min(self.eq_params.bands.len() - 1); | ||
| 2143 | + self.commit_eq(cx); | ||
| 2072 | } | 2144 | } |
| 2073 | 2145 | ||
| 2074 | /// Which band a press on the graph grabs: the nearest one along the | 2146 | /// Which band a press on the graph grabs: the nearest one along the |
| @@ -3778,31 +3850,55 @@ impl Render for Player { | |||
| 3778 | // cannot move at all, and every one of them is listed in the | 3850 | // cannot move at all, and every one of them is listed in the |
| 3779 | // keys menu (keymap.rs `FIXED`) rather than being a secret. | 3851 | // keys menu (keymap.rs `FIXED`) rather than being a secret. |
| 3780 | if this.eq_open.is_some() { | 3852 | if this.eq_open.is_some() { |
| 3853 | + // Shift makes the two horizontal keys Q instead of | ||
| 3854 | + // frequency: both are the *width* of the same hump, so they | ||
| 3855 | + // sit on the same axis rather than on two keys nobody would | ||
| 3856 | + // guess. Wider is a lower Q, which is why left widens. | ||
| 3857 | + let shift = event.keystroke.modifiers.shift; | ||
| 3781 | if key == ESCAPE { | 3858 | if key == ESCAPE { |
| 3782 | // Nothing to undo: every change is already at the clip, | 3859 | // Nothing to undo: every change is already at the clip, |
| 3783 | // and undo is undo's own key. | 3860 | // and undo is undo's own key. |
| 3784 | this.eq_open = None; | 3861 | this.eq_open = None; |
| 3785 | this.eq_dragging = false; | 3862 | this.eq_dragging = false; |
| 3786 | } else if key == "up" { | 3863 | } else if key == "up" { |
| 3787 | - this.nudge_band(EQ_STEP, cx); | 3864 | + this.nudge_band(|b| b.gain_db += EQ_STEP, cx); |
| 3788 | } else if key == "down" { | 3865 | } else if key == "down" { |
| 3789 | - this.nudge_band(-EQ_STEP, cx); | 3866 | + this.nudge_band(|b| b.gain_db -= EQ_STEP, cx); |
| 3867 | + } else if key == "left" && shift { | ||
| 3868 | + this.nudge_band(|b| b.q /= EQ_Q_STEP, cx); | ||
| 3869 | + } else if key == "right" && shift { | ||
| 3870 | + this.nudge_band(|b| b.q *= EQ_Q_STEP, cx); | ||
| 3871 | + } else if key == "left" { | ||
| 3872 | + this.nudge_band(|b| b.freq_hz /= EQ_FREQ_STEP, cx); | ||
| 3873 | + } else if key == "right" { | ||
| 3874 | + this.nudge_band(|b| b.freq_hz *= EQ_FREQ_STEP, cx); | ||
| 3790 | } else if key == "r" { | 3875 | } else if key == "r" { |
| 3791 | for band in &mut this.eq_params.bands { | 3876 | for band in &mut this.eq_params.bands { |
| 3792 | band.gain_db = 0.; | 3877 | band.gain_db = 0.; |
| 3793 | } | 3878 | } |
| 3794 | this.commit_eq(cx); | 3879 | this.commit_eq(cx); |
| 3880 | + } else if key == "f" { | ||
| 3881 | + // This one band back to flat, which is the undo of one | ||
| 3882 | + // hand movement -- `r` is the undo of the whole card. | ||
| 3883 | + this.nudge_band(|b| b.gain_db = 0., cx); | ||
| 3884 | + } else if key == "a" { | ||
| 3885 | + this.add_band(cx); | ||
| 3886 | + } else if key == "x" { | ||
| 3887 | + this.remove_band(cx); | ||
| 3795 | } else if key == "s" { | 3888 | } else if key == "s" { |
| 3796 | // The analyser off and on. Nothing is committed: it is | 3889 | // The analyser off and on. Nothing is committed: it is |
| 3797 | // what the card *shows*, so it survives no further than | 3890 | // what the card *shows*, so it survives no further than |
| 3798 | // this window. | 3891 | // this window. |
| 3799 | this.eq_spectrum = !this.eq_spectrum; | 3892 | this.eq_spectrum = !this.eq_spectrum; |
| 3800 | } else if let Ok(digit) = key.parse::<usize>() { | 3893 | } else if let Ok(digit) = key.parse::<usize>() { |
| 3801 | - // 1-based, as the rows are numbered on screen; a digit | 3894 | + // As the keys are laid out: 1-9 then 0 for the tenth, |
| 3802 | - // past the last band picks nothing rather than panics. | 3895 | + // which is the cap ([`EQ_BANDS_MAX`]). A digit past the |
| 3803 | - if let Some(band) = digit.checked_sub(1) | 3896 | + // last band picks nothing rather than panics. |
| 3804 | - && band < this.eq_params.bands.len() | 3897 | + let band = match digit { |
| 3805 | - { | 3898 | + 0 => EQ_BANDS_MAX - 1, |
| 3899 | + n => n - 1, | ||
| 3900 | + }; | ||
| 3901 | + if band < this.eq_params.bands.len() { | ||
| 3806 | this.eq_band = band; | 3902 | this.eq_band = band; |
| 3807 | } | 3903 | } |
| 3808 | } | 3904 | } |
| @@ -3964,7 +4060,7 @@ impl Render for Player { | |||
| 3964 | // the equalizer drag is tracked here for the ruler's reason. | 4060 | // the equalizer drag is tracked here for the ruler's reason. |
| 3965 | if this.eq_dragging { | 4061 | if this.eq_dragging { |
| 3966 | if event.pressed_button == Some(MouseButton::Left) { | 4062 | if event.pressed_button == Some(MouseButton::Left) { |
| 3967 | - this.drag_band(event.position.y, cx); | 4063 | + this.drag_band(event.position, cx); |
| 3968 | } else { | 4064 | } else { |
| 3969 | // Released outside the window: the up below never came, | 4065 | // Released outside the window: the up below never came, |
| 3970 | // so this is where the gesture ends -- and it still owes | 4066 | // so this is where the gesture ends -- and it still owes |
| @@ -4034,7 +4130,7 @@ impl Render for Player { | |||
| 4034 | if std::mem::take(&mut this.eq_dragging) { | 4130 | if std::mem::take(&mut this.eq_dragging) { |
| 4035 | // The release lands exactly, then the gesture is written | 4131 | // The release lands exactly, then the gesture is written |
| 4036 | // once -- the append-only table's whole reason. | 4132 | // once -- the append-only table's whole reason. |
| 4037 | - this.drag_band(event.position.y, cx); | 4133 | + this.drag_band(event.position, cx); |
| 4038 | this.commit_eq(cx); | 4134 | this.commit_eq(cx); |
| 4039 | return; | 4135 | return; |
| 4040 | } | 4136 | } |
| @@ -4136,7 +4232,7 @@ impl Render for Player { | |||
| 4136 | // column, and only one of the two is ever up. | 4232 | // column, and only one of the two is ever up. |
| 4137 | .children(self.keys_overlay(cx)) | 4233 | .children(self.keys_overlay(cx)) |
| 4138 | .children(self.export_card(window.viewport_size(), cx)) | 4234 | .children(self.export_card(window.viewport_size(), cx)) |
| 4139 | - .children(self.eq_card(cx)) | 4235 | + .children(self.eq_card(window.viewport_size(), cx)) |
| 4140 | .children(self.color_card(cx)) | 4236 | .children(self.color_card(cx)) |
| 4141 | .children(self.speed_card(cx)) | 4237 | .children(self.speed_card(cx)) |
| 4142 | .children(self.silence_card(cx)) | 4238 | .children(self.silence_card(cx)) |
| @@ -5595,20 +5691,28 @@ impl Player { | |||
| 5595 | } | 5691 | } |
| 5596 | 5692 | ||
| 5597 | /// The equalizer of one audio clip: its frequency response drawn as a | 5693 | /// The equalizer of one audio clip: its frequency response drawn as a |
| 5598 | - /// curve, a handle per band sitting on it, and a row that flattens them | 5694 | + /// curve, a handle per band sitting on it, each band's own bell under the |
| 5599 | - /// all. The curve is the clip's actual filter (`EqParams::response_db` | 5695 | + /// sum, and a row that reads and moves the picked band's three numbers. The |
| 5600 | - /// reads the coefficients the samples go through), and it is redrawn on | 5696 | + /// curve is the clip's actual filter (`EqParams::response_db` reads the |
| 5601 | - /// every pointer sample of a drag, so the shape bends under the hand. | 5697 | + /// coefficients the samples go through), and it is redrawn on every pointer |
| 5698 | + /// sample of a drag, so the shape bends under the hand. | ||
| 5602 | /// | 5699 | /// |
| 5603 | - /// The same scrim and width as the other two cards, and the same plain divs | 5700 | + /// Wider than the other cards and wider still on a bigger window |
| 5604 | - /// -- nothing here takes focus, so the root keeps the keyboard and the | 5701 | + /// ([`eq_card_w`]): every pixel across is frequency resolution, which none |
| 5605 | - /// card's own strokes (`1`–`5`, up, down, `r`) reach it. | 5702 | + /// of the row-shaped cards have any use for. The same scrim and the same |
| 5703 | + /// plain divs -- nothing here takes focus, so the root keeps the keyboard | ||
| 5704 | + /// and the card's own strokes (a digit, the arrows, `a`, `x`, `f`, `r`, | ||
| 5705 | + /// `s`) reach it. | ||
| 5606 | /// | 5706 | /// |
| 5607 | /// Every change is written at the clip as it is made | 5707 | /// Every change is written at the clip as it is made |
| 5608 | /// ([`Player::commit_eq`]), so what the card shows is always what is | 5708 | /// ([`Player::commit_eq`]), so what the card shows is always what is |
| 5609 | /// playing: there is no OK button to forget, and closing it changes | 5709 | /// playing: there is no OK button to forget, and closing it changes |
| 5610 | /// nothing. What takes a curve back off is undo, like every other edit. | 5710 | /// nothing. What takes a curve back off is undo, like every other edit. |
| 5611 | - fn eq_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 5711 | + fn eq_card( |
| 5712 | + &self, | ||
| 5713 | + viewport: Size<Pixels>, | ||
| 5714 | + cx: &mut Context<Self>, | ||
| 5715 | + ) -> Option<impl IntoElement> { | ||
| 5612 | let (lane, idx) = self.eq_open?; | 5716 | let (lane, idx) = self.eq_open?; |
| 5613 | // The rate the engine filters this timeline at, so the drawn curve is | 5717 | // The rate the engine filters this timeline at, so the drawn curve is |
| 5614 | // the one those coefficients make -- near the top of the axis a 44.1 kHz | 5718 | // the one those coefficients make -- near the top of the axis a 44.1 kHz |
| @@ -5662,13 +5766,20 @@ impl Player { | |||
| 5662 | .bg(rgb(HOVER_DIM)) | 5766 | .bg(rgb(HOVER_DIM)) |
| 5663 | .cursor_pointer() | 5767 | .cursor_pointer() |
| 5664 | // The press picks the band under it *and* is already the first | 5768 | // The press picks the band under it *and* is already the first |
| 5665 | - // sample of the drag, so a plain click sets a value. | 5769 | + // sample of the drag, so a plain click sets a value. A second click |
| 5770 | + // takes that band back to flat instead: the gesture that undoes one | ||
| 5771 | + // handle, with no modifier to remember. | ||
| 5666 | .on_mouse_down( | 5772 | .on_mouse_down( |
| 5667 | MouseButton::Left, | 5773 | MouseButton::Left, |
| 5668 | cx.listener(|this, event: &MouseDownEvent, _, cx| { | 5774 | cx.listener(|this, event: &MouseDownEvent, _, cx| { |
| 5669 | this.eq_band = this.nearest_band(event.position.x); | 5775 | this.eq_band = this.nearest_band(event.position.x); |
| 5776 | + if event.click_count >= 2 { | ||
| 5777 | + this.eq_dragging = false; | ||
| 5778 | + this.nudge_band(|b| b.gain_db = 0., cx); | ||
| 5779 | + return; | ||
| 5780 | + } | ||
| 5670 | this.eq_dragging = true; | 5781 | this.eq_dragging = true; |
| 5671 | - this.drag_band(event.position.y, cx); | 5782 | + this.drag_band(event.position, cx); |
| 5672 | }), | 5783 | }), |
| 5673 | ) | 5784 | ) |
| 5674 | .child(bounds_probe(self.eq_graph.clone())) | 5785 | .child(bounds_probe(self.eq_graph.clone())) |
| @@ -5760,7 +5871,7 @@ impl Player { | |||
| 5760 | }) | 5871 | }) |
| 5761 | .child( | 5872 | .child( |
| 5762 | div() | 5873 | div() |
| 5763 | - .w(px(KEYS_W)) | 5874 | + .w(px(eq_card_w(f32::from(viewport.width)))) |
| 5764 | .flex() | 5875 | .flex() |
| 5765 | .flex_col() | 5876 | .flex_col() |
| 5766 | .gap(px(2.)) | 5877 | .gap(px(2.)) |
| @@ -5781,28 +5892,15 @@ impl Player { | |||
| 5781 | .text_size(px(11.)) | 5892 | .text_size(px(11.)) |
| 5782 | .text_color(rgb(INK_DIM)) | 5893 | .text_color(rgb(INK_DIM)) |
| 5783 | .child(self.notice.clone().unwrap_or_else(|| { | 5894 | .child(self.notice.clone().unwrap_or_else(|| { |
| 5784 | - "drag the curve, or 1–5 then up/down — s hides the spectrum, esc closes".into() | 5895 | + "drag a handle, or a digit picks a band — ←→ moves it, ↑↓ its gain, shift+←→ its width; a adds, x removes, f flattens it, r all, s spectrum, esc closes".into() |
| 5785 | })), | 5896 | })), |
| 5786 | ) | 5897 | ) |
| 5787 | .child(graph) | 5898 | .child(graph) |
| 5788 | - // Which band the keyboard is holding and what it is set | 5899 | + // Which band the keyboard is holding and every number it |
| 5789 | - // to: the curve shows the sum, and a band pushed against | 5900 | + // is set to, each with the pair of buttons that moves it: |
| 5790 | - // one pulling the other way is not readable off it. | 5901 | + // the curve shows the sum, and a band pushed against one |
| 5791 | - .child(div().flex_none().px(px(6.)).text_size(px(11.)).child( | 5902 | + // pulling the other way is not readable off it. |
| 5792 | - match picked { | 5903 | + .child(self.eq_numbers(picked, cx)) |
| 5793 | - // Q as well as the two the curve shows: it is | ||
| 5794 | - // how wide the hump under the handle is, and | ||
| 5795 | - // nothing else on the card says so. | ||
| 5796 | - Some(band) => format!( | ||
| 5797 | - "{} {} {:+.1} dB — Q {:.2}", | ||
| 5798 | - self.eq_band + 1, | ||
| 5799 | - band_label(band), | ||
| 5800 | - band.gain_db, | ||
| 5801 | - band.q | ||
| 5802 | - ), | ||
| 5803 | - None => "no bands".into(), | ||
| 5804 | - }, | ||
| 5805 | - )) | ||
| 5806 | .child( | 5904 | .child( |
| 5807 | div() | 5905 | div() |
| 5808 | .mt(px(4.)) | 5906 | .mt(px(4.)) |
| @@ -5826,7 +5924,45 @@ impl Player { | |||
| 5826 | } | 5924 | } |
| 5827 | this.commit_eq(cx); | 5925 | this.commit_eq(cx); |
| 5828 | })) | 5926 | })) |
| 5829 | - .child("Flatten"), | 5927 | + .child("Flatten all"), |
| 5928 | + ) | ||
| 5929 | + // The two that change how many bands there are. | ||
| 5930 | + // The engine takes any cascade -- the count was | ||
| 5931 | + // only ever fixed because this card had no way | ||
| 5932 | + // to say otherwise. | ||
| 5933 | + .child( | ||
| 5934 | + div() | ||
| 5935 | + .id("eq-add") | ||
| 5936 | + .flex() | ||
| 5937 | + .flex_1() | ||
| 5938 | + .h(px(CONTROL_H)) | ||
| 5939 | + .items_center() | ||
| 5940 | + .justify_center() | ||
| 5941 | + .rounded(px(3.)) | ||
| 5942 | + .bg(rgb(CHROME)) | ||
| 5943 | + .cursor_pointer() | ||
| 5944 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5945 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 5946 | + this.add_band(cx) | ||
| 5947 | + })) | ||
| 5948 | + .child("Add band"), | ||
| 5949 | + ) | ||
| 5950 | + .child( | ||
| 5951 | + div() | ||
| 5952 | + .id("eq-remove") | ||
| 5953 | + .flex() | ||
| 5954 | + .flex_1() | ||
| 5955 | + .h(px(CONTROL_H)) | ||
| 5956 | + .items_center() | ||
| 5957 | + .justify_center() | ||
| 5958 | + .rounded(px(3.)) | ||
| 5959 | + .bg(rgb(CHROME)) | ||
| 5960 | + .cursor_pointer() | ||
| 5961 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5962 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 5963 | + this.remove_band(cx) | ||
| 5964 | + })) | ||
| 5965 | + .child("Remove band"), | ||
| 5830 | ) | 5966 | ) |
| 5831 | // The analyser's switch, next to the one other | 5967 | // The analyser's switch, next to the one other |
| 5832 | // button the card has: `s` does the same, and a | 5968 | // button the card has: `s` does the same, and a |
| @@ -5861,6 +5997,103 @@ impl Player { | |||
| 5861 | ) | 5997 | ) |
| 5862 | } | 5998 | } |
| 5863 | 5999 | ||
| 6000 | + /// The picked band's three numbers -- where it sits, how far it pushes and | ||
| 6001 | + /// how wide it is -- each beside the pair of buttons that moves it. The | ||
| 6002 | + /// arrows do the same three things, but a value only a key can change is a | ||
| 6003 | + /// value a hand on the pointer cannot reach at all, which is the same reason | ||
| 6004 | + /// [`Player::mbps_steppers`] exists. | ||
| 6005 | + fn eq_numbers(&self, picked: Option<&Band>, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 6006 | + let row = div() | ||
| 6007 | + .flex_none() | ||
| 6008 | + .flex() | ||
| 6009 | + .items_center() | ||
| 6010 | + .gap(px(10.)) | ||
| 6011 | + .px(px(6.)) | ||
| 6012 | + .text_size(px(11.)); | ||
| 6013 | + let Some(band) = picked.copied() else { | ||
| 6014 | + return row.child("no bands — a adds one"); | ||
| 6015 | + }; | ||
| 6016 | + let step = |id: &'static str, | ||
| 6017 | + label: &'static str, | ||
| 6018 | + change: fn(&mut Band), | ||
| 6019 | + cx: &mut Context<Self>| { | ||
| 6020 | + div() | ||
| 6021 | + .id(id) | ||
| 6022 | + .flex() | ||
| 6023 | + .w(px(HIT_MIN)) | ||
| 6024 | + .h(px(HIT_MIN)) | ||
| 6025 | + .items_center() | ||
| 6026 | + .justify_center() | ||
| 6027 | + .rounded(px(3.)) | ||
| 6028 | + .bg(rgb(CHROME)) | ||
| 6029 | + .cursor_pointer() | ||
| 6030 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 6031 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 6032 | + this.nudge_band(change, cx) | ||
| 6033 | + })) | ||
| 6034 | + .child(label) | ||
| 6035 | + }; | ||
| 6036 | + let number = |value: String, | ||
| 6037 | + ids: (&'static str, &'static str), | ||
| 6038 | + by: (fn(&mut Band), fn(&mut Band)), | ||
| 6039 | + cx: &mut Context<Self>| { | ||
| 6040 | + div() | ||
| 6041 | + .flex() | ||
| 6042 | + .items_center() | ||
| 6043 | + .gap(px(4.)) | ||
| 6044 | + .child(div().child(value)) | ||
| 6045 | + .child(step(ids.0, "−", by.0, cx)) | ||
| 6046 | + .child(step(ids.1, "+", by.1, cx)) | ||
| 6047 | + }; | ||
| 6048 | + row.child(format!( | ||
| 6049 | + "Band {} of {}", | ||
| 6050 | + self.eq_band + 1, | ||
| 6051 | + self.eq_params.bands.len() | ||
| 6052 | + )) | ||
| 6053 | + .child(number( | ||
| 6054 | + band_label(&band), | ||
| 6055 | + ("eq-freq-down", "eq-freq-up"), | ||
| 6056 | + ( | ||
| 6057 | + |b| b.freq_hz /= EQ_FREQ_STEP, | ||
| 6058 | + |b| b.freq_hz *= EQ_FREQ_STEP, | ||
| 6059 | + ), | ||
| 6060 | + cx, | ||
| 6061 | + )) | ||
| 6062 | + .child(number( | ||
| 6063 | + format!("{:+.1} dB", band.gain_db), | ||
| 6064 | + ("eq-gain-down", "eq-gain-up"), | ||
| 6065 | + (|b| b.gain_db -= EQ_STEP, |b| b.gain_db += EQ_STEP), | ||
| 6066 | + cx, | ||
| 6067 | + )) | ||
| 6068 | + // Q is width, so its buttons are labelled by what they *do* to the | ||
| 6069 | + // hump rather than by which way the number goes: a wider band is a | ||
| 6070 | + // smaller Q, and nobody should have to know that to use the card. | ||
| 6071 | + .child(number( | ||
| 6072 | + format!("Q {:.2}", band.q), | ||
| 6073 | + ("eq-q-wider", "eq-q-narrower"), | ||
| 6074 | + (|b| b.q /= EQ_Q_STEP, |b| b.q *= EQ_Q_STEP), | ||
| 6075 | + cx, | ||
| 6076 | + )) | ||
| 6077 | + .child( | ||
| 6078 | + div() | ||
| 6079 | + .id("eq-flat-band") | ||
| 6080 | + .flex() | ||
| 6081 | + .h(px(HIT_MIN)) | ||
| 6082 | + .px(px(8.)) | ||
| 6083 | + .items_center() | ||
| 6084 | + .rounded(px(3.)) | ||
| 6085 | + .bg(rgb(CHROME)) | ||
| 6086 | + .cursor_pointer() | ||
| 6087 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 6088 | + .on_click( | ||
| 6089 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 6090 | + this.nudge_band(|b| b.gain_db = 0., cx) | ||
| 6091 | + }), | ||
| 6092 | + ) | ||
| 6093 | + .child("Flatten this"), | ||
| 6094 | + ) | ||
| 6095 | + } | ||
| 6096 | + | ||
| 5864 | /// The colour card: the graded frame's histogram over a row per control, | 6097 | /// The colour card: the graded frame's histogram over a row per control, |
| 5865 | /// each row a bar the pointer drags straight to a value -- no stepper | 6098 | /// each row a bar the pointer drags straight to a value -- no stepper |
| 5866 | /// buttons, because a slider is a thing to pull, and the arrow keys still | 6099 | /// buttons, because a slider is a thing to pull, and the arrow keys still |
| @@ -7552,6 +7785,36 @@ fn eq_x(freq_hz: f32) -> f32 { | |||
| 7552 | ((freq_hz.max(1.) / EQ_FREQ_LOW).log10() / span).clamp(0., 1.) | 7785 | ((freq_hz.max(1.) / EQ_FREQ_LOW).log10() / span).clamp(0., 1.) |
| 7553 | } | 7786 | } |
| 7554 | 7787 | ||
| 7788 | +/// The frequency at a fraction across the graph -- [`eq_x`] backwards, which is | ||
| 7789 | +/// how a drag and the curve's own sample points read one. Clamped to the axis | ||
| 7790 | +/// either way, so a pointer that leaves the box stops at 20 Hz or 20 kHz. | ||
| 7791 | +fn eq_freq(along: f32) -> f32 { | ||
| 7792 | + EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along.clamp(0., 1.)) | ||
| 7793 | +} | ||
| 7794 | + | ||
| 7795 | +/// The band an "add" makes: a flat peak half way -- in octaves, which is what | ||
| 7796 | +/// the log axis draws -- between the picked band and whatever sits above it, so | ||
| 7797 | +/// a new band lands in the gap on screen rather than on top of its neighbour. | ||
| 7798 | +/// Above the topmost band the gap is the rest of the axis. | ||
| 7799 | +fn inserted_band(bands: &[Band], after: usize) -> Band { | ||
| 7800 | + let below = bands.get(after).map_or(1000., |b| b.freq_hz); | ||
| 7801 | + let above = bands | ||
| 7802 | + .iter() | ||
| 7803 | + .map(|b| b.freq_hz) | ||
| 7804 | + .filter(|f| *f > below) | ||
| 7805 | + .min_by(f32::total_cmp) | ||
| 7806 | + .unwrap_or(EQ_FREQ_HIGH); | ||
| 7807 | + Band { | ||
| 7808 | + freq_hz: (below * above).sqrt().clamp(EQ_FREQ_LOW, EQ_FREQ_HIGH), | ||
| 7809 | + gain_db: 0., | ||
| 7810 | + // A shade narrower than the flat-shelf 0.707 the defaults use: a band | ||
| 7811 | + // someone asked for is a band they mean to aim, and a wide one aimed at | ||
| 7812 | + // 300 Hz is really a band at everything. | ||
| 7813 | + q: 1., | ||
| 7814 | + kind: BandKind::Peak, | ||
| 7815 | + } | ||
| 7816 | +} | ||
| 7817 | + | ||
| 7555 | /// Where a gain sits *down* the graph, 0..1 from the top: flat is the middle, | 7818 | /// Where a gain sits *down* the graph, 0..1 from the top: flat is the middle, |
| 7556 | /// so a cut reads as a dip below the line it is a cut from. The inverse of | 7819 | /// so a cut reads as a dip below the line it is a cut from. The inverse of |
| 7557 | /// [`Player::drag_band`]'s reading of the pointer, and clamped like it, so a | 7820 | /// [`Player::drag_band`]'s reading of the pointer, and clamped like it, so a |
| @@ -7561,14 +7824,24 @@ fn eq_y(gain_db: f32) -> f32 { | |||
| 7561 | 0.5 - (gain_db / EQ_GAIN_LIMIT).clamp(-1., 1.) / 2. | 7824 | 0.5 - (gain_db / EQ_GAIN_LIMIT).clamp(-1., 1.) / 2. |
| 7562 | } | 7825 | } |
| 7563 | 7826 | ||
| 7827 | +/// A frequency as the card writes it. Two decimals of a kHz at most, with the | ||
| 7828 | +/// zeroes trimmed, so "1 kHz" stays "1 kHz" and a band nudged off it reads as | ||
| 7829 | +/// 1.12 kHz rather than as the same "1 kHz" it was before the keystroke -- a | ||
| 7830 | +/// number that does not move under an edit is worse than no number. | ||
| 7831 | +fn eq_freq_label(freq_hz: f32) -> String { | ||
| 7832 | + if freq_hz < 1000. { | ||
| 7833 | + return format!("{freq_hz:.0} Hz"); | ||
| 7834 | + } | ||
| 7835 | + let khz = format!("{:.2}", freq_hz / 1000.); | ||
| 7836 | + let khz = khz.trim_end_matches('0').trim_end_matches('.'); | ||
| 7837 | + format!("{khz} kHz") | ||
| 7838 | +} | ||
| 7839 | + | ||
| 7564 | /// What a band row calls itself: the corner or centre frequency, and for a | 7840 | /// What a band row calls itself: the corner or centre frequency, and for a |
| 7565 | /// shelf the fact that it tilts everything past it -- which is the difference | 7841 | /// shelf the fact that it tilts everything past it -- which is the difference |
| 7566 | /// between "12 kHz" moving the last octave and moving one band inside it. | 7842 | /// between "12 kHz" moving the last octave and moving one band inside it. |
| 7567 | fn band_label(band: &Band) -> String { | 7843 | fn band_label(band: &Band) -> String { |
| 7568 | - let freq = match band.freq_hz >= 1000. { | 7844 | + let freq = eq_freq_label(band.freq_hz); |
| 7569 | - true => format!("{:.0} kHz", band.freq_hz / 1000.), | ||
| 7570 | - false => format!("{:.0} Hz", band.freq_hz), | ||
| 7571 | - }; | ||
| 7572 | match band.kind { | 7845 | match band.kind { |
| 7573 | BandKind::LowShelf => format!("{freq} low shelf"), | 7846 | BandKind::LowShelf => format!("{freq} low shelf"), |
| 7574 | BandKind::HighShelf => format!("{freq} high shelf"), | 7847 | BandKind::HighShelf => format!("{freq} high shelf"), |
| @@ -7923,6 +8196,15 @@ fn unusable(info: &StreamInfo, timeline_audio: Option<(u32, u16)>) -> Option<Str | |||
| 7923 | }) | 8196 | }) |
| 7924 | } | 8197 | } |
| 7925 | 8198 | ||
| 8199 | +/// How wide the equalizer card is drawn in a window this wide: all of it bar a | ||
| 8200 | +/// margin, up to [`EQ_W_MAX`]. The card is a graph, and a graph of twenty | ||
| 8201 | +/// thousand hertz on 320 px spends four pixels on the octave below middle C -- | ||
| 8202 | +/// so it takes the room a big window has and stays inside a small one. Floored | ||
| 8203 | +/// at the other cards' width, which is the last size the rows still read at. | ||
| 8204 | +fn eq_card_w(window_w: f32) -> f32 { | ||
| 8205 | + (window_w - EQ_W_MARGIN).clamp(KEYS_W, EQ_W_MAX) | ||
| 8206 | +} | ||
| 8207 | + | ||
| 7926 | /// What the media list is given of the window. A share of it, so a narrow | 8208 | /// What the media list is given of the window. A share of it, so a narrow |
| 7927 | /// window gives the panel less rather than giving the picture nothing, floored | 8209 | /// window gives the panel less rather than giving the picture nothing, floored |
| 7928 | /// where a name stops being readable and capped at a third of the window -- | 8210 | /// where a name stops being readable and capped at a third of the window -- |
| @@ -9320,11 +9602,15 @@ fn eq_spectrum_curve(levels: Vec<f32>) -> impl IntoElement { | |||
| 9320 | .size_full() | 9602 | .size_full() |
| 9321 | } | 9603 | } |
| 9322 | 9604 | ||
| 9323 | -/// The cascade's frequency response, drawn as one line across the graph. | 9605 | +/// The cascade's frequency response, drawn as one line across the graph, with |
| 9606 | +/// each band's own response threaded dimly under it. | ||
| 9324 | /// | 9607 | /// |
| 9325 | /// Every point comes from `EqParams::response_db`, which reads the very | 9608 | /// Every point comes from `EqParams::response_db`, which reads the very |
| 9326 | /// coefficients the samples are filtered through: the curve cannot drift from | 9609 | /// coefficients the samples are filtered through: the curve cannot drift from |
| 9327 | -/// what is heard, because there is no second copy of the maths. | 9610 | +/// what is heard, because there is no second copy of the maths. A single band's |
| 9611 | +/// thread is that same call on a cascade of one, so the two cannot disagree | ||
| 9612 | +/// either -- and it is what makes a boost sitting inside a cut visible at all, | ||
| 9613 | +/// where the sum alone would draw a flat line and say nothing. | ||
| 9328 | /// | 9614 | /// |
| 9329 | /// ponytail: bands that overlap can sum past the ±`EQ_GAIN_LIMIT` axis and the | 9615 | /// ponytail: bands that overlap can sum past the ±`EQ_GAIN_LIMIT` axis and the |
| 9330 | /// curve then rides the edge of the box; upgrade = a wider dB axis with the | 9616 | /// curve then rides the edge of the box; upgrade = a wider dB axis with the |
| @@ -9334,16 +9620,37 @@ fn eq_curve(params: EqParams, sample_rate: u32) -> impl IntoElement { | |||
| 9334 | |_, _, _| (), | 9620 | |_, _, _| (), |
| 9335 | move |bounds, _, window, _| { | 9621 | move |bounds, _, window, _| { |
| 9336 | let (o, s) = (bounds.origin, bounds.size); | 9622 | let (o, s) = (bounds.origin, bounds.size); |
| 9337 | - let points: Vec<_> = (0..=EQ_CURVE_STEPS) | 9623 | + let line = |of: &EqParams| -> Vec<_> { |
| 9338 | - .map(|step| { | 9624 | + (0..=EQ_CURVE_STEPS) |
| 9339 | - let along = step as f32 / EQ_CURVE_STEPS as f32; | 9625 | + .map(|step| { |
| 9340 | - let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | 9626 | + let along = step as f32 / EQ_CURVE_STEPS as f32; |
| 9341 | - point( | 9627 | + point( |
| 9342 | - o.x + s.width * along, | 9628 | + o.x + s.width * along, |
| 9343 | - o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | 9629 | + o.y + s.height |
| 9344 | - ) | 9630 | + * eq_y(of.response_db(eq_freq(along), sample_rate)), |
| 9631 | + ) | ||
| 9632 | + }) | ||
| 9633 | + .collect() | ||
| 9634 | + }; | ||
| 9635 | + // One thread per band, first, so the sum is drawn over them. | ||
| 9636 | + for band in ¶ms.bands { | ||
| 9637 | + let mut bell = PathBuilder::stroke(px(1.)); | ||
| 9638 | + for (step, at) in line(&EqParams { | ||
| 9639 | + bands: vec![*band], | ||
| 9345 | }) | 9640 | }) |
| 9346 | - .collect(); | 9641 | + .into_iter() |
| 9642 | + .enumerate() | ||
| 9643 | + { | ||
| 9644 | + match step { | ||
| 9645 | + 0 => bell.move_to(at), | ||
| 9646 | + _ => bell.line_to(at), | ||
| 9647 | + } | ||
| 9648 | + } | ||
| 9649 | + if let Ok(bell) = bell.build() { | ||
| 9650 | + window.paint_path(bell, rgba(EQ_BELL_INK)); | ||
| 9651 | + } | ||
| 9652 | + } | ||
| 9653 | + let points = line(¶ms); | ||
| 9347 | // The area between the curve and 0 dB, closed along that line: a | 9654 | // The area between the curve and 0 dB, closed along that line: a |
| 9348 | // boost and a cut wind opposite ways around it, which is exactly | 9655 | // boost and a cut wind opposite ways around it, which is exactly |
| 9349 | // what makes both of them fill and the flat parts stay empty. | 9656 | // what makes both of them fill and the flat parts stay empty. |
| @@ -9445,9 +9752,10 @@ fn timecode(t: f64, fps: f64) -> String { | |||
| 9445 | #[cfg(test)] | 9752 | #[cfg(test)] |
| 9446 | mod tests { | 9753 | mod tests { |
| 9447 | use super::{ | 9754 | use super::{ |
| 9448 | - ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, | 9755 | + ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, EQ_BANDS_MAX, |
| 9449 | - EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, | 9756 | + EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, |
| 9450 | - EQ_SPECTRUM_DB, EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, FORMATS, | 9757 | + EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, |
| 9758 | + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, FORMATS, | ||
| 9451 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, | 9759 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, |
| 9452 | INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, | 9760 | INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, |
| 9453 | LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, | 9761 | LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, |
| @@ -9455,9 +9763,11 @@ mod tests { | |||
| 9455 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, | 9763 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, |
| 9456 | Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, band_label, bitrate_refusal, | 9764 | Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, band_label, bitrate_refusal, |
| 9457 | can_add, cancels_export, clipboard_after_remove, color_snap, containers, enable, envelope, | 9765 | can_add, cancels_export, clipboard_after_remove, color_snap, containers, enable, envelope, |
| 9458 | - eq_spectrum, eq_x, eq_y, estimated_mb, export_path, export_settings, format_key, | 9766 | + eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, estimated_mb, export_path, |
| 9767 | + export_settings, format_key, | ||
| 9459 | format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, | 9768 | format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, |
| 9460 | - is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, next_container, | 9769 | + inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, |
| 9770 | + next_container, | ||
| 9461 | normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, | 9771 | normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, |
| 9462 | show_label, silence_rate, snap_cue, snap_marks, snapped, source_tint, span_partner, | 9772 | show_label, silence_rate, snap_cue, snap_marks, snapped, source_tint, span_partner, |
| 9463 | speed_at, summary_head, summary_tail, timecode, transport, unseen_paths, unseen_sources, | 9773 | speed_at, summary_head, summary_tail, timecode, transport, unseen_paths, unseen_sources, |
| @@ -11286,6 +11596,9 @@ mod tests { | |||
| 11286 | "12 kHz high shelf" | 11596 | "12 kHz high shelf" |
| 11287 | ] | 11597 | ] |
| 11288 | ); | 11598 | ); |
| 11599 | + // A band moved off a round number reads as where it *is*: a keystroke | ||
| 11600 | + // that changes the filter and not the number on the card is a keystroke | ||
| 11601 | + // nobody can aim. | ||
| 11289 | assert_eq!( | 11602 | assert_eq!( |
| 11290 | band_label(&Band { | 11603 | band_label(&Band { |
| 11291 | freq_hz: 2600., | 11604 | freq_hz: 2600., |
| @@ -11293,23 +11606,38 @@ mod tests { | |||
| 11293 | q: 1., | 11606 | q: 1., |
| 11294 | kind: BandKind::Peak | 11607 | kind: BandKind::Peak |
| 11295 | }), | 11608 | }), |
| 11296 | - "3 kHz", | 11609 | + "2.6 kHz" |
| 11297 | - "rounded, because a band label is not a measurement" | 11610 | + ); |
| 11611 | + assert_eq!(eq_freq_label(1122.), "1.12 kHz"); | ||
| 11612 | + assert_eq!(eq_freq_label(12000.), "12 kHz", "no zeroes to read past"); | ||
| 11613 | + assert_eq!(eq_freq_label(80.), "80 Hz"); | ||
| 11614 | + | ||
| 11615 | + // The card fits the smallest window and takes the room a bigger one has | ||
| 11616 | + // -- it is a graph, and the width *is* the frequency resolution. | ||
| 11617 | + assert!(eq_card_w(640.) <= 640. - 24., "card too wide for 640"); | ||
| 11618 | + assert!(eq_card_w(1280.) > eq_card_w(640.), "card ignores the window"); | ||
| 11619 | + assert_eq!(eq_card_w(1920.), EQ_W_MAX, "card grows without end"); | ||
| 11620 | + assert!(eq_card_w(320.) >= KEYS_W, "card narrower than a row of text"); | ||
| 11621 | + // At the smallest window the graph is still a graph: three across for | ||
| 11622 | + // one down, so an octave is wide enough to put a handle in. | ||
| 11623 | + assert!( | ||
| 11624 | + eq_card_w(640.) - 24. >= 3. * EQ_GRAPH_H, | ||
| 11625 | + "graph too square to aim at" | ||
| 11298 | ); | 11626 | ); |
| 11299 | 11627 | ||
| 11300 | // The same shape as the other two cards, so it fits where they do: the | 11628 | // The same shape as the other two cards, so it fits where they do: the |
| 11301 | // graph stands where the export card's rows do, and is shorter than | 11629 | // graph stands where the export card's rows do, and is shorter than |
| 11302 | - // they are. | 11630 | + // they are. The numbers row is a row of buttons now, so it is one of |
| 11303 | - let (title, status, readout, gaps, padding) = (17., 28., 17., 4. * 2., 24.); | 11631 | + // those tall rather than one line of text. |
| 11632 | + let (title, status, gaps, padding) = (17., 28., 4. * 2., 24.); | ||
| 11304 | assert!( | 11633 | assert!( |
| 11305 | - title + status + EQ_GRAPH_H + readout + gaps + padding + CONTROL_H <= 360., | 11634 | + title + status + EQ_GRAPH_H + HIT_MIN + gaps + padding + CONTROL_H <= 360., |
| 11306 | "card too tall" | 11635 | "card too tall" |
| 11307 | ); | 11636 | ); |
| 11308 | assert!( | 11637 | assert!( |
| 11309 | EQ_GRAPH_H <= EXPORT_ROWS_H, | 11638 | EQ_GRAPH_H <= EXPORT_ROWS_H, |
| 11310 | "graph taller than a card of rows" | 11639 | "graph taller than a card of rows" |
| 11311 | ); | 11640 | ); |
| 11312 | - assert!(KEYS_W <= 640., "card too wide"); | ||
| 11313 | // What is dragged is the whole graph -- the handle is a 10 px dot, but | 11641 | // What is dragged is the whole graph -- the handle is a 10 px dot, but |
| 11314 | // a press anywhere in the box takes the band nearest it -- so WCAG | 11642 | // a press anywhere in the box takes the band nearest it -- so WCAG |
| 11315 | // 2.5.8 is satisfied by the box, which is far past the minimum. | 11643 | // 2.5.8 is satisfied by the box, which is far past the minimum. |
| @@ -11321,6 +11649,83 @@ mod tests { | |||
| 11321 | assert!(KEYS_ROW_H >= HIT_MIN); | 11649 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 11322 | } | 11650 | } |
| 11323 | 11651 | ||
| 11652 | + /// Editing a band, which is what the card is *for*: the pointer reads a | ||
| 11653 | + /// frequency off the axis the same way the axis draws one, a new band lands | ||
| 11654 | + /// in the gap beside the picked one rather than on top of it, and every band | ||
| 11655 | + /// the card will hold has a digit that picks it. | ||
| 11656 | + #[test] | ||
| 11657 | + fn a_band_can_be_moved_added_and_reached() { | ||
| 11658 | + use engine::eq::{Band, BandKind, EqParams}; | ||
| 11659 | + // Across the graph and back: a drag sets the frequency the handle is | ||
| 11660 | + // then drawn at, so the two mappings have to be one another's inverse or | ||
| 11661 | + // the handle walks away from the pointer. | ||
| 11662 | + for freq in [20., 80., 250., 1000., 4000., 12000., 20000.] { | ||
| 11663 | + let read = eq_freq(eq_x(freq)); | ||
| 11664 | + assert!( | ||
| 11665 | + (read / freq - 1.).abs() < 1e-3, | ||
| 11666 | + "{freq} Hz read back as {read}" | ||
| 11667 | + ); | ||
| 11668 | + } | ||
| 11669 | + // Off the box either end stops at the axis, never past it. | ||
| 11670 | + assert_eq!(eq_freq(-1.), EQ_FREQ_LOW); | ||
| 11671 | + assert_eq!(eq_freq(2.), EQ_FREQ_HIGH); | ||
| 11672 | + | ||
| 11673 | + // A step of the frequency keys is a real move on screen -- a keystroke | ||
| 11674 | + // that changes nothing visible is a keystroke that reads as broken -- | ||
| 11675 | + // and small enough to aim with. | ||
| 11676 | + let step = eq_x(1000. * EQ_FREQ_STEP) - eq_x(1000.); | ||
| 11677 | + assert!(step > 0.01 && step < 0.06, "frequency key steps {step}"); | ||
| 11678 | + | ||
| 11679 | + // A new band lands between the picked one and the next one up, in | ||
| 11680 | + // octaves: 250 Hz and 1 kHz put it at 500, which is a gap on screen. | ||
| 11681 | + let bands = EqParams::default_layout().bands; | ||
| 11682 | + let added = inserted_band(&bands, 1); | ||
| 11683 | + assert!((added.freq_hz - 500.).abs() < 1., "landed at {added:?}"); | ||
| 11684 | + assert_eq!(added.gain_db, 0., "a new band changes nothing until moved"); | ||
| 11685 | + assert_eq!(added.kind, BandKind::Peak, "a new band is not a shelf"); | ||
| 11686 | + assert!(eq_x(added.freq_hz) - eq_x(bands[1].freq_hz) > 0.1); | ||
| 11687 | + // Above the topmost band the gap is the rest of the axis, and the band | ||
| 11688 | + // still lands on it rather than off the end. | ||
| 11689 | + let top = inserted_band(&bands, bands.len() - 1); | ||
| 11690 | + assert!( | ||
| 11691 | + top.freq_hz > bands[4].freq_hz && top.freq_hz <= EQ_FREQ_HIGH, | ||
| 11692 | + "landed at {top:?}" | ||
| 11693 | + ); | ||
| 11694 | + // Bands out of frequency order (a drag may cross two over) still get a | ||
| 11695 | + // sane neighbour: the next one *up*, not the next one along the list. | ||
| 11696 | + let crossed = vec![ | ||
| 11697 | + Band { | ||
| 11698 | + freq_hz: 4000., | ||
| 11699 | + gain_db: 0., | ||
| 11700 | + q: 1., | ||
| 11701 | + kind: BandKind::Peak, | ||
| 11702 | + }, | ||
| 11703 | + Band { | ||
| 11704 | + freq_hz: 100., | ||
| 11705 | + gain_db: 0., | ||
| 11706 | + q: 1., | ||
| 11707 | + kind: BandKind::Peak, | ||
| 11708 | + }, | ||
| 11709 | + ]; | ||
| 11710 | + let between = inserted_band(&crossed, 1); | ||
| 11711 | + assert!( | ||
| 11712 | + (between.freq_hz - 632.).abs() < 2., | ||
| 11713 | + "landed at {between:?}, not between 100 and 4000" | ||
| 11714 | + ); | ||
| 11715 | + | ||
| 11716 | + // Every band the card will hold is one digit away: the keyboard has ten | ||
| 11717 | + // digits, which is exactly why the cap is what it is. | ||
| 11718 | + assert!( | ||
| 11719 | + EQ_BANDS_MAX <= 10, | ||
| 11720 | + "a band past the tenth has no key that picks it" | ||
| 11721 | + ); | ||
| 11722 | + assert!(EQ_BANDS_MAX > EqParams::default_layout().bands.len()); | ||
| 11723 | + // The Q range holds the default, so a file's band never opens out of | ||
| 11724 | + // range and needs dragging back in before it can be edited. | ||
| 11725 | + assert!((EQ_Q_LOW..=EQ_Q_HIGH).contains(&0.707)); | ||
| 11726 | + assert!(EQ_Q_STEP > 1.); | ||
| 11727 | + } | ||
| 11728 | + | ||
| 11324 | /// The analyser drawn behind the curve: a tone has to land on its own | 11729 | /// The analyser drawn behind the curve: a tone has to land on its own |
| 11325 | /// frequency, or the backdrop is a decoration rather than a reading of what | 11730 | /// frequency, or the backdrop is a decoration rather than a reading of what |
| 11326 | /// is playing -- and someone shaping a band against it would be aiming at | 11731 | /// is playing -- and someone shaping a band against it would be aiming at |