Commit 3ec707eee442688f2cf820a4336c7e69b3703ec0
show the beats
Michael Williams committed on 5/13/2018, 10:04:39 AMParent: de37e989827890621e4dbd2d5a5493b416130606
Files changed
src/clock.rs | changed |
src/interface.rs | changed |
src/clock.rs | ||
---|---|---|
@@ -18,14 +18,16 @@ | ||
18 | 18 … | static NANOS_PER_SECOND: u64 = 1_000_000_000; |
19 | 19 … | static BEATS_PER_MINUTE: u64 = 60; |
20 | 20 … | static DEFAULT_TICKS_PER_BEAT: u64 = 16; |
21 | 21 … | static DEFAULT_BEATS_PER_BAR: u64 = 4; |
22 … | +static DEFAULT_BARS_PER_LOOP: u64 = 4; | |
22 | 23 … | |
23 | 24 … | |
24 | 25 … | pub struct ClockSignature { |
25 | 26 … | pub nanos_per_beat: u64, // tempo |
26 | 27 … | 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, | |
28 | 30 … | } |
29 | 31 … | |
30 | 32 … | impl ClockSignature { |
31 | 33 … | pub fn new (beats_per_minute: f64) -> Self { |
@@ -35,9 +37,10 @@ | ||
35 | 37 … | |
36 | 38 … | Self { |
37 | 39 … | nanos_per_beat: nanos_per_beat as u64, |
38 | 40 … | 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, | |
40 | 43 … | } |
41 | 44 … | } |
42 | 45 … | |
43 | 46 … | pub fn to_beats_per_minute (&self) -> f64 { |
@@ -60,17 +63,17 @@ | ||
60 | 63 … | self.nanos_per_beat() * self.beats_per_bar |
61 | 64 … | } |
62 | 65 … | |
63 | 66 … | 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 | |
65 | 68 … | } |
66 | 69 … | |
67 | 70 … | 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 | |
69 | 72 … | } |
70 | 73 … | |
71 | 74 … | 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 | |
73 | 76 … | } |
74 | 77 … | } |
75 | 78 … | |
76 | 79 … | |
@@ -86,9 +89,11 @@ | ||
86 | 89 … | Self { |
87 | 90 … | nanos, |
88 | 91 … | ticks: signature.nanos_to_ticks(nanos), |
89 | 92 … | 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) | |
91 | 96 … | } |
92 | 97 … | } |
93 | 98 … | } |
94 | 99 … |
src/interface.rs | ||
---|---|---|
@@ -71,11 +71,15 @@ | ||
71 | 71 … | match interface_message { |
72 | 72 … | InterfaceMessage::Time(time) => { |
73 | 73 … | ncurses::clear(); |
74 | 74 … | ncurses::mv(0, 0); |
75 … | + if time.ticks == 0 { | |
76 … | + ncurses::printw("BEAT"); | |
77 … | + } | |
78 … | + ncurses::printw("\n"); | |
75 | 79 … | print_time(time); |
76 | 80 … | print_signature(signature); |
77 | - } | |
81 … | + }, | |
78 | 82 … | InterfaceMessage::Signature(signature) => { |
79 | 83 … | } |
80 | 84 … | } |
81 | 85 … | |
@@ -90,13 +94,13 @@ | ||
90 | 94 … | pub fn print_time (time: clock::ClockTime) { |
91 | 95 … | ncurses::printw("nanos: "); |
92 | 96 … | ncurses::printw(format!("{}\n", time.nanos).as_ref()); |
93 | 97 … | ncurses::printw("ticks: "); |
94 | - ncurses::printw(format!("{}\n", time.ticks).as_ref()); | |
98 … | + ncurses::printw(format!("{}\n", time.ticks + 1).as_ref()); | |
95 | 99 … | ncurses::printw("beats: "); |
96 | - ncurses::printw(format!("{}\n", time.beats).as_ref()); | |
100 … | + ncurses::printw(format!("{}\n", time.beats + 1).as_ref()); | |
97 | 101 … | ncurses::printw("bars: "); |
98 | - ncurses::printw(format!("{}\n", time.bars).as_ref()); | |
102 … | + ncurses::printw(format!("{}\n", time.bars + 1).as_ref()); | |
99 | 103 … | } |
100 | 104 … | |
101 | 105 … | pub fn print_signature (signature: clock::ClockSignature) { |
102 | 106 … | ncurses::printw("beats per minute: "); |
@@ -104,8 +108,10 @@ | ||
104 | 108 … | ncurses::printw("ticks per beat: "); |
105 | 109 … | ncurses::printw(format!("{}\n", signature.ticks_per_beat).as_ref()); |
106 | 110 … | ncurses::printw("beats per bar: "); |
107 | 111 … | 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()); | |
108 | 114 … | } |
109 | 115 … | |
110 | 116 … | |
111 | 117 … | pub enum InterfaceMessage { |
Built with git-ssb-web