The equalizer takes the room it needs, and every band is editable
Browse files at this commit462692e53b921631eda7d40de9db7a0b21ece3a1Parent: 4bf4e78- feat
- the equalizer takes the room it needs, and every band is editable
2 changed files +524 -94
- crates/app/src/keymap.rs +27 -2
- crates/app/src/main.rs +497 -92
crates/app/src/keymap.rsmodified+27 -2
| @@ -326,7 +326,7 @@ pub struct Fixed { | |||
| 326 | pub category: Category, | 326 | pub category: Category, |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | -pub const FIXED: [Fixed; 21] = [ | 329 | +pub const FIXED: [Fixed; 26] = [ |
| 330 | // Not a chord at all but a way of pressing one, and the only place the | 330 | // Not a chord at all but a way of pressing one, and the only place the |
| 331 | // editor can say so: holding a key that moves a *value* runs it, and | 331 | // editor can say so: holding a key that moves a *value* runs it, and |
| 332 | // holding anything else still does what one press did. | 332 | // holding anything else still does what one press did. |
| @@ -394,7 +394,7 @@ pub const FIXED: [Fixed; 21] = [ | |||
| 394 | // its own: a band nothing but a drag can reach is a band half the users of | 394 | // its own: a band nothing but a drag can reach is a band half the users of |
| 395 | // this editor cannot move at all. Card-local, so none of them is bindable. | 395 | // this editor cannot move at all. Card-local, so none of them is bindable. |
| 396 | Fixed { | 396 | Fixed { |
| 397 | - chord: "1–5", | 397 | + chord: "1–9, 0", |
| 398 | label: "Pick an equalizer band", | 398 | label: "Pick an equalizer band", |
| 399 | category: Category::Audio, | 399 | category: Category::Audio, |
| 400 | }, | 400 | }, |
| @@ -408,6 +408,31 @@ pub const FIXED: [Fixed; 21] = [ | |||
| 408 | label: "Lower the picked band 1 dB", | 408 | label: "Lower the picked band 1 dB", |
| 409 | category: Category::Audio, | 409 | category: Category::Audio, |
| 410 | }, | 410 | }, |
| 411 | + Fixed { | ||
| 412 | + chord: "← / →", | ||
| 413 | + label: "Move the picked band down or up in frequency", | ||
| 414 | + category: Category::Audio, | ||
| 415 | + }, | ||
| 416 | + Fixed { | ||
| 417 | + chord: "shift ← / →", | ||
| 418 | + label: "Widen or narrow the picked band (its Q)", | ||
| 419 | + category: Category::Audio, | ||
| 420 | + }, | ||
| 421 | + Fixed { | ||
| 422 | + chord: "a", | ||
| 423 | + label: "Add an equalizer band beside the picked one", | ||
| 424 | + category: Category::Audio, | ||
| 425 | + }, | ||
| 426 | + Fixed { | ||
| 427 | + chord: "x", | ||
| 428 | + label: "Remove the picked equalizer band", | ||
| 429 | + category: Category::Audio, | ||
| 430 | + }, | ||
| 431 | + Fixed { | ||
| 432 | + chord: "f", | ||
| 433 | + label: "Flatten the picked band (double-click does the same)", | ||
| 434 | + category: Category::Audio, | ||
| 435 | + }, | ||
| 411 | Fixed { | 436 | Fixed { |
| 412 | chord: "r", | 437 | chord: "r", |
| 413 | label: "Flatten every band", | 438 | label: "Flatten every band", |
crates/app/src/main.rsmodified+497 -92
| @@ -528,6 +528,36 @@ const EQ_FREQ_HIGH: f32 = 20_000.; | |||
| 528 | /// and short enough that the card still fits a 360 px window. | 528 | /// and short enough that the card still fits a 360 px window. |
| 529 | const EQ_GRAPH_H: f32 = 132.; | 529 | const EQ_GRAPH_H: f32 = 132.; |
| 530 | 530 | ||
| 531 | +/// How wide the equalizer card is allowed to get. It is the one card that is a | ||
| 532 | +/// *graph*: every pixel across is frequency resolution, and at the 320 px the | ||
| 533 | +/// other cards use, a third of an octave was a couple of pixels. Past this the | ||
| 534 | +/// curve stops gaining anything and the card starts reading as a wall. | ||
| 535 | +const EQ_W_MAX: f32 = 720.; | ||
| 536 | + | ||
| 537 | +/// The gap the card leaves either side of it, so it reads as a card on a scrim | ||
| 538 | +/// rather than as a second window: it takes the width it can get inside that. | ||
| 539 | +const EQ_W_MARGIN: f32 = 32.; | ||
| 540 | + | ||
| 541 | +/// How many bands one clip's equalizer may carry from this card. Ten because | ||
| 542 | +/// the keyboard picks a band with a digit and a keyboard has ten of them -- | ||
| 543 | +/// past that a band would be reachable by pointer only. The engine itself caps | ||
| 544 | +/// nothing (`EqParams::bands` is a plain `Vec`), so a file may still carry more | ||
| 545 | +/// and this card will draw and edit every one it finds. | ||
| 546 | +const EQ_BANDS_MAX: usize = 10; | ||
| 547 | + | ||
| 548 | +/// One press of the frequency keys, as a factor: a sixth of an octave, so a | ||
| 549 | +/// band walks the whole axis in about sixty presses and still lands close | ||
| 550 | +/// enough to a named frequency to aim at one. | ||
| 551 | +const EQ_FREQ_STEP: f32 = 1.122_462; | ||
| 552 | + | ||
| 553 | +/// One press of the Q keys, as a factor, and the range they move in. Below the | ||
| 554 | +/// bottom a peak is barely a peak any more; above the top it is a whistle on | ||
| 555 | +/// one frequency. 0.707 -- the flat-shelf value, and the default -- sits inside | ||
| 556 | +/// them, so nothing a file carries has to be dragged into range first. | ||
| 557 | +const EQ_Q_STEP: f32 = 1.25; | ||
| 558 | +const EQ_Q_LOW: f32 = 0.3; | ||
| 559 | +const EQ_Q_HIGH: f32 = 12.; | ||
| 560 | + | ||
| 531 | /// How many points the curve is drawn from. One per ~3 px across the card: | 561 | /// How many points the curve is drawn from. One per ~3 px across the card: |
| 532 | /// past that the line is smooth and the extra biquad evaluations are wasted. | 562 | /// past that the line is smooth and the extra biquad evaluations are wasted. |
| 533 | const EQ_CURVE_STEPS: usize = 96; | 563 | const EQ_CURVE_STEPS: usize = 96; |
| @@ -576,6 +606,11 @@ const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |||
| 576 | /// its weight: it is what makes a boost read as a hill rather than as a wire. | 606 | /// its weight: it is what makes a boost read as a hill rather than as a wire. |
| 577 | const EQ_FILL_INK: u32 = 0x4a9eff26; | 607 | const EQ_FILL_INK: u32 = 0x4a9eff26; |
| 578 | 608 | ||
| 609 | +/// One band's own response, drawn under the sum: a dim thread per band, so a | ||
| 610 | +/// boost pushed against a cut can be *seen* as two bands rather than as the | ||
| 611 | +/// flat line their total makes. | ||
| 612 | +const EQ_BELL_INK: u32 = 0x4a9eff66; | ||
| 613 | + | ||
| 579 | /// The colour card's four controls, in the order it lists them: what each is | 614 | /// The colour card's four controls, in the order it lists them: what each is |
| 580 | /// called and the range it moves in. The order is `ColorParams`' own, which is | 615 | /// called and the range it moves in. The order is `ColorParams`' own, which is |
| 581 | /// what [`color_band`] indexes. | 616 | /// what [`color_band`] indexes. |
| @@ -1944,41 +1979,78 @@ impl Player { | |||
| 1944 | cx.notify(); | 1979 | cx.notify(); |
| 1945 | } | 1980 | } |
| 1946 | 1981 | ||
| 1947 | - /// Moves one band and says whether anything changed. Live only: the write | 1982 | + /// Changes the picked band in place and says whether anything moved. Every |
| 1948 | - /// is [`commit_eq`](Player::commit_eq)'s. | 1983 | + /// edit of a band goes through here -- the drag, each key, each stepper |
| 1949 | - fn set_band(&mut self, band: usize, gain_db: f32) -> bool { | 1984 | + /// button -- so the card has exactly one place that clamps a band into what |
| 1950 | - let gain_db = gain_db.clamp(-EQ_GAIN_LIMIT, EQ_GAIN_LIMIT); | 1985 | + /// the graph can draw, and no caller has to remember the limits. |
| 1951 | - match self.eq_params.bands.get_mut(band) { | 1986 | + fn set_band(&mut self, change: impl FnOnce(&mut Band)) -> bool { |
| 1952 | - Some(b) if b.gain_db != gain_db => { | 1987 | + let Some(band) = self.eq_params.bands.get_mut(self.eq_band) else { |
| 1953 | - b.gain_db = gain_db; | 1988 | + return false; |
| 1954 | - true | 1989 | + }; |
| 1955 | - } | 1990 | + let was = *band; |
| 1956 | - _ => false, | 1991 | + change(band); |
| 1992 | + band.freq_hz = band.freq_hz.clamp(EQ_FREQ_LOW, EQ_FREQ_HIGH); | ||
| 1993 | + band.gain_db = band.gain_db.clamp(-EQ_GAIN_LIMIT, EQ_GAIN_LIMIT); | ||
| 1994 | + band.q = band.q.clamp(EQ_Q_LOW, EQ_Q_HIGH); | ||
| 1995 | + *band != was | ||
| 1996 | + } | ||
| 1997 | + | ||
| 1998 | + /// The keyboard's and the buttons' version of a drag: one step on the picked | ||
| 1999 | + /// band, committed straight away -- neither has a release to wait for. | ||
| 2000 | + fn nudge_band(&mut self, change: impl FnOnce(&mut Band), cx: &mut Context<Self>) { | ||
| 2001 | + if self.set_band(change) { | ||
| 2002 | + self.commit_eq(cx); | ||
| 1957 | } | 2003 | } |
| 1958 | } | 2004 | } |
| 1959 | 2005 | ||
| 1960 | - /// The keyboard's version of a drag: one step on the picked band, committed | 2006 | + /// Where the pointer sits in the graph, as the picked band's frequency and |
| 1961 | - /// straight away -- a keystroke has no release to wait for. | 2007 | + /// gain: across is the frequency axis and down is the gain one, so the |
| 1962 | - fn nudge_band(&mut self, by: f32, cx: &mut Context<Self>) { | 2008 | + /// handle follows the hand both ways rather than sliding up a rail. Called |
| 1963 | - let gain = self | 2009 | + /// on every pointer sample, so the curve bends under it; the write is the |
| 1964 | - .eq_params | 2010 | + /// release's ([`commit_eq`](Player::commit_eq)). |
| 1965 | - .bands | 2011 | + fn drag_band(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) { |
| 1966 | - .get(self.eq_band) | 2012 | + let bounds = self.eq_graph.get(); |
| 1967 | - .map_or(0., |b| b.gain_db); | 2013 | + let gain = (0.5 - frac_down(at.y, bounds)) * 2. * EQ_GAIN_LIMIT; |
| 1968 | - if self.set_band(self.eq_band, gain + by) { | 2014 | + let freq = eq_freq(frac_along(at.x, bounds)); |
| 1969 | - self.commit_eq(cx); | 2015 | + if self.set_band(|b| { |
| 2016 | + b.gain_db = gain; | ||
| 2017 | + b.freq_hz = freq; | ||
| 2018 | + }) { | ||
| 2019 | + cx.notify(); | ||
| 1970 | } | 2020 | } |
| 1971 | } | 2021 | } |
| 1972 | 2022 | ||
| 1973 | - /// Where the pointer sits down the graph, as a gain on the picked band: the | 2023 | + /// A band added beside the picked one, at the frequency with the most room |
| 1974 | - /// middle is flat and the top and bottom edges are the limit either way. | 2024 | + /// around it ([`inserted_band`]), and picked so the next keystroke moves the |
| 1975 | - /// Called on every pointer sample, so the curve bends under the hand; the | 2025 | + /// band that was just made. Refused rather than silently ignored at the cap. |
| 1976 | - /// write is the release's ([`commit_eq`](Player::commit_eq)). | 2026 | + fn add_band(&mut self, cx: &mut Context<Self>) { |
| 1977 | - fn drag_band(&mut self, y: Pixels, cx: &mut Context<Self>) { | 2027 | + if self.eq_params.bands.len() >= EQ_BANDS_MAX { |
| 1978 | - let gain = (0.5 - frac_down(y, self.eq_graph.get())) * 2. * EQ_GAIN_LIMIT; | 2028 | + self.notice = Some( |
| 1979 | - if self.set_band(self.eq_band, gain) { | 2029 | + format!( |
| 2030 | + "EQUALIZER FULL — {EQ_BANDS_MAX} bands is all this card holds; move one instead" | ||
| 2031 | + ) | ||
| 2032 | + .into(), | ||
| 2033 | + ); | ||
| 1980 | cx.notify(); | 2034 | cx.notify(); |
| 2035 | + return; | ||
| 1981 | } | 2036 | } |
| 2037 | + let band = inserted_band(&self.eq_params.bands, self.eq_band); | ||
| 2038 | + self.eq_band = (self.eq_band + 1).min(self.eq_params.bands.len()); | ||
| 2039 | + self.eq_params.bands.insert(self.eq_band, band); | ||
| 2040 | + self.commit_eq(cx); | ||
| 2041 | + } | ||
| 2042 | + | ||
| 2043 | + /// Takes the picked band out. The last one stays: an equalizer of no bands | ||
| 2044 | + /// is a card with nothing to edit, and flattening is what "off" means here. | ||
| 2045 | + fn remove_band(&mut self, cx: &mut Context<Self>) { | ||
| 2046 | + if self.eq_params.bands.len() <= 1 { | ||
| 2047 | + self.notice = Some("LAST BAND — flatten it instead (r), or close the card".into()); | ||
| 2048 | + cx.notify(); | ||
| 2049 | + return; | ||
| 2050 | + } | ||
| 2051 | + self.eq_params.bands.remove(self.eq_band); | ||
| 2052 | + self.eq_band = self.eq_band.min(self.eq_params.bands.len() - 1); | ||
| 2053 | + self.commit_eq(cx); | ||
| 1982 | } | 2054 | } |
| 1983 | 2055 | ||
| 1984 | /// Which band a press on the graph grabs: the nearest one along the | 2056 | /// Which band a press on the graph grabs: the nearest one along the |
| @@ -3643,31 +3715,55 @@ impl Render for Player { | |||
| 3643 | // cannot move at all, and every one of them is listed in the | 3715 | // cannot move at all, and every one of them is listed in the |
| 3644 | // keys menu (keymap.rs `FIXED`) rather than being a secret. | 3716 | // keys menu (keymap.rs `FIXED`) rather than being a secret. |
| 3645 | if this.eq_open.is_some() { | 3717 | if this.eq_open.is_some() { |
| 3718 | + // Shift makes the two horizontal keys Q instead of | ||
| 3719 | + // frequency: both are the *width* of the same hump, so they | ||
| 3720 | + // sit on the same axis rather than on two keys nobody would | ||
| 3721 | + // guess. Wider is a lower Q, which is why left widens. | ||
| 3722 | + let shift = event.keystroke.modifiers.shift; | ||
| 3646 | if key == ESCAPE { | 3723 | if key == ESCAPE { |
| 3647 | // Nothing to undo: every change is already at the clip, | 3724 | // Nothing to undo: every change is already at the clip, |
| 3648 | // and undo is undo's own key. | 3725 | // and undo is undo's own key. |
| 3649 | this.eq_open = None; | 3726 | this.eq_open = None; |
| 3650 | this.eq_dragging = false; | 3727 | this.eq_dragging = false; |
| 3651 | } else if key == "up" { | 3728 | } else if key == "up" { |
| 3652 | - this.nudge_band(EQ_STEP, cx); | 3729 | + this.nudge_band(|b| b.gain_db += EQ_STEP, cx); |
| 3653 | } else if key == "down" { | 3730 | } else if key == "down" { |
| 3654 | - this.nudge_band(-EQ_STEP, cx); | 3731 | + this.nudge_band(|b| b.gain_db -= EQ_STEP, cx); |
| 3732 | + } else if key == "left" && shift { | ||
| 3733 | + this.nudge_band(|b| b.q /= EQ_Q_STEP, cx); | ||
| 3734 | + } else if key == "right" && shift { | ||
| 3735 | + this.nudge_band(|b| b.q *= EQ_Q_STEP, cx); | ||
| 3736 | + } else if key == "left" { | ||
| 3737 | + this.nudge_band(|b| b.freq_hz /= EQ_FREQ_STEP, cx); | ||
| 3738 | + } else if key == "right" { | ||
| 3739 | + this.nudge_band(|b| b.freq_hz *= EQ_FREQ_STEP, cx); | ||
| 3655 | } else if key == "r" { | 3740 | } else if key == "r" { |
| 3656 | for band in &mut this.eq_params.bands { | 3741 | for band in &mut this.eq_params.bands { |
| 3657 | band.gain_db = 0.; | 3742 | band.gain_db = 0.; |
| 3658 | } | 3743 | } |
| 3659 | this.commit_eq(cx); | 3744 | this.commit_eq(cx); |
| 3745 | + } else if key == "f" { | ||
| 3746 | + // This one band back to flat, which is the undo of one | ||
| 3747 | + // hand movement -- `r` is the undo of the whole card. | ||
| 3748 | + this.nudge_band(|b| b.gain_db = 0., cx); | ||
| 3749 | + } else if key == "a" { | ||
| 3750 | + this.add_band(cx); | ||
| 3751 | + } else if key == "x" { | ||
| 3752 | + this.remove_band(cx); | ||
| 3660 | } else if key == "s" { | 3753 | } else if key == "s" { |
| 3661 | // The analyser off and on. Nothing is committed: it is | 3754 | // The analyser off and on. Nothing is committed: it is |
| 3662 | // what the card *shows*, so it survives no further than | 3755 | // what the card *shows*, so it survives no further than |
| 3663 | // this window. | 3756 | // this window. |
| 3664 | this.eq_spectrum = !this.eq_spectrum; | 3757 | this.eq_spectrum = !this.eq_spectrum; |
| 3665 | } else if let Ok(digit) = key.parse::<usize>() { | 3758 | } else if let Ok(digit) = key.parse::<usize>() { |
| 3666 | - // 1-based, as the rows are numbered on screen; a digit | 3759 | + // As the keys are laid out: 1-9 then 0 for the tenth, |
| 3667 | - // past the last band picks nothing rather than panics. | 3760 | + // which is the cap ([`EQ_BANDS_MAX`]). A digit past the |
| 3668 | - if let Some(band) = digit.checked_sub(1) | 3761 | + // last band picks nothing rather than panics. |
| 3669 | - && band < this.eq_params.bands.len() | 3762 | + let band = match digit { |
| 3670 | - { | 3763 | + 0 => EQ_BANDS_MAX - 1, |
| 3764 | + n => n - 1, | ||
| 3765 | + }; | ||
| 3766 | + if band < this.eq_params.bands.len() { | ||
| 3671 | this.eq_band = band; | 3767 | this.eq_band = band; |
| 3672 | } | 3768 | } |
| 3673 | } | 3769 | } |
| @@ -3814,7 +3910,7 @@ impl Render for Player { | |||
| 3814 | // the equalizer drag is tracked here for the ruler's reason. | 3910 | // the equalizer drag is tracked here for the ruler's reason. |
| 3815 | if this.eq_dragging { | 3911 | if this.eq_dragging { |
| 3816 | if event.pressed_button == Some(MouseButton::Left) { | 3912 | if event.pressed_button == Some(MouseButton::Left) { |
| 3817 | - this.drag_band(event.position.y, cx); | 3913 | + this.drag_band(event.position, cx); |
| 3818 | } else { | 3914 | } else { |
| 3819 | // Released outside the window: the up below never came, | 3915 | // Released outside the window: the up below never came, |
| 3820 | // so this is where the gesture ends -- and it still owes | 3916 | // so this is where the gesture ends -- and it still owes |
| @@ -3884,7 +3980,7 @@ impl Render for Player { | |||
| 3884 | if std::mem::take(&mut this.eq_dragging) { | 3980 | if std::mem::take(&mut this.eq_dragging) { |
| 3885 | // The release lands exactly, then the gesture is written | 3981 | // The release lands exactly, then the gesture is written |
| 3886 | // once -- the append-only table's whole reason. | 3982 | // once -- the append-only table's whole reason. |
| 3887 | - this.drag_band(event.position.y, cx); | 3983 | + this.drag_band(event.position, cx); |
| 3888 | this.commit_eq(cx); | 3984 | this.commit_eq(cx); |
| 3889 | return; | 3985 | return; |
| 3890 | } | 3986 | } |
| @@ -3986,7 +4082,7 @@ impl Render for Player { | |||
| 3986 | // column, and only one of the two is ever up. | 4082 | // column, and only one of the two is ever up. |
| 3987 | .children(self.keys_overlay(cx)) | 4083 | .children(self.keys_overlay(cx)) |
| 3988 | .children(self.export_card(window.viewport_size(), cx)) | 4084 | .children(self.export_card(window.viewport_size(), cx)) |
| 3989 | - .children(self.eq_card(cx)) | 4085 | + .children(self.eq_card(window.viewport_size(), cx)) |
| 3990 | .children(self.color_card(cx)) | 4086 | .children(self.color_card(cx)) |
| 3991 | .children(self.speed_card(cx)) | 4087 | .children(self.speed_card(cx)) |
| 3992 | .children(self.silence_card(cx)) | 4088 | .children(self.silence_card(cx)) |
| @@ -5389,20 +5485,28 @@ impl Player { | |||
| 5389 | } | 5485 | } |
| 5390 | 5486 | ||
| 5391 | /// The equalizer of one audio clip: its frequency response drawn as a | 5487 | /// The equalizer of one audio clip: its frequency response drawn as a |
| 5392 | - /// curve, a handle per band sitting on it, and a row that flattens them | 5488 | + /// curve, a handle per band sitting on it, each band's own bell under the |
| 5393 | - /// all. The curve is the clip's actual filter (`EqParams::response_db` | 5489 | + /// sum, and a row that reads and moves the picked band's three numbers. The |
| 5394 | - /// reads the coefficients the samples go through), and it is redrawn on | 5490 | + /// curve is the clip's actual filter (`EqParams::response_db` reads the |
| 5395 | - /// every pointer sample of a drag, so the shape bends under the hand. | 5491 | + /// coefficients the samples go through), and it is redrawn on every pointer |
| 5492 | + /// sample of a drag, so the shape bends under the hand. | ||
| 5396 | /// | 5493 | /// |
| 5397 | - /// The same scrim and width as the other two cards, and the same plain divs | 5494 | + /// Wider than the other cards and wider still on a bigger window |
| 5398 | - /// -- nothing here takes focus, so the root keeps the keyboard and the | 5495 | + /// ([`eq_card_w`]): every pixel across is frequency resolution, which none |
| 5399 | - /// card's own strokes (`1`–`5`, up, down, `r`) reach it. | 5496 | + /// of the row-shaped cards have any use for. The same scrim and the same |
| 5497 | + /// plain divs -- nothing here takes focus, so the root keeps the keyboard | ||
| 5498 | + /// and the card's own strokes (a digit, the arrows, `a`, `x`, `f`, `r`, | ||
| 5499 | + /// `s`) reach it. | ||
| 5400 | /// | 5500 | /// |
| 5401 | /// Every change is written at the clip as it is made | 5501 | /// Every change is written at the clip as it is made |
| 5402 | /// ([`Player::commit_eq`]), so what the card shows is always what is | 5502 | /// ([`Player::commit_eq`]), so what the card shows is always what is |
| 5403 | /// playing: there is no OK button to forget, and closing it changes | 5503 | /// playing: there is no OK button to forget, and closing it changes |
| 5404 | /// nothing. What takes a curve back off is undo, like every other edit. | 5504 | /// nothing. What takes a curve back off is undo, like every other edit. |
| 5405 | - fn eq_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 5505 | + fn eq_card( |
| 5506 | + &self, | ||
| 5507 | + viewport: Size<Pixels>, | ||
| 5508 | + cx: &mut Context<Self>, | ||
| 5509 | + ) -> Option<impl IntoElement> { | ||
| 5406 | let (lane, idx) = self.eq_open?; | 5510 | let (lane, idx) = self.eq_open?; |
| 5407 | // The rate the engine filters this timeline at, so the drawn curve is | 5511 | // The rate the engine filters this timeline at, so the drawn curve is |
| 5408 | // the one those coefficients make -- near the top of the axis a 44.1 kHz | 5512 | // the one those coefficients make -- near the top of the axis a 44.1 kHz |
| @@ -5456,13 +5560,20 @@ impl Player { | |||
| 5456 | .bg(rgb(HOVER_DIM)) | 5560 | .bg(rgb(HOVER_DIM)) |
| 5457 | .cursor_pointer() | 5561 | .cursor_pointer() |
| 5458 | // The press picks the band under it *and* is already the first | 5562 | // The press picks the band under it *and* is already the first |
| 5459 | - // sample of the drag, so a plain click sets a value. | 5563 | + // sample of the drag, so a plain click sets a value. A second click |
| 5564 | + // takes that band back to flat instead: the gesture that undoes one | ||
| 5565 | + // handle, with no modifier to remember. | ||
| 5460 | .on_mouse_down( | 5566 | .on_mouse_down( |
| 5461 | MouseButton::Left, | 5567 | MouseButton::Left, |
| 5462 | cx.listener(|this, event: &MouseDownEvent, _, cx| { | 5568 | cx.listener(|this, event: &MouseDownEvent, _, cx| { |
| 5463 | this.eq_band = this.nearest_band(event.position.x); | 5569 | this.eq_band = this.nearest_band(event.position.x); |
| 5570 | + if event.click_count >= 2 { | ||
| 5571 | + this.eq_dragging = false; | ||
| 5572 | + this.nudge_band(|b| b.gain_db = 0., cx); | ||
| 5573 | + return; | ||
| 5574 | + } | ||
| 5464 | this.eq_dragging = true; | 5575 | this.eq_dragging = true; |
| 5465 | - this.drag_band(event.position.y, cx); | 5576 | + this.drag_band(event.position, cx); |
| 5466 | }), | 5577 | }), |
| 5467 | ) | 5578 | ) |
| 5468 | .child(bounds_probe(self.eq_graph.clone())) | 5579 | .child(bounds_probe(self.eq_graph.clone())) |
| @@ -5554,7 +5665,7 @@ impl Player { | |||
| 5554 | }) | 5665 | }) |
| 5555 | .child( | 5666 | .child( |
| 5556 | div() | 5667 | div() |
| 5557 | - .w(px(KEYS_W)) | 5668 | + .w(px(eq_card_w(f32::from(viewport.width)))) |
| 5558 | .flex() | 5669 | .flex() |
| 5559 | .flex_col() | 5670 | .flex_col() |
| 5560 | .gap(px(2.)) | 5671 | .gap(px(2.)) |
| @@ -5575,28 +5686,15 @@ impl Player { | |||
| 5575 | .text_size(px(11.)) | 5686 | .text_size(px(11.)) |
| 5576 | .text_color(rgb(INK_DIM)) | 5687 | .text_color(rgb(INK_DIM)) |
| 5577 | .child(self.notice.clone().unwrap_or_else(|| { | 5688 | .child(self.notice.clone().unwrap_or_else(|| { |
| 5578 | - "drag the curve, or 1–5 then up/down — s hides the spectrum, esc closes".into() | 5689 | + "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() |
| 5579 | })), | 5690 | })), |
| 5580 | ) | 5691 | ) |
| 5581 | .child(graph) | 5692 | .child(graph) |
| 5582 | - // Which band the keyboard is holding and what it is set | 5693 | + // Which band the keyboard is holding and every number it |
| 5583 | - // to: the curve shows the sum, and a band pushed against | 5694 | + // is set to, each with the pair of buttons that moves it: |
| 5584 | - // one pulling the other way is not readable off it. | 5695 | + // the curve shows the sum, and a band pushed against one |
| 5585 | - .child(div().flex_none().px(px(6.)).text_size(px(11.)).child( | 5696 | + // pulling the other way is not readable off it. |
| 5586 | - match picked { | 5697 | + .child(self.eq_numbers(picked, cx)) |
| 5587 | - // Q as well as the two the curve shows: it is | ||
| 5588 | - // how wide the hump under the handle is, and | ||
| 5589 | - // nothing else on the card says so. | ||
| 5590 | - Some(band) => format!( | ||
| 5591 | - "{} {} {:+.1} dB — Q {:.2}", | ||
| 5592 | - self.eq_band + 1, | ||
| 5593 | - band_label(band), | ||
| 5594 | - band.gain_db, | ||
| 5595 | - band.q | ||
| 5596 | - ), | ||
| 5597 | - None => "no bands".into(), | ||
| 5598 | - }, | ||
| 5599 | - )) | ||
| 5600 | .child( | 5698 | .child( |
| 5601 | div() | 5699 | div() |
| 5602 | .mt(px(4.)) | 5700 | .mt(px(4.)) |
| @@ -5620,7 +5718,45 @@ impl Player { | |||
| 5620 | } | 5718 | } |
| 5621 | this.commit_eq(cx); | 5719 | this.commit_eq(cx); |
| 5622 | })) | 5720 | })) |
| 5623 | - .child("Flatten"), | 5721 | + .child("Flatten all"), |
| 5722 | + ) | ||
| 5723 | + // The two that change how many bands there are. | ||
| 5724 | + // The engine takes any cascade -- the count was | ||
| 5725 | + // only ever fixed because this card had no way | ||
| 5726 | + // to say otherwise. | ||
| 5727 | + .child( | ||
| 5728 | + div() | ||
| 5729 | + .id("eq-add") | ||
| 5730 | + .flex() | ||
| 5731 | + .flex_1() | ||
| 5732 | + .h(px(CONTROL_H)) | ||
| 5733 | + .items_center() | ||
| 5734 | + .justify_center() | ||
| 5735 | + .rounded(px(3.)) | ||
| 5736 | + .bg(rgb(CHROME)) | ||
| 5737 | + .cursor_pointer() | ||
| 5738 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5739 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 5740 | + this.add_band(cx) | ||
| 5741 | + })) | ||
| 5742 | + .child("Add band"), | ||
| 5743 | + ) | ||
| 5744 | + .child( | ||
| 5745 | + div() | ||
| 5746 | + .id("eq-remove") | ||
| 5747 | + .flex() | ||
| 5748 | + .flex_1() | ||
| 5749 | + .h(px(CONTROL_H)) | ||
| 5750 | + .items_center() | ||
| 5751 | + .justify_center() | ||
| 5752 | + .rounded(px(3.)) | ||
| 5753 | + .bg(rgb(CHROME)) | ||
| 5754 | + .cursor_pointer() | ||
| 5755 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5756 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 5757 | + this.remove_band(cx) | ||
| 5758 | + })) | ||
| 5759 | + .child("Remove band"), | ||
| 5624 | ) | 5760 | ) |
| 5625 | // The analyser's switch, next to the one other | 5761 | // The analyser's switch, next to the one other |
| 5626 | // button the card has: `s` does the same, and a | 5762 | // button the card has: `s` does the same, and a |
| @@ -5655,6 +5791,103 @@ impl Player { | |||
| 5655 | ) | 5791 | ) |
| 5656 | } | 5792 | } |
| 5657 | 5793 | ||
| 5794 | + /// The picked band's three numbers -- where it sits, how far it pushes and | ||
| 5795 | + /// how wide it is -- each beside the pair of buttons that moves it. The | ||
| 5796 | + /// arrows do the same three things, but a value only a key can change is a | ||
| 5797 | + /// value a hand on the pointer cannot reach at all, which is the same reason | ||
| 5798 | + /// [`Player::mbps_steppers`] exists. | ||
| 5799 | + fn eq_numbers(&self, picked: Option<&Band>, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 5800 | + let row = div() | ||
| 5801 | + .flex_none() | ||
| 5802 | + .flex() | ||
| 5803 | + .items_center() | ||
| 5804 | + .gap(px(10.)) | ||
| 5805 | + .px(px(6.)) | ||
| 5806 | + .text_size(px(11.)); | ||
| 5807 | + let Some(band) = picked.copied() else { | ||
| 5808 | + return row.child("no bands — a adds one"); | ||
| 5809 | + }; | ||
| 5810 | + let step = |id: &'static str, | ||
| 5811 | + label: &'static str, | ||
| 5812 | + change: fn(&mut Band), | ||
| 5813 | + cx: &mut Context<Self>| { | ||
| 5814 | + div() | ||
| 5815 | + .id(id) | ||
| 5816 | + .flex() | ||
| 5817 | + .w(px(HIT_MIN)) | ||
| 5818 | + .h(px(HIT_MIN)) | ||
| 5819 | + .items_center() | ||
| 5820 | + .justify_center() | ||
| 5821 | + .rounded(px(3.)) | ||
| 5822 | + .bg(rgb(CHROME)) | ||
| 5823 | + .cursor_pointer() | ||
| 5824 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5825 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5826 | + this.nudge_band(change, cx) | ||
| 5827 | + })) | ||
| 5828 | + .child(label) | ||
| 5829 | + }; | ||
| 5830 | + let number = |value: String, | ||
| 5831 | + ids: (&'static str, &'static str), | ||
| 5832 | + by: (fn(&mut Band), fn(&mut Band)), | ||
| 5833 | + cx: &mut Context<Self>| { | ||
| 5834 | + div() | ||
| 5835 | + .flex() | ||
| 5836 | + .items_center() | ||
| 5837 | + .gap(px(4.)) | ||
| 5838 | + .child(div().child(value)) | ||
| 5839 | + .child(step(ids.0, "−", by.0, cx)) | ||
| 5840 | + .child(step(ids.1, "+", by.1, cx)) | ||
| 5841 | + }; | ||
| 5842 | + row.child(format!( | ||
| 5843 | + "Band {} of {}", | ||
| 5844 | + self.eq_band + 1, | ||
| 5845 | + self.eq_params.bands.len() | ||
| 5846 | + )) | ||
| 5847 | + .child(number( | ||
| 5848 | + band_label(&band), | ||
| 5849 | + ("eq-freq-down", "eq-freq-up"), | ||
| 5850 | + ( | ||
| 5851 | + |b| b.freq_hz /= EQ_FREQ_STEP, | ||
| 5852 | + |b| b.freq_hz *= EQ_FREQ_STEP, | ||
| 5853 | + ), | ||
| 5854 | + cx, | ||
| 5855 | + )) | ||
| 5856 | + .child(number( | ||
| 5857 | + format!("{:+.1} dB", band.gain_db), | ||
| 5858 | + ("eq-gain-down", "eq-gain-up"), | ||
| 5859 | + (|b| b.gain_db -= EQ_STEP, |b| b.gain_db += EQ_STEP), | ||
| 5860 | + cx, | ||
| 5861 | + )) | ||
| 5862 | + // Q is width, so its buttons are labelled by what they *do* to the | ||
| 5863 | + // hump rather than by which way the number goes: a wider band is a | ||
| 5864 | + // smaller Q, and nobody should have to know that to use the card. | ||
| 5865 | + .child(number( | ||
| 5866 | + format!("Q {:.2}", band.q), | ||
| 5867 | + ("eq-q-wider", "eq-q-narrower"), | ||
| 5868 | + (|b| b.q /= EQ_Q_STEP, |b| b.q *= EQ_Q_STEP), | ||
| 5869 | + cx, | ||
| 5870 | + )) | ||
| 5871 | + .child( | ||
| 5872 | + div() | ||
| 5873 | + .id("eq-flat-band") | ||
| 5874 | + .flex() | ||
| 5875 | + .h(px(HIT_MIN)) | ||
| 5876 | + .px(px(8.)) | ||
| 5877 | + .items_center() | ||
| 5878 | + .rounded(px(3.)) | ||
| 5879 | + .bg(rgb(CHROME)) | ||
| 5880 | + .cursor_pointer() | ||
| 5881 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5882 | + .on_click( | ||
| 5883 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 5884 | + this.nudge_band(|b| b.gain_db = 0., cx) | ||
| 5885 | + }), | ||
| 5886 | + ) | ||
| 5887 | + .child("Flatten this"), | ||
| 5888 | + ) | ||
| 5889 | + } | ||
| 5890 | + | ||
| 5658 | /// The colour card: the graded frame's histogram over a row per control, | 5891 | /// The colour card: the graded frame's histogram over a row per control, |
| 5659 | /// each row a bar the pointer drags straight to a value -- no stepper | 5892 | /// each row a bar the pointer drags straight to a value -- no stepper |
| 5660 | /// buttons, because a slider is a thing to pull, and the arrow keys still | 5893 | /// buttons, because a slider is a thing to pull, and the arrow keys still |
| @@ -7307,6 +7540,36 @@ fn eq_x(freq_hz: f32) -> f32 { | |||
| 7307 | ((freq_hz.max(1.) / EQ_FREQ_LOW).log10() / span).clamp(0., 1.) | 7540 | ((freq_hz.max(1.) / EQ_FREQ_LOW).log10() / span).clamp(0., 1.) |
| 7308 | } | 7541 | } |
| 7309 | 7542 | ||
| 7543 | +/// The frequency at a fraction across the graph -- [`eq_x`] backwards, which is | ||
| 7544 | +/// how a drag and the curve's own sample points read one. Clamped to the axis | ||
| 7545 | +/// either way, so a pointer that leaves the box stops at 20 Hz or 20 kHz. | ||
| 7546 | +fn eq_freq(along: f32) -> f32 { | ||
| 7547 | + EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along.clamp(0., 1.)) | ||
| 7548 | +} | ||
| 7549 | + | ||
| 7550 | +/// The band an "add" makes: a flat peak half way -- in octaves, which is what | ||
| 7551 | +/// the log axis draws -- between the picked band and whatever sits above it, so | ||
| 7552 | +/// a new band lands in the gap on screen rather than on top of its neighbour. | ||
| 7553 | +/// Above the topmost band the gap is the rest of the axis. | ||
| 7554 | +fn inserted_band(bands: &[Band], after: usize) -> Band { | ||
| 7555 | + let below = bands.get(after).map_or(1000., |b| b.freq_hz); | ||
| 7556 | + let above = bands | ||
| 7557 | + .iter() | ||
| 7558 | + .map(|b| b.freq_hz) | ||
| 7559 | + .filter(|f| *f > below) | ||
| 7560 | + .min_by(f32::total_cmp) | ||
| 7561 | + .unwrap_or(EQ_FREQ_HIGH); | ||
| 7562 | + Band { | ||
| 7563 | + freq_hz: (below * above).sqrt().clamp(EQ_FREQ_LOW, EQ_FREQ_HIGH), | ||
| 7564 | + gain_db: 0., | ||
| 7565 | + // A shade narrower than the flat-shelf 0.707 the defaults use: a band | ||
| 7566 | + // someone asked for is a band they mean to aim, and a wide one aimed at | ||
| 7567 | + // 300 Hz is really a band at everything. | ||
| 7568 | + q: 1., | ||
| 7569 | + kind: BandKind::Peak, | ||
| 7570 | + } | ||
| 7571 | +} | ||
| 7572 | + | ||
| 7310 | /// Where a gain sits *down* the graph, 0..1 from the top: flat is the middle, | 7573 | /// Where a gain sits *down* the graph, 0..1 from the top: flat is the middle, |
| 7311 | /// so a cut reads as a dip below the line it is a cut from. The inverse of | 7574 | /// so a cut reads as a dip below the line it is a cut from. The inverse of |
| 7312 | /// [`Player::drag_band`]'s reading of the pointer, and clamped like it, so a | 7575 | /// [`Player::drag_band`]'s reading of the pointer, and clamped like it, so a |
| @@ -7316,14 +7579,24 @@ fn eq_y(gain_db: f32) -> f32 { | |||
| 7316 | 0.5 - (gain_db / EQ_GAIN_LIMIT).clamp(-1., 1.) / 2. | 7579 | 0.5 - (gain_db / EQ_GAIN_LIMIT).clamp(-1., 1.) / 2. |
| 7317 | } | 7580 | } |
| 7318 | 7581 | ||
| 7582 | +/// A frequency as the card writes it. Two decimals of a kHz at most, with the | ||
| 7583 | +/// zeroes trimmed, so "1 kHz" stays "1 kHz" and a band nudged off it reads as | ||
| 7584 | +/// 1.12 kHz rather than as the same "1 kHz" it was before the keystroke -- a | ||
| 7585 | +/// number that does not move under an edit is worse than no number. | ||
| 7586 | +fn eq_freq_label(freq_hz: f32) -> String { | ||
| 7587 | + if freq_hz < 1000. { | ||
| 7588 | + return format!("{freq_hz:.0} Hz"); | ||
| 7589 | + } | ||
| 7590 | + let khz = format!("{:.2}", freq_hz / 1000.); | ||
| 7591 | + let khz = khz.trim_end_matches('0').trim_end_matches('.'); | ||
| 7592 | + format!("{khz} kHz") | ||
| 7593 | +} | ||
| 7594 | + | ||
| 7319 | /// What a band row calls itself: the corner or centre frequency, and for a | 7595 | /// What a band row calls itself: the corner or centre frequency, and for a |
| 7320 | /// shelf the fact that it tilts everything past it -- which is the difference | 7596 | /// shelf the fact that it tilts everything past it -- which is the difference |
| 7321 | /// between "12 kHz" moving the last octave and moving one band inside it. | 7597 | /// between "12 kHz" moving the last octave and moving one band inside it. |
| 7322 | fn band_label(band: &Band) -> String { | 7598 | fn band_label(band: &Band) -> String { |
| 7323 | - let freq = match band.freq_hz >= 1000. { | 7599 | + let freq = eq_freq_label(band.freq_hz); |
| 7324 | - true => format!("{:.0} kHz", band.freq_hz / 1000.), | ||
| 7325 | - false => format!("{:.0} Hz", band.freq_hz), | ||
| 7326 | - }; | ||
| 7327 | match band.kind { | 7600 | match band.kind { |
| 7328 | BandKind::LowShelf => format!("{freq} low shelf"), | 7601 | BandKind::LowShelf => format!("{freq} low shelf"), |
| 7329 | BandKind::HighShelf => format!("{freq} high shelf"), | 7602 | BandKind::HighShelf => format!("{freq} high shelf"), |
| @@ -7588,6 +7861,15 @@ fn unusable(info: &StreamInfo, timeline_audio: Option<(u32, u16)>) -> Option<Str | |||
| 7588 | }) | 7861 | }) |
| 7589 | } | 7862 | } |
| 7590 | 7863 | ||
| 7864 | +/// How wide the equalizer card is drawn in a window this wide: all of it bar a | ||
| 7865 | +/// margin, up to [`EQ_W_MAX`]. The card is a graph, and a graph of twenty | ||
| 7866 | +/// thousand hertz on 320 px spends four pixels on the octave below middle C -- | ||
| 7867 | +/// so it takes the room a big window has and stays inside a small one. Floored | ||
| 7868 | +/// at the other cards' width, which is the last size the rows still read at. | ||
| 7869 | +fn eq_card_w(window_w: f32) -> f32 { | ||
| 7870 | + (window_w - EQ_W_MARGIN).clamp(KEYS_W, EQ_W_MAX) | ||
| 7871 | +} | ||
| 7872 | + | ||
| 7591 | /// What the media list is given of the window. A share of it, so a narrow | 7873 | /// What the media list is given of the window. A share of it, so a narrow |
| 7592 | /// window gives the panel less rather than giving the picture nothing, floored | 7874 | /// window gives the panel less rather than giving the picture nothing, floored |
| 7593 | /// where a name stops being readable and capped at a third of the window -- | 7875 | /// where a name stops being readable and capped at a third of the window -- |
| @@ -8935,11 +9217,15 @@ fn eq_spectrum_curve(levels: Vec<f32>) -> impl IntoElement { | |||
| 8935 | .size_full() | 9217 | .size_full() |
| 8936 | } | 9218 | } |
| 8937 | 9219 | ||
| 8938 | -/// The cascade's frequency response, drawn as one line across the graph. | 9220 | +/// The cascade's frequency response, drawn as one line across the graph, with |
| 9221 | +/// each band's own response threaded dimly under it. | ||
| 8939 | /// | 9222 | /// |
| 8940 | /// Every point comes from `EqParams::response_db`, which reads the very | 9223 | /// Every point comes from `EqParams::response_db`, which reads the very |
| 8941 | /// coefficients the samples are filtered through: the curve cannot drift from | 9224 | /// coefficients the samples are filtered through: the curve cannot drift from |
| 8942 | -/// what is heard, because there is no second copy of the maths. | 9225 | +/// what is heard, because there is no second copy of the maths. A single band's |
| 9226 | +/// thread is that same call on a cascade of one, so the two cannot disagree | ||
| 9227 | +/// either -- and it is what makes a boost sitting inside a cut visible at all, | ||
| 9228 | +/// where the sum alone would draw a flat line and say nothing. | ||
| 8943 | /// | 9229 | /// |
| 8944 | /// ponytail: bands that overlap can sum past the ±`EQ_GAIN_LIMIT` axis and the | 9230 | /// ponytail: bands that overlap can sum past the ±`EQ_GAIN_LIMIT` axis and the |
| 8945 | /// curve then rides the edge of the box; upgrade = a wider dB axis with the | 9231 | /// curve then rides the edge of the box; upgrade = a wider dB axis with the |
| @@ -8949,16 +9235,37 @@ fn eq_curve(params: EqParams, sample_rate: u32) -> impl IntoElement { | |||
| 8949 | |_, _, _| (), | 9235 | |_, _, _| (), |
| 8950 | move |bounds, _, window, _| { | 9236 | move |bounds, _, window, _| { |
| 8951 | let (o, s) = (bounds.origin, bounds.size); | 9237 | let (o, s) = (bounds.origin, bounds.size); |
| 8952 | - let points: Vec<_> = (0..=EQ_CURVE_STEPS) | 9238 | + let line = |of: &EqParams| -> Vec<_> { |
| 8953 | - .map(|step| { | 9239 | + (0..=EQ_CURVE_STEPS) |
| 8954 | - let along = step as f32 / EQ_CURVE_STEPS as f32; | 9240 | + .map(|step| { |
| 8955 | - let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | 9241 | + let along = step as f32 / EQ_CURVE_STEPS as f32; |
| 8956 | - point( | 9242 | + point( |
| 8957 | - o.x + s.width * along, | 9243 | + o.x + s.width * along, |
| 8958 | - o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | 9244 | + o.y + s.height |
| 8959 | - ) | 9245 | + * eq_y(of.response_db(eq_freq(along), sample_rate)), |
| 9246 | + ) | ||
| 9247 | + }) | ||
| 9248 | + .collect() | ||
| 9249 | + }; | ||
| 9250 | + // One thread per band, first, so the sum is drawn over them. | ||
| 9251 | + for band in ¶ms.bands { | ||
| 9252 | + let mut bell = PathBuilder::stroke(px(1.)); | ||
| 9253 | + for (step, at) in line(&EqParams { | ||
| 9254 | + bands: vec![*band], | ||
| 8960 | }) | 9255 | }) |
| 8961 | - .collect(); | 9256 | + .into_iter() |
| 9257 | + .enumerate() | ||
| 9258 | + { | ||
| 9259 | + match step { | ||
| 9260 | + 0 => bell.move_to(at), | ||
| 9261 | + _ => bell.line_to(at), | ||
| 9262 | + } | ||
| 9263 | + } | ||
| 9264 | + if let Ok(bell) = bell.build() { | ||
| 9265 | + window.paint_path(bell, rgba(EQ_BELL_INK)); | ||
| 9266 | + } | ||
| 9267 | + } | ||
| 9268 | + let points = line(¶ms); | ||
| 8962 | // The area between the curve and 0 dB, closed along that line: a | 9269 | // The area between the curve and 0 dB, closed along that line: a |
| 8963 | // boost and a cut wind opposite ways around it, which is exactly | 9270 | // boost and a cut wind opposite ways around it, which is exactly |
| 8964 | // what makes both of them fill and the flat parts stay empty. | 9271 | // what makes both of them fill and the flat parts stay empty. |
| @@ -9062,16 +9369,19 @@ mod tests { | |||
| 9062 | use super::{ | 9369 | use super::{ |
| 9063 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | 9370 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, |
| 9064 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | 9371 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, |
| 9065 | - EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, | 9372 | + EQ_BANDS_MAX, EQ_FREQ_STEP, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_TICKS, EQ_W_MAX, ESCAPE, |
| 9373 | + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, | ||
| 9066 | HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, | 9374 | HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, |
| 9067 | KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, | 9375 | KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, |
| 9068 | LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, | 9376 | LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, |
| 9069 | PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, | 9377 | PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, |
| 9070 | SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Transport, VOLUME_W, Volume, | 9378 | SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Transport, VOLUME_W, Volume, |
| 9071 | WAVE_BPS, WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, | 9379 | WAVE_BPS, WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, |
| 9072 | - clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, eq_x, eq_y, | 9380 | + clipboard_after_remove, color_snap, containers, envelope, eq_card_w, eq_freq, eq_freq_label, |
| 9381 | + eq_spectrum, eq_x, eq_y, | ||
| 9073 | estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, | 9382 | estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, |
| 9074 | - fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, | 9383 | + fps_label, frac_along, frac_down, frame_at, histogram, inserted_band, is_bare_modifier, |
| 9384 | + is_project, | ||
| 9075 | keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, | 9385 | keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, |
| 9076 | project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, | 9386 | project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, |
| 9077 | source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, | 9387 | source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, |
| @@ -10724,6 +11034,9 @@ mod tests { | |||
| 10724 | "12 kHz high shelf" | 11034 | "12 kHz high shelf" |
| 10725 | ] | 11035 | ] |
| 10726 | ); | 11036 | ); |
| 11037 | + // A band moved off a round number reads as where it *is*: a keystroke | ||
| 11038 | + // that changes the filter and not the number on the card is a keystroke | ||
| 11039 | + // nobody can aim. | ||
| 10727 | assert_eq!( | 11040 | assert_eq!( |
| 10728 | band_label(&Band { | 11041 | band_label(&Band { |
| 10729 | freq_hz: 2600., | 11042 | freq_hz: 2600., |
| @@ -10731,23 +11044,38 @@ mod tests { | |||
| 10731 | q: 1., | 11044 | q: 1., |
| 10732 | kind: BandKind::Peak | 11045 | kind: BandKind::Peak |
| 10733 | }), | 11046 | }), |
| 10734 | - "3 kHz", | 11047 | + "2.6 kHz" |
| 10735 | - "rounded, because a band label is not a measurement" | 11048 | + ); |
| 11049 | + assert_eq!(eq_freq_label(1122.), "1.12 kHz"); | ||
| 11050 | + assert_eq!(eq_freq_label(12000.), "12 kHz", "no zeroes to read past"); | ||
| 11051 | + assert_eq!(eq_freq_label(80.), "80 Hz"); | ||
| 11052 | + | ||
| 11053 | + // The card fits the smallest window and takes the room a bigger one has | ||
| 11054 | + // -- it is a graph, and the width *is* the frequency resolution. | ||
| 11055 | + assert!(eq_card_w(640.) <= 640. - 24., "card too wide for 640"); | ||
| 11056 | + assert!(eq_card_w(1280.) > eq_card_w(640.), "card ignores the window"); | ||
| 11057 | + assert_eq!(eq_card_w(1920.), EQ_W_MAX, "card grows without end"); | ||
| 11058 | + assert!(eq_card_w(320.) >= KEYS_W, "card narrower than a row of text"); | ||
| 11059 | + // At the smallest window the graph is still a graph: three across for | ||
| 11060 | + // one down, so an octave is wide enough to put a handle in. | ||
| 11061 | + assert!( | ||
| 11062 | + eq_card_w(640.) - 24. >= 3. * EQ_GRAPH_H, | ||
| 11063 | + "graph too square to aim at" | ||
| 10736 | ); | 11064 | ); |
| 10737 | 11065 | ||
| 10738 | // The same shape as the other two cards, so it fits where they do: the | 11066 | // The same shape as the other two cards, so it fits where they do: the |
| 10739 | // graph stands where the export card's rows do, and is shorter than | 11067 | // graph stands where the export card's rows do, and is shorter than |
| 10740 | - // they are. | 11068 | + // they are. The numbers row is a row of buttons now, so it is one of |
| 10741 | - let (title, status, readout, gaps, padding) = (17., 28., 17., 4. * 2., 24.); | 11069 | + // those tall rather than one line of text. |
| 11070 | + let (title, status, gaps, padding) = (17., 28., 4. * 2., 24.); | ||
| 10742 | assert!( | 11071 | assert!( |
| 10743 | - title + status + EQ_GRAPH_H + readout + gaps + padding + CONTROL_H <= 360., | 11072 | + title + status + EQ_GRAPH_H + HIT_MIN + gaps + padding + CONTROL_H <= 360., |
| 10744 | "card too tall" | 11073 | "card too tall" |
| 10745 | ); | 11074 | ); |
| 10746 | assert!( | 11075 | assert!( |
| 10747 | EQ_GRAPH_H <= EXPORT_ROWS_H, | 11076 | EQ_GRAPH_H <= EXPORT_ROWS_H, |
| 10748 | "graph taller than a card of rows" | 11077 | "graph taller than a card of rows" |
| 10749 | ); | 11078 | ); |
| 10750 | - assert!(KEYS_W <= 640., "card too wide"); | ||
| 10751 | // What is dragged is the whole graph -- the handle is a 10 px dot, but | 11079 | // What is dragged is the whole graph -- the handle is a 10 px dot, but |
| 10752 | // a press anywhere in the box takes the band nearest it -- so WCAG | 11080 | // a press anywhere in the box takes the band nearest it -- so WCAG |
| 10753 | // 2.5.8 is satisfied by the box, which is far past the minimum. | 11081 | // 2.5.8 is satisfied by the box, which is far past the minimum. |
| @@ -10759,6 +11087,83 @@ mod tests { | |||
| 10759 | assert!(KEYS_ROW_H >= HIT_MIN); | 11087 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 10760 | } | 11088 | } |
| 10761 | 11089 | ||
| 11090 | + /// Editing a band, which is what the card is *for*: the pointer reads a | ||
| 11091 | + /// frequency off the axis the same way the axis draws one, a new band lands | ||
| 11092 | + /// in the gap beside the picked one rather than on top of it, and every band | ||
| 11093 | + /// the card will hold has a digit that picks it. | ||
| 11094 | + #[test] | ||
| 11095 | + fn a_band_can_be_moved_added_and_reached() { | ||
| 11096 | + use engine::eq::{Band, BandKind, EqParams}; | ||
| 11097 | + // Across the graph and back: a drag sets the frequency the handle is | ||
| 11098 | + // then drawn at, so the two mappings have to be one another's inverse or | ||
| 11099 | + // the handle walks away from the pointer. | ||
| 11100 | + for freq in [20., 80., 250., 1000., 4000., 12000., 20000.] { | ||
| 11101 | + let read = eq_freq(eq_x(freq)); | ||
| 11102 | + assert!( | ||
| 11103 | + (read / freq - 1.).abs() < 1e-3, | ||
| 11104 | + "{freq} Hz read back as {read}" | ||
| 11105 | + ); | ||
| 11106 | + } | ||
| 11107 | + // Off the box either end stops at the axis, never past it. | ||
| 11108 | + assert_eq!(eq_freq(-1.), EQ_FREQ_LOW); | ||
| 11109 | + assert_eq!(eq_freq(2.), EQ_FREQ_HIGH); | ||
| 11110 | + | ||
| 11111 | + // A step of the frequency keys is a real move on screen -- a keystroke | ||
| 11112 | + // that changes nothing visible is a keystroke that reads as broken -- | ||
| 11113 | + // and small enough to aim with. | ||
| 11114 | + let step = eq_x(1000. * EQ_FREQ_STEP) - eq_x(1000.); | ||
| 11115 | + assert!(step > 0.01 && step < 0.06, "frequency key steps {step}"); | ||
| 11116 | + | ||
| 11117 | + // A new band lands between the picked one and the next one up, in | ||
| 11118 | + // octaves: 250 Hz and 1 kHz put it at 500, which is a gap on screen. | ||
| 11119 | + let bands = EqParams::default_layout().bands; | ||
| 11120 | + let added = inserted_band(&bands, 1); | ||
| 11121 | + assert!((added.freq_hz - 500.).abs() < 1., "landed at {added:?}"); | ||
| 11122 | + assert_eq!(added.gain_db, 0., "a new band changes nothing until moved"); | ||
| 11123 | + assert_eq!(added.kind, BandKind::Peak, "a new band is not a shelf"); | ||
| 11124 | + assert!(eq_x(added.freq_hz) - eq_x(bands[1].freq_hz) > 0.1); | ||
| 11125 | + // Above the topmost band the gap is the rest of the axis, and the band | ||
| 11126 | + // still lands on it rather than off the end. | ||
| 11127 | + let top = inserted_band(&bands, bands.len() - 1); | ||
| 11128 | + assert!( | ||
| 11129 | + top.freq_hz > bands[4].freq_hz && top.freq_hz <= EQ_FREQ_HIGH, | ||
| 11130 | + "landed at {top:?}" | ||
| 11131 | + ); | ||
| 11132 | + // Bands out of frequency order (a drag may cross two over) still get a | ||
| 11133 | + // sane neighbour: the next one *up*, not the next one along the list. | ||
| 11134 | + let crossed = vec![ | ||
| 11135 | + Band { | ||
| 11136 | + freq_hz: 4000., | ||
| 11137 | + gain_db: 0., | ||
| 11138 | + q: 1., | ||
| 11139 | + kind: BandKind::Peak, | ||
| 11140 | + }, | ||
| 11141 | + Band { | ||
| 11142 | + freq_hz: 100., | ||
| 11143 | + gain_db: 0., | ||
| 11144 | + q: 1., | ||
| 11145 | + kind: BandKind::Peak, | ||
| 11146 | + }, | ||
| 11147 | + ]; | ||
| 11148 | + let between = inserted_band(&crossed, 1); | ||
| 11149 | + assert!( | ||
| 11150 | + (between.freq_hz - 632.).abs() < 2., | ||
| 11151 | + "landed at {between:?}, not between 100 and 4000" | ||
| 11152 | + ); | ||
| 11153 | + | ||
| 11154 | + // Every band the card will hold is one digit away: the keyboard has ten | ||
| 11155 | + // digits, which is exactly why the cap is what it is. | ||
| 11156 | + assert!( | ||
| 11157 | + EQ_BANDS_MAX <= 10, | ||
| 11158 | + "a band past the tenth has no key that picks it" | ||
| 11159 | + ); | ||
| 11160 | + assert!(EQ_BANDS_MAX > EqParams::default_layout().bands.len()); | ||
| 11161 | + // The Q range holds the default, so a file's band never opens out of | ||
| 11162 | + // range and needs dragging back in before it can be edited. | ||
| 11163 | + assert!((EQ_Q_LOW..=EQ_Q_HIGH).contains(&0.707)); | ||
| 11164 | + assert!(EQ_Q_STEP > 1.); | ||
| 11165 | + } | ||
| 11166 | + | ||
| 10762 | /// The analyser drawn behind the curve: a tone has to land on its own | 11167 | /// The analyser drawn behind the curve: a tone has to land on its own |
| 10763 | /// frequency, or the backdrop is a decoration rather than a reading of what | 11168 | /// frequency, or the backdrop is a decoration rather than a reading of what |
| 10764 | /// is playing -- and someone shaping a band against it would be aiming at | 11169 | /// is playing -- and someone shaping a band against it would be aiming at |