aboutsummaryrefslogtreecommitdiff
path: root/src/note.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-03-06 23:18:13 +0000
committerFuwn <[email protected]>2023-03-06 23:18:13 +0000
commit6dc2f6f616dea520a6b6c52aec5a7308928d7d5b (patch)
tree00adfc06cf5d6f4f550ff57e07f74a3f19af4980 /src/note.rs
downloadguitar-6dc2f6f616dea520a6b6c52aec5a7308928d7d5b.tar.xz
guitar-6dc2f6f616dea520a6b6c52aec5a7308928d7d5b.zip
feat: core featuresv0.1.1
Diffstat (limited to 'src/note.rs')
-rw-r--r--src/note.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/note.rs b/src/note.rs
new file mode 100644
index 0000000..053ce15
--- /dev/null
+++ b/src/note.rs
@@ -0,0 +1,62 @@
+// This file is part of Guitar <https://github.com/Fuwn/guitar>.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+use crate::{pitch::Pitch, unit::Octave};
+
+/// A note which only keeps track of its frequency, octave, and name; enables
+/// for a more flexible note system; including conversions, enharmonics, and
+/// more.
+///
+/// # Examples
+///
+/// ```rust
+/// let _ = guitar::Note::new("A", 4);
+/// ```
+#[derive(Debug, Clone, PartialEq, PartialOrd)]
+pub struct Note {
+ pitch: Pitch,
+}
+
+impl Note {
+ /// Creates a new, specific [`Note`] given a note's name, octave, and
+ /// duration.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// let _ = guitar::Note::new("A", 4);
+ /// ```
+ #[must_use]
+ pub fn new(pitch: &str, octave: Octave) -> Self {
+ let pitch = Pitch::new(pitch, octave);
+
+ Self::new_from_pitch(pitch)
+ }
+
+ /// Creates a new, specific [`Note`] given a frequency and a [`Pitch`].
+ ///
+ /// This is an internal command which is made obsolete by the other,
+ /// public-acing `new_from_*` methods.
+ #[must_use]
+ pub const fn new_from_pitch(pitch: Pitch) -> Self { Self { pitch } }
+
+ /// Returns the [`Pitch`] of the [`Note`] for further manipulation.
+ pub fn pitch(&mut self) -> &Pitch { &self.pitch }
+
+ /// Returns the [`Pitch`] of the [`Note`] for further manipulation.
+ pub fn pitch_mut(&mut self) -> &mut Pitch { &mut self.pitch }
+}