Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6d86f8

Browse files
authored
Merge pull request #5 from Azorlogh/iced-interval-input
Iced interval input
2 parents 04a6fdc + b402f3f commit e6d86f8

14 files changed

Lines changed: 573 additions & 215 deletions

File tree

Cargo.lock

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harmoxen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
[lib]
88

99
[dependencies]
10-
iced = { git = "https://github.com/hecrj/iced.git", branch = "master", features = [ "debug", "tokio" ]}
10+
iced = { git = "https://github.com/hecrj/iced.git", branch = "master", features = [ "debug", "tokio", "canvas" ]}
1111
iced_native = { git = "https://github.com/hecrj/iced.git", branch = "master" }
1212
iced_wgpu = { git = "https://github.com/hecrj/iced.git", branch = "master" }
1313
iced_winit = { git = "https://github.com/hecrj/iced.git", branch = "master" }

harmoxen/src/state/sheet_editor.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::backend;
22
use crate::data::{
33
self,
44
layout::Layout,
5-
sheet::{Clipboard, Interval, Sheet},
5+
sheet::{self, Clipboard, Pitch, Sheet},
66
Frame, Frame2, Point, Range,
77
};
88
use crate::state::Message as RootMessage;
@@ -21,6 +21,7 @@ pub struct WStates {
2121
pub yrange_slider: widget::range_slider::State,
2222
pub cursor: widget::sheet_editor::cursor::State,
2323
pub preview: widget::sheet_editor::preview::State,
24+
pub interval_input: Option<widget::sheet_editor::interval_input::State>,
2425
}
2526

2627
pub struct State {
@@ -33,7 +34,6 @@ pub struct State {
3334
pub last_tick: Instant,
3435
pub layout: Layout,
3536
pub tempo: f32,
36-
pub interval_input: Interval,
3737
pub curr_marker: usize,
3838
pub selection: HashSet<Index>,
3939
pub clipboard: Rc<RefCell<Clipboard>>,
@@ -61,7 +61,6 @@ impl Default for State {
6161
last_tick: Instant::now(),
6262
layout: Layout::default(),
6363
tempo: 172.0,
64-
interval_input: Interval::Ratio(3, 2),
6564
curr_marker: 0,
6665
selection: HashSet::new(),
6766
clipboard: Rc::new(RefCell::new(Clipboard::new())),
@@ -110,22 +109,36 @@ impl State {
110109
Message::SetCursor(at) => {
111110
self.cursor = at;
112111
}
113-
Message::AddNote(note, mov) => {
112+
Message::NoteAdd(note, mov) => {
114113
let idx = self.sheet.add_note(note);
115-
if mov {
114+
115+
if let Pitch::Relative(_, _) = note.pitch {
116+
self.wstates.interval_input = Some(widget::sheet_editor::interval_input::State::new(&self.sheet, idx));
117+
} else if mov {
116118
let rect = note.rect(&self.sheet, 0.0);
117119
self.wstates.board.set_action_move(idx, rect);
118120
}
119121
}
120-
Message::MoveNote(idx, pos) => {
122+
Message::NoteMove(idx, pos) => {
121123
self.sheet.move_note(idx, pos.x, pos.y);
122124
}
123-
Message::DeleteNote(idx) => {
125+
Message::NoteResize(idx, len) => {
126+
let note = self.sheet.get_note_mut(idx).expect("tried to resize dead note");
127+
note.length = len;
128+
}
129+
Message::NoteDelete(idx) => {
124130
self.sheet.remove_note(idx);
131+
self.wstates.interval_input = None;
125132
}
126-
Message::ResizeNote(idx, len) => {
127-
let note = self.sheet.get_note_mut(idx).unwrap();
128-
note.length = len;
133+
Message::NoteSetPitch(idx, pitch) => {
134+
let note = self.sheet.get_note_mut(idx).expect("tried to change pitch of dead note");
135+
note.pitch = pitch;
136+
}
137+
Message::OpenIntervalInput(idx) => {
138+
self.wstates.interval_input = Some(widget::sheet_editor::interval_input::State::new(&self.sheet, idx));
139+
}
140+
Message::CloseIntervalInput => {
141+
self.wstates.interval_input = None;
129142
}
130143
Message::AddMarker(at) => {
131144
let mut new_marker = self.layout.markers[self.curr_marker].clone();
@@ -157,10 +170,13 @@ pub enum Message {
157170
Play,
158171
CursorTick(Instant),
159172
SetCursor(f32),
160-
AddNote(data::sheet::Note, bool), // if true: initiate move action
161-
MoveNote(data::sheet::Index, Point),
162-
ResizeNote(data::sheet::Index, f32),
163-
DeleteNote(data::sheet::Index),
173+
NoteAdd(sheet::Note, bool), // if true: initiate move action
174+
NoteMove(sheet::Index, Point),
175+
NoteResize(sheet::Index, f32),
176+
NoteDelete(sheet::Index),
177+
NoteSetPitch(sheet::Index, Pitch),
178+
OpenIntervalInput(sheet::Index),
179+
CloseIntervalInput,
164180
AddMarker(f32),
165181
SelectMarker(usize),
166182
MoveMarker(f32),

harmoxen/src/style/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub const fn color(code: u32) -> iced::Color {
99
}
1010
}
1111

12-
mod flux;
13-
mod nord;
12+
// mod flux;
13+
// mod nord;
1414
mod one_dark;
1515

1616
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -60,7 +60,9 @@ impl_style!(tab, Tab);
6060

6161
mod sheet_editor {
6262
use super::{
63-
flux, nord, one_dark,
63+
// flux,
64+
// nord,
65+
one_dark,
6466
Theme::{self, *},
6567
};
6668
use crate::widget::sheet_editor::*;

harmoxen/src/style/one_dark.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const FEATURE_HL: Color = color(0x69FFA2);
1616

1717
const FG: Color = color(0xEEEEEE);
1818

19+
const RED: Color = color(0xE06C75);
20+
const GREEN: Color = color(0x98C379);
21+
const YELLOW: Color = color(0xE5C07B);
22+
const BLUE: Color = color(0x61AFEF);
23+
const MAGENTA: Color = color(0xC678DD);
24+
const CYAN: Color = color(0x56B6C2);
25+
1926
pub struct Container;
2027
impl container::StyleSheet for Container {
2128
fn style(&self) -> container::Style {
@@ -135,11 +142,26 @@ impl tab::StyleSheet for Tab {
135142
}
136143
}
137144

145+
fn context_menu() -> pick_list::Menu {
146+
pick_list::Menu {
147+
text_color: FG,
148+
background: BG_2.into(),
149+
border_width: 0,
150+
border_color: BG_1.into(),
151+
selected_background: BG_3.into(),
152+
selected_text_color: FG.into(),
153+
}
154+
}
155+
138156
pub mod sheet_editor {
139157
use super::*;
140158
use crate::widget::sheet_editor::*;
141159
pub struct Board;
142160
impl board::StyleSheet for Board {
161+
fn menu(&self) -> pick_list::Menu {
162+
context_menu()
163+
}
164+
143165
fn active(&self) -> board::Style {
144166
board::Style {
145167
note_color: FEATURE,
@@ -154,14 +176,7 @@ pub mod sheet_editor {
154176
pub struct MarkerEditor;
155177
impl marker_editor::StyleSheet for MarkerEditor {
156178
fn menu(&self) -> pick_list::Menu {
157-
pick_list::Menu {
158-
text_color: FG,
159-
background: BG_0.into(),
160-
border_width: 1,
161-
border_color: BG_1.into(),
162-
selected_background: BG_3.into(),
163-
selected_text_color: FG.into(),
164-
}
179+
context_menu()
165180
}
166181

167182
fn active(&self) -> marker_editor::Style {

harmoxen/src/ui/sheet_editor.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ pub fn build(state: &mut State, theme: Theme) -> Element<RootMessage> {
5353
)
5454
.height(TIMELINE_THICKNESS.into());
5555

56+
let mut editing_area = Stack::new()
57+
.push(
58+
Board::new(
59+
&mut state.wstates.board,
60+
&state.sheet,
61+
&state.frame,
62+
&state.layout,
63+
&state.cursor,
64+
&state.selection,
65+
)
66+
.style(theme),
67+
)
68+
.push(ScrollView::new(
69+
&mut state.wstates.scroll_view,
70+
&state.frame,
71+
[(true, false), (true, true)],
72+
|| Message::SetScrolling.into(),
73+
));
74+
if let Some(wstate) = &mut state.wstates.interval_input {
75+
editing_area = editing_area.push(IntervalInput::new(wstate, &state.sheet, &state.frame));
76+
}
77+
5678
Stack::new()
5779
.push(
5880
Row::new()
@@ -69,30 +91,7 @@ pub fn build(state: &mut State, theme: Theme) -> Element<RootMessage> {
6991
.push(Column::new().push(x_scrollbar).push(timeline).width(Length::Fill))
7092
.push(Space::with_width(SCROLLBAR_THICKNESS.into())),
7193
)
72-
.push(
73-
Row::new()
74-
.push(
75-
Stack::new()
76-
.push(
77-
Board::new(
78-
&mut state.wstates.board,
79-
&state.sheet,
80-
&state.frame,
81-
&state.layout,
82-
&state.cursor,
83-
&state.selection,
84-
)
85-
.style(theme),
86-
)
87-
.push(ScrollView::new(
88-
&mut state.wstates.scroll_view,
89-
&state.frame,
90-
[(true, false), (true, true)],
91-
|| Message::SetScrolling.into(),
92-
)),
93-
)
94-
.push(y_scrollbar),
95-
),
94+
.push(Row::new().push(editing_area).push(y_scrollbar)),
9695
),
9796
)
9897
.push(Shortcuts)

harmoxen/src/widget/common/stack/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ where
4545
)
4646
}
4747

48-
fn hash_layout(&self, _action: &mut Hasher) {}
48+
fn hash_layout(&self, state: &mut Hasher) {
49+
for child in &self.children {
50+
child.hash_layout(state)
51+
}
52+
}
4953

5054
fn on_event(
5155
&mut self,
@@ -56,7 +60,7 @@ where
5660
renderer: &Renderer<B>,
5761
clipboard: Option<&dyn Clipboard>,
5862
) -> event::Status {
59-
let layouts: Vec<Layout> = layout.children().collect();
63+
let layouts: Vec<Layout> = layout.children().collect(); // should reverse this
6064
for i in (0..self.children.len()).rev() {
6165
let child = &mut self.children[i];
6266
let status = child.on_event(event.clone(), layouts[i], cursor_position, messages, renderer, clipboard);

0 commit comments

Comments
 (0)