git ssb

0+

dinoworm 🐛 / metronome



Commit 3ec707eee442688f2cf820a4336c7e69b3703ec0

show the beats

Michael Williams committed on 5/13/2018, 10:04:39 AM
Parent: de37e989827890621e4dbd2d5a5493b416130606

Files changed

src/clock.rschanged
src/interface.rschanged
src/clock.rsView
@@ -18,14 +18,16 @@
1818 static NANOS_PER_SECOND: u64 = 1_000_000_000;
1919 static BEATS_PER_MINUTE: u64 = 60;
2020 static DEFAULT_TICKS_PER_BEAT: u64 = 16;
2121 static DEFAULT_BEATS_PER_BAR: u64 = 4;
22 +static DEFAULT_BARS_PER_LOOP: u64 = 4;
2223
2324 #[derive(Clone, Copy, Debug, Hash)]
2425 pub struct ClockSignature {
2526 pub nanos_per_beat: u64, // tempo
2627 pub ticks_per_beat: u64, // meter
27- pub beats_per_bar: u64 // meter
28 + pub beats_per_bar: u64, // meter
29 + pub bars_per_loop: u64,
2830 }
2931
3032 impl ClockSignature {
3133 pub fn new (beats_per_minute: f64) -> Self {
@@ -35,9 +37,10 @@
3537
3638 Self {
3739 nanos_per_beat: nanos_per_beat as u64,
3840 ticks_per_beat: DEFAULT_TICKS_PER_BEAT,
39- beats_per_bar: DEFAULT_BEATS_PER_BAR
41 + beats_per_bar: DEFAULT_BEATS_PER_BAR,
42 + bars_per_loop: DEFAULT_BARS_PER_LOOP,
4043 }
4144 }
4245
4346 pub fn to_beats_per_minute (&self) -> f64 {
@@ -60,17 +63,17 @@
6063 self.nanos_per_beat() * self.beats_per_bar
6164 }
6265
6366 pub fn nanos_to_ticks (&self, nanos: Nanos) -> u64 {
64- (nanos / self.nanos_per_tick()) as u64
67 + (nanos / self.nanos_per_tick()) % self.ticks_per_beat
6568 }
6669
6770 pub fn nanos_to_beats (&self, nanos: Nanos) -> u64 {
68- (nanos / self.nanos_per_beat()) as u64
71 + (nanos / self.nanos_per_beat()) % self.beats_per_bar
6972 }
7073
7174 pub fn nanos_to_bars (&self, nanos: Nanos) -> u64 {
72- (nanos / self.nanos_per_bar()) as u64
75 + nanos / self.nanos_per_bar() % self.bars_per_loop
7376 }
7477 }
7578
7679 #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
@@ -86,9 +89,11 @@
8689 Self {
8790 nanos,
8891 ticks: signature.nanos_to_ticks(nanos),
8992 beats: signature.nanos_to_beats(nanos),
90- bars: signature.nanos_to_bars(nanos)
93 + bars: signature.nanos_to_bars(nanos),
94 + // ticks_til_beat: signature.ticks_til_beat(nanos),
95 + // beats_til_bar: signature.beats_til_bar(nanos)
9196 }
9297 }
9398 }
9499
src/interface.rsView
@@ -71,11 +71,15 @@
7171 match interface_message {
7272 InterfaceMessage::Time(time) => {
7373 ncurses::clear();
7474 ncurses::mv(0, 0);
75 + if time.ticks == 0 {
76 + ncurses::printw("BEAT");
77 + }
78 + ncurses::printw("\n");
7579 print_time(time);
7680 print_signature(signature);
77- }
81 + },
7882 InterfaceMessage::Signature(signature) => {
7983 }
8084 }
8185
@@ -90,13 +94,13 @@
9094 pub fn print_time (time: clock::ClockTime) {
9195 ncurses::printw("nanos: ");
9296 ncurses::printw(format!("{}\n", time.nanos).as_ref());
9397 ncurses::printw("ticks: ");
94- ncurses::printw(format!("{}\n", time.ticks).as_ref());
98 + ncurses::printw(format!("{}\n", time.ticks + 1).as_ref());
9599 ncurses::printw("beats: ");
96- ncurses::printw(format!("{}\n", time.beats).as_ref());
100 + ncurses::printw(format!("{}\n", time.beats + 1).as_ref());
97101 ncurses::printw("bars: ");
98- ncurses::printw(format!("{}\n", time.bars).as_ref());
102 + ncurses::printw(format!("{}\n", time.bars + 1).as_ref());
99103 }
100104
101105 pub fn print_signature (signature: clock::ClockSignature) {
102106 ncurses::printw("beats per minute: ");
@@ -104,8 +108,10 @@
104108 ncurses::printw("ticks per beat: ");
105109 ncurses::printw(format!("{}\n", signature.ticks_per_beat).as_ref());
106110 ncurses::printw("beats per bar: ");
107111 ncurses::printw(format!("{}\n", signature.beats_per_bar).as_ref());
112 + ncurses::printw("bars per loop: ");
113 + ncurses::printw(format!("{}\n", signature.bars_per_loop).as_ref());
108114 }
109115
110116 #[derive(Clone, Copy, Debug, Hash)]
111117 pub enum InterfaceMessage {

Built with git-ssb-web