-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0e2ce8
commit 45635c5
Showing
12 changed files
with
280 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use super::effect_type::EffectType; | ||
|
||
/// A hashable EffectType. | ||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, Deserialize, Serialize)] | ||
pub enum ValuelessEffectType { | ||
#[default] | ||
Chorus, | ||
Reverb, | ||
Pan, | ||
PitchBend, | ||
ChannelPressure, | ||
PolyphonicKeyPressure, | ||
} | ||
|
||
impl From<EffectType> for ValuelessEffectType { | ||
fn from(value: EffectType) -> Self { | ||
match value { | ||
EffectType::Chorus(_) => Self::Chorus, | ||
EffectType::Reverb(_) => Self::Reverb, | ||
EffectType::Pan(_) => Self::Pan, | ||
EffectType::PitchBend(_) => Self::PitchBend, | ||
EffectType::ChannelPressure(_) => Self::ChannelPressure, | ||
EffectType::PolyphonicKeyPressure { key: _, value: _ } => Self::PolyphonicKeyPressure, | ||
} | ||
} | ||
} | ||
|
||
impl ValuelessEffectType { | ||
pub fn eq(&self, value: &EffectType) -> bool { | ||
match value { | ||
EffectType::Chorus(_) => *self == Self::Chorus, | ||
EffectType::Reverb(_) => *self == Self::Reverb, | ||
EffectType::Pan(_) => *self == Self::Pan, | ||
EffectType::PitchBend(_) => *self == Self::PitchBend, | ||
EffectType::ChannelPressure(_) => *self == Self::ChannelPressure, | ||
EffectType::PolyphonicKeyPressure { key: _, value: _ } => *self == Self::PolyphonicKeyPressure, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ pub enum PanelType { | |
ExportSettings, | ||
Quit, | ||
Links, | ||
Effects, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use crate::panel::*; | ||
use common::{EffectType, Effect, ValuelessEffectType, MIDDLE_C}; | ||
use text::EFFECT_NAME_KEYS; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct EffectsPanel { | ||
} | ||
|
||
impl EffectsPanel { | ||
/// Increment or decrement the effect type index. | ||
fn cycle_effect_type(state: &mut State, up: bool) -> Option<Snapshot> { | ||
let s0 = state.clone(); | ||
state.effect_types.index.increment(up); | ||
Some(Snapshot::from_states(s0, state)) | ||
} | ||
|
||
fn increment_effect_value(state: &mut State, conn: &Conn, up: bool) -> Option<Snapshot> { | ||
let s0 = state.clone(); | ||
let ve = state.effect_types.get(); | ||
match state.music.get_selected_track_mut() { | ||
Some(track) => match track.effects.iter_mut().filter(|e| e.time == state.time.cursor && ve.eq(&e.effect)).next() { | ||
Some(effect) => { | ||
if (up && effect.effect.increment()) || (!up && effect.effect.decrement()) { | ||
Some(Snapshot::from_states(s0, state)) | ||
} | ||
else { | ||
None | ||
} | ||
} | ||
// Add a new effect. | ||
None => { | ||
let program = &conn.state.programs[&track.channel]; | ||
// Get a new effect type. | ||
let effect_type = match ve { | ||
ValuelessEffectType::Chorus => EffectType::Chorus(program.chorus as u16), | ||
ValuelessEffectType::Pan => EffectType::Pan(program.pan as i16), | ||
ValuelessEffectType::Reverb => EffectType::Reverb(program.reverb as u16), | ||
ValuelessEffectType::PitchBend => EffectType::PitchBend(0), | ||
ValuelessEffectType::ChannelPressure => EffectType::ChannelPressure(0), | ||
ValuelessEffectType::PolyphonicKeyPressure => EffectType::PolyphonicKeyPressure { key: MIDDLE_C, value: 0 } | ||
}; | ||
// Get a new effect. | ||
track.effects.push(Effect { time: state.time.cursor, effect: effect_type }); | ||
Some(Snapshot::from_states(s0, state)) | ||
} | ||
} | ||
None => None | ||
} | ||
} | ||
} | ||
|
||
impl Panel for EffectsPanel { | ||
fn update( | ||
&mut self, | ||
state: &mut State, | ||
conn: &mut Conn, | ||
input: &Input, | ||
tts: &mut TTS, | ||
text: &Text, | ||
_: &mut PathsState, | ||
) -> Option<Snapshot> { | ||
// Cycle the selected input event. | ||
if input.happened(&InputEvent::NextEffect) { | ||
Self::cycle_effect_type(state, true) | ||
} | ||
else if input.happened(&InputEvent::PreviousEffect) { | ||
Self::cycle_effect_type(state, false) | ||
} | ||
else if input.happened(&InputEvent::IncrementEffectValue) { | ||
Self::increment_effect_value(state, conn, true) | ||
} | ||
else if input.happened(&InputEvent::DecrementEffectValue) { | ||
Self::increment_effect_value(state, conn, false) | ||
} | ||
else if input.happened(&InputEvent::DeleteEffect) { | ||
let s0 = state.clone(); | ||
let ve = state.effect_types.get(); | ||
match state.music.get_selected_track_mut() { | ||
Some(track) => { | ||
let has_effect = track.effects.iter().filter(|e| e.time == state.time.cursor && ve.eq(&e.effect)).next().is_some(); | ||
track.effects.retain(|e| e.time != state.time.cursor || !ve.eq(&e.effect)); | ||
if has_effect { | ||
Some(Snapshot::from_states(s0, state)) | ||
} | ||
else { | ||
None | ||
} | ||
} | ||
None => None | ||
} | ||
} | ||
else { | ||
None | ||
} | ||
} | ||
|
||
fn on_disable_abc123(&mut self, _: &mut State, _: &mut Conn) {} | ||
|
||
fn update_abc123( | ||
&mut self, | ||
_: &mut State, | ||
_: &Input, | ||
_: &mut Conn, | ||
) -> (Option<Snapshot>, bool) { | ||
(None, false) | ||
} | ||
|
||
fn allow_alphanumeric_input(&self, _: &State, _: &Conn) -> bool { | ||
false | ||
} | ||
|
||
fn allow_play_music(&self) -> bool { | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.