Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
alters-mit committed Dec 13, 2023
1 parent cfcba04 commit 9c5bbb0
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 14 deletions.
4 changes: 3 additions & 1 deletion data/text.csv
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,6 @@ EFFECTS_PANE_INPUT_TTS_VALUE,\0 and \1 to set the effect's value.
EFFECTS_PANEL_INPUT_TTS_AFTERTOUCH,\0 and \1 to set the aftertouch note.
EFFECTS_PANEL_STATUS_TTS_NO_EFFECT,The selected effect is \0 but you haven't added this effect.
EFFECTS_PANEL_STATUS_TTS_EFFECT_NAME,The selected effect is \0. The value is \1. The time is \2.
EFFECTS_PANEL_STATUS_TTS_AFTERTOUCH_KEY,The aftertouch note is \0.
EFFECTS_PANEL_STATUS_TTS_AFTERTOUCH_KEY,The aftertouch note is \0.
EFFECTS_PANEL_POLYPHONIC_KEY_PRESSURE_NOTE,Note
EFFECTS_PANEL_POLYPHONIC_KEY_PRESSURE_VALUE,Value
2 changes: 1 addition & 1 deletion io/src/effects_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl EffectsPanel {
}
}
}

/// Get the selected effect.
fn get_effect(state: &mut State) -> Option<&mut Effect> {
let ve = state.effect_types.get();
Expand Down
2 changes: 1 addition & 1 deletion io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl IO {
PanelType::Tracks => &mut self.tracks_panel,
PanelType::Quit => &mut self.quit_panel,
PanelType::Links => &mut self.links_panel,
PanelType::Effects => &mut self.effects_panel
PanelType::Effects => &mut self.effects_panel,
}
}

Expand Down
134 changes: 134 additions & 0 deletions render/src/effects_panel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
use std::ops::Index;

use crate::get_effects_panel_width;
use crate::panel::*;
use common::Effect;
use common::ValuelessEffectType;
use text::EFFECT_NAME_KEYS;

const VALUE_WIDTH: u32 = 5;
const EFFECT_TYPES: [ValuelessEffectType; 6] = [
ValuelessEffectType::Chorus,
ValuelessEffectType::Reverb,
ValuelessEffectType::Pan,
ValuelessEffectType::PitchBend,
ValuelessEffectType::ChannelPressure,
ValuelessEffectType::PolyphonicKeyPressure,
];

#[derive(Debug)]
struct EffectField {
label: Label,
value: List,
rect: Rectangle,
}

impl EffectField {
fn new(x: u32, y: &mut u32, width: u32, i: usize, text: &Text) -> Self {
let label = Label::new([x, *y], text.get(EFFECT_NAME_KEYS[i]));
let value = List::new([x, *y + 1], VALUE_WIDTH);
let rect = Rectangle::new([x, *y], [width, 2]);
*y += 2;
Self { label, value, rect }
}
}

pub(crate) struct EffectsPanel {
panel: Panel,
effects: [EffectField; 5],
aftertouch_label: Label,
aftertouch_rect: Rectangle,
aftertouch_values: [KeyList; 2],
}

impl EffectsPanel {
pub fn new(config: &Ini, renderer: &Renderer, text: &Text) -> Self {
// Get the panel.
let size = [
get_effects_panel_width(text),
get_piano_roll_panel_size(config)[1]
- PIANO_ROLL_PANEL_TOP_BAR_HEIGHT
- PIANO_ROLL_PANEL_VOLUME_HEIGHT,
];
let position = [
get_window_grid_size(config)[0] - size[0],
MAIN_MENU_HEIGHT + PIANO_ROLL_PANEL_TOP_BAR_HEIGHT,
];
let panel = Panel::new(PanelType::Effects, position, size, renderer, text);
// Get the labels.
let x = position[0] + 1;
let mut y = position[1] + 1;
let width = size[0] - 2;
let effects: [EffectField; 5] = (0..5)
.map(|i| EffectField::new(x, &mut y, width, i, text))
.collect::<Vec<EffectField>>()
.try_into()
.unwrap();
let aftertouch_label = Label::new([x, y], text.get(EFFECT_NAME_KEYS[5]));
let aftertouch_rect = Rectangle::new([x, y], [width, 2]);
y += 1;
let aftertouch_values = [
KeyList::new(
text.get("EFFECTS_PANEL_POLYPHONIC_KEY_PRESSURE_NOTE"),
[x, y],
width,
VALUE_WIDTH,
),
KeyList::new(
text.get("EFFECTS_PANEL_POLYPHONIC_KEY_PRESSURE_VALUE"),
[x, y + 1],
width,
VALUE_WIDTH,
),
];
Self {
panel,
effects,
aftertouch_label,
aftertouch_rect,
aftertouch_values,
}
}
}

impl Drawable for EffectsPanel {
fn update(
&self,
renderer: &Renderer,
state: &State,
_: &Conn,
_: &Text,
_: &PathsState,
) {
// Render the panel.
let focus = self.panel.has_focus(state);
self.panel.update(focus, renderer);

// Is there a playable track?
match state.music.get_selected_track() {
Some(track) => {
// Get the selected effects.
let mut selected = [false; EFFECT_TYPES.len()];
if let Some((_, effects)) = state.selection.get_selection(&state.music) {
for effect in effects {
for (i, e) in EFFECT_TYPES.iter().enumerate() {
if e.eq(&effect.effect) {
selected[i] = true;
}
}
}
}
// Get the effects at this time.
let current_effects = track.effects.iter().filter(|e| e.time == state.time.cursor).map(|e| ValuelessEffectType::from(e.effect)).collect::<Vec<ValuelessEffectType>>();
for ((field, selected), effect) in self.effects.iter().zip(selected).zip(current_effects) {

}
}
None => {
for e in self.effects.iter() {
renderer.text(&e.label, &ColorKey::NoFocus);
}
}
}
}
}
1 change: 1 addition & 0 deletions render/src/field_params/key_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Label, List};

/// A key `Label` on the left and a `List` on the right.
#[derive(Debug)]
pub(crate) struct KeyList {
/// The key label.
pub key: Label,
Expand Down
2 changes: 1 addition & 1 deletion render/src/field_params/label.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A position and a string.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct Label {
/// The position in grid units.
pub position: [u32; 2],
Expand Down
1 change: 1 addition & 0 deletions render/src/field_params/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const LEFT_ARROW: &str = "<";
const RIGHT_ARROW: &str = ">";

/// A list has a label and two arrows.
#[derive(Debug)]
pub(crate) struct List {
/// The label at the center of the list. There is no stored text.
label: Width,
Expand Down
2 changes: 1 addition & 1 deletion render/src/field_params/rectangle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A rectangle has a position and a size.
#[derive(Clone)]
#[derive(Clone, Default, Debug)]
pub(crate) struct Rectangle {
/// The position in grid units.
pub position: [u32; 2],
Expand Down
1 change: 1 addition & 0 deletions render/src/field_params/width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use text::truncate;

/// Not a label... but the IDEA of a label.
/// This holds space for text.
#[derive(Debug)]
pub(crate) struct Width {
/// The position in grid coordinates.
pub position: [u32; 2],
Expand Down
11 changes: 11 additions & 0 deletions render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use audio::Conn;
use common::State;
pub(crate) use page::Page;
pub(crate) use page_position::PagePosition;
mod effects_panel;
mod links_panel;
mod quit_panel;

Expand All @@ -65,3 +66,13 @@ pub(crate) fn get_track_heights(state: &State, conn: &Conn) -> Vec<u32> {
}
elements
}

/// Returns the width of the longest effect name.
pub(crate) fn get_effects_panel_width(text: &text::Text) -> u32 {
(*text::EFFECT_NAME_KEYS
.map(|s| text.get_ref(s).chars().count())
.iter()
.max()
.unwrap()
+ 2) as u32
}
9 changes: 0 additions & 9 deletions text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,6 @@ impl Text {
})
}

/// Returns the width of the longest effect name.
pub fn get_effect_name_max_width(&self) -> usize {
*EFFECT_NAME_KEYS
.map(|s| self.text[s].len())
.iter()
.max()
.unwrap()
}

/// Returns the name of the note.
pub fn get_note_name(&self, note: u8) -> &str {
&self.note_names[(note - MIN_NOTE) as usize]
Expand Down

0 comments on commit 9c5bbb0

Please sign in to comment.