Skip to content

Commit 90eb915

Browse files
committed
Gros ménage
1 parent 70d30fe commit 90eb915

14 files changed

Lines changed: 528 additions & 552 deletions

File tree

core/src/error.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::VecDeque;
1+
use std::{cell::RefCell, collections::VecDeque};
22

33
use serde::{Deserialize, Serialize};
44

@@ -12,12 +12,23 @@ pub struct SovaError {
1212
pub text: String
1313
}
1414

15+
#[derive(Debug, Default)]
1516
pub struct ErrorQueue {
16-
pub buffer: VecDeque<SovaError>
17+
buffer: RefCell<VecDeque<SovaError>>
1718
}
1819

1920
impl ErrorQueue {
21+
pub fn throw(&self, err: SovaError) {
22+
self.buffer.borrow_mut().push_back(err);
23+
}
24+
25+
pub fn poll(&self) -> Option<SovaError> {
26+
self.buffer.borrow_mut().pop_front()
27+
}
2028

29+
pub fn clear(&self) {
30+
self.buffer.borrow_mut().clear();
31+
}
2132
}
2233

2334
impl SovaError {

core/src/protocol/audio_engine_proxy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ impl AudioEnginePayload {
2727
let addr = addr.parse::<i64>();
2828
match args {
2929
VariableValue::Map(mut map) => {
30-
if !map.contains_key("dur") {
31-
map.insert("dur".to_owned(), dur_s.into());
30+
if !map.contains_key("duration") {
31+
map.insert("duration".to_owned(), dur_s.into());
3232
}
3333
if let Ok(a) = addr {
3434
map.insert("voice".to_owned(), a.into());
@@ -41,8 +41,8 @@ impl AudioEnginePayload {
4141
}
4242
VariableValue::Str(s) => {
4343
let mut map = HashMap::new();
44-
map.insert("s".to_owned(), s.into());
45-
map.insert("dur".to_owned(), dur_s.into());
44+
map.insert("sound".to_owned(), s.into());
45+
map.insert("duration".to_owned(), dur_s.into());
4646
if let Ok(a) = addr {
4747
map.insert("voice".to_owned(), a.into());
4848
}

core/src/protocol/osc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::net::{SocketAddr, UdpSocket};
55
use crate::clock::TimeSpan;
66
use crate::vm::variable::VariableValue;
77
use crate::protocol::error::ProtocolError;
8-
use crate::util::decimal_operations::float64_from_decimal;
98

109
mod message;
1110
pub use message::*;
@@ -64,8 +63,8 @@ impl OSCOut {
6463
match arg {
6564
VariableValue::Integer(i) => Ok(OscType::Int(i as i32)),
6665
VariableValue::Float(f) => Ok(OscType::Float(f as f32)),
67-
VariableValue::Decimal(sign, num, den) => {
68-
let f = float64_from_decimal(sign, num, den);
66+
VariableValue::Decimal(d) => {
67+
let f = f64::from(d);
6968
Ok(OscType::Float(f as f32))
7069
}
7170
VariableValue::Str(s) => Ok(OscType::String(s)),

core/src/protocol/osc/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ impl OSCMessage {
159159
VariableValue::Map(map) => map,
160160
value => {
161161
let mut map = HashMap::new();
162-
map.insert("s".to_owned(), value);
162+
map.insert("sound".to_owned(), value);
163163
map
164164
}
165165
};
166-
if args.contains_key("s") && !args.contains_key("sustain") {
166+
if (args.contains_key("s") || args.contains_key("sound")) && !args.contains_key("sustain") {
167167
let dur_s = (duration as f64) / 1_000_000.0;
168168
args.insert("sustain".to_owned(), dur_s.into());
169169
}

core/src/schedule.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
use crate::{
2-
clock::{Clock, ClockServer, NEVER, SyncTime},
3-
device_map::DeviceMap,
4-
log_println,
5-
protocol::TimedMessage,
6-
scene::Scene,
7-
schedule::{playback::PlaybackManager, scheduler_actions::ActionProcessor},
8-
vm::{LanguageCenter, PartialContext, variable::VariableStore},
9-
world::ACTIVE_WAITING_SWITCH_MICROS,
2+
clock::{Clock, ClockServer, NEVER, SyncTime}, device_map::DeviceMap, error::ErrorQueue, log_println, protocol::TimedMessage, scene::Scene, schedule::{playback::PlaybackManager, scheduler_actions::ActionProcessor}, vm::{LanguageCenter, PartialContext, variable::VariableStore}, world::ACTIVE_WAITING_SWITCH_MICROS
103
};
114

125
use crossbeam_channel::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
@@ -43,6 +36,8 @@ pub struct Scheduler {
4336
playback_manager: PlaybackManager,
4437
shutdown_requested: bool,
4538

39+
error_queue: ErrorQueue,
40+
4641
scene_structure: Vec<Vec<f64>>,
4742
}
4843

@@ -102,6 +97,7 @@ impl Scheduler {
10297
playback_manager: PlaybackManager::default(),
10398
shutdown_requested: false,
10499
scene_structure: Vec::new(),
100+
error_queue: Default::default()
105101
}
106102
}
107103

@@ -232,6 +228,7 @@ impl Scheduler {
232228
partial.clock = Some(&self.clock);
233229
partial.device_map = Some(&self.devices);
234230
partial.structure = Some(&self.scene_structure);
231+
partial.errors = Some(&self.error_queue);
235232
let (events, wait) = self.scene.update_executions(partial);
236233
for event in events {
237234
for msg in self.devices.map_event(event, date, &self.clock) {
@@ -306,6 +303,10 @@ impl Scheduler {
306303

307304
let next_exec_delay = self.process_executions(date);
308305

306+
while let Some(error) = self.error_queue.poll() {
307+
let _ = self.update_notifier.send(SovaNotification::Error(error));
308+
}
309+
309310
// Check if global variables changed and send notification
310311
let one_letter_vars: VariableStore = self.scene.vars.one_letter_vars().collect();
311312
if one_letter_vars != one_letters_before {

core/src/util/decimal_operations/decimal.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::{cmp::Ordering, fmt::Display, ops::{Add, Div, Mul, Neg, Rem, Sub}};
22

3+
use serde::{Deserialize, Serialize};
4+
35
use crate::util::decimal_operations::{add_decimal, decimal_from_float64, div_decimal, eq_decimal, float64_from_decimal, lt_decimal, mul_decimal, rem_decimal, simplify_decimal, string_from_decimal, sub_decimal};
46

5-
#[derive(Debug, Clone, Copy)]
7+
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
68
pub struct Decimal {
79
pub sign: i8,
810
pub num: u64,
@@ -19,6 +21,9 @@ impl Decimal {
1921
pub fn zero() -> Self {
2022
Self { sign: 1, num: 0, den: 1 }
2123
}
24+
pub fn is_zero(&self) -> bool {
25+
self.num == 0
26+
}
2227
}
2328

2429
impl Default for Decimal {
@@ -146,6 +151,12 @@ impl From<Decimal> for f64 {
146151
}
147152
}
148153

154+
impl From<Decimal> for i64 {
155+
fn from(value: Decimal) -> Self {
156+
(value.sign as i64) * (value.den / value.num) as i64
157+
}
158+
}
159+
149160
impl From<(i8, u64, u64)> for Decimal {
150161
fn from(value: (i8, u64, u64)) -> Self {
151162
Decimal {

core/src/util/music/scale.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ impl Scale {
8383

8484
impl Default for Scale {
8585
fn default() -> Self {
86-
Self::chromatic(NOTE_C, 4)
86+
Self::major(NOTE_C, 4)
8787
}
8888
}

0 commit comments

Comments
 (0)