Skip to content

Commit eff6b08

Browse files
author
stephen
committed
can optionally save custom midi config with project
1 parent 3c519b8 commit eff6b08

3 files changed

Lines changed: 37 additions & 65 deletions

File tree

example.project.json

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
"ControlValue": 165
3535
},
3636
"colour": {
37-
"ColourValue": [
38-
0,
39-
0,
40-
0,
41-
0
42-
]
37+
"ColourValue": [0, 0, 0, 0]
4338
},
4439
"zoom": {
4540
"ControlValue": 0
@@ -53,12 +48,7 @@
5348
"ControlValue": 0
5449
},
5550
"colour": {
56-
"ColourValue": [
57-
0,
58-
0,
59-
0,
60-
0
61-
]
51+
"ColourValue": [0, 0, 0, 0]
6252
},
6353
"tilt": {
6454
"ControlValue": 120
@@ -75,12 +65,7 @@
7565
"ControlValue": 0
7666
},
7767
"colour": {
78-
"ColourValue": [
79-
0,
80-
0,
81-
0,
82-
0
83-
]
68+
"ColourValue": [0, 0, 0, 0]
8469
},
8570
"pan": {
8671
"ControlValue": 205
@@ -91,12 +76,7 @@
9176
"ControlValue": 193
9277
},
9378
"colour": {
94-
"ColourValue": [
95-
0,
96-
0,
97-
0,
98-
0
99-
]
79+
"ColourValue": [0, 0, 0, 0]
10080
},
10181
"tilt": {
10282
"ControlValue": 150
@@ -115,12 +95,7 @@
11595
"ControlValue": 255
11696
},
11797
"colour": {
118-
"ColourValue": [
119-
237,
120-
255,
121-
0,
122-
255
123-
]
98+
"ColourValue": [237, 255, 0, 255]
12499
},
125100
"pan": {
126101
"ControlValue": 0
@@ -137,25 +112,15 @@
137112
"ControlValue": 150
138113
},
139114
"colour": {
140-
"ColourValue": [
141-
255,
142-
0,
143-
0,
144-
255
145-
]
115+
"ColourValue": [255, 0, 0, 255]
146116
},
147117
"zoom": {
148118
"ControlValue": 255
149119
}
150120
},
151121
"Hex West": {
152122
"colour": {
153-
"ColourValue": [
154-
0,
155-
255,
156-
87,
157-
255
158-
]
123+
"ColourValue": [0, 255, 87, 255]
159124
},
160125
"pan": {
161126
"ControlValue": 0
@@ -169,12 +134,7 @@
169134
},
170135
"Hero North": {
171136
"colour": {
172-
"ColourValue": [
173-
37,
174-
0,
175-
243,
176-
255
177-
]
137+
"ColourValue": [37, 0, 243, 255]
178138
},
179139
"tilt": {
180140
"ControlValue": 127
@@ -189,4 +149,4 @@
189149
}
190150
}
191151
]
192-
}
152+
}

src/model.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Model {
178178
channel: _,
179179
velocity: _,
180180
} = note;
181-
let start_note = 48;
181+
let start_note = self.project.midi_config.note_start;
182182
let index = note - start_note;
183183
debug!("Note {} => macro group index {}", note, index);
184184
self.selected_macro_group_index = index as usize;
@@ -191,21 +191,11 @@ impl Model {
191191
value,
192192
} = cc;
193193

194-
// let active_macros = self
195-
// .project
196-
// .fixtures
197-
// .iter()
198-
// .map(|fc| {
199-
// if let Some(fixture) = &fc.fixture {
200-
// let macros = fixture.modes[0].macros.clone();
201-
// return Some((fc.clone(), macros));
202-
// } else {
203-
// return None;
204-
// }
205-
// })
206-
// .filter_map(|x| x);
207-
208-
let controller_start = 48;
194+
let controller_start = self.project.midi_config.controller_start;
195+
196+
if controller < controller_start {
197+
return;
198+
}
209199

210200
for (i, fixture) in self.project.fixtures.iter_mut().enumerate() {
211201
if self.selected_macro_group_index as usize == i {

src/project.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ use serde::{Deserialize, Serialize};
77
use crate::animation::Animation;
88

99
#[derive(Serialize, Deserialize, Clone)]
10+
#[serde(rename_all = "camelCase")]
1011
pub struct Project {
1112
pub fixtures: Vec<FixtureInstance>,
1213
pub scenes: Vec<Scene>,
14+
#[serde(default)]
15+
pub midi_config: MidiConfig,
16+
}
17+
18+
#[derive(Serialize, Deserialize, Clone)]
19+
#[serde(rename_all = "camelCase")]
20+
pub struct MidiConfig {
21+
/// Which controller number counts as the first, i.e. macro index 0
22+
pub controller_start: u8,
23+
/// Which note count as the first, i.e. fixture index 0
24+
pub note_start: u8,
25+
}
26+
27+
impl Default for MidiConfig {
28+
fn default() -> Self {
29+
MidiConfig {
30+
controller_start: 48,
31+
note_start: 49,
32+
}
33+
}
1334
}
1435

1536
#[derive(Serialize, Deserialize, Clone)]
@@ -159,6 +180,7 @@ impl Project {
159180
Project {
160181
fixtures: Vec::new(),
161182
scenes: Vec::new(),
183+
midi_config: MidiConfig::default(),
162184
}
163185
}
164186

0 commit comments

Comments
 (0)