|
1 | 1 | /// 12-tone equal temperament following the A440Hz convention |
2 | | -use caw_core::{Sig, SigT}; |
| 2 | +use caw_core::{Buf, ConstBuf, Sig, SigCtx, SigT}; |
3 | 3 |
|
4 | 4 | #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] |
5 | 5 | pub struct Octave(u8); |
@@ -220,8 +220,28 @@ where |
220 | 220 | } |
221 | 221 | } |
222 | 222 |
|
| 223 | +impl SigT for Note { |
| 224 | + type Item = Self; |
| 225 | + |
| 226 | + fn sample(&mut self, ctx: &SigCtx) -> impl Buf<Self::Item> { |
| 227 | + ConstBuf { |
| 228 | + value: *self, |
| 229 | + count: ctx.num_samples, |
| 230 | + } |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +/// Arbitrary default value to help when a temporary value must be set before updating a note by |
| 235 | +/// some other process, as signals cannot have undefined values. The default note is C4. |
| 236 | +impl Default for Note { |
| 237 | + fn default() -> Self { |
| 238 | + note::C4 |
| 239 | + } |
| 240 | +} |
| 241 | + |
223 | 242 | pub mod chord { |
224 | | - use super::{Note, NoteName, Octave}; |
| 243 | + use super::{Note, NoteName, Octave, note_name}; |
| 244 | + use caw_core::{Buf, ConstBuf, SigCtx, SigT}; |
225 | 245 | use smallvec::{SmallVec, smallvec}; |
226 | 246 |
|
227 | 247 | pub struct Notes(SmallVec<[Note; 4]>); |
@@ -424,7 +444,7 @@ pub mod chord { |
424 | 444 | } |
425 | 445 |
|
426 | 446 | impl Chord { |
427 | | - pub fn new(root: NoteName, typ: ChordType) -> Self { |
| 447 | + pub const fn new(root: NoteName, typ: ChordType) -> Self { |
428 | 448 | Self { |
429 | 449 | root, |
430 | 450 | typ, |
@@ -505,9 +525,28 @@ pub mod chord { |
505 | 525 | } |
506 | 526 | } |
507 | 527 |
|
508 | | - pub fn chord(root: NoteName, typ: ChordType) -> Chord { |
| 528 | + pub const fn chord(root: NoteName, typ: ChordType) -> Chord { |
509 | 529 | Chord::new(root, typ) |
510 | 530 | } |
| 531 | + |
| 532 | + impl SigT for Chord { |
| 533 | + type Item = Self; |
| 534 | + |
| 535 | + fn sample(&mut self, ctx: &SigCtx) -> impl Buf<Self::Item> { |
| 536 | + ConstBuf { |
| 537 | + value: *self, |
| 538 | + count: ctx.num_samples, |
| 539 | + } |
| 540 | + } |
| 541 | + } |
| 542 | + |
| 543 | + /// Arbitrary default value to help when a temporary value must be set before updating a note by |
| 544 | + /// some other process, as signals cannot have undefined values. The default chord is C major. |
| 545 | + impl Default for Chord { |
| 546 | + fn default() -> Self { |
| 547 | + chord(note_name::C, MAJOR) |
| 548 | + } |
| 549 | + } |
511 | 550 | } |
512 | 551 |
|
513 | 552 | impl Note { |
|
0 commit comments