From 50da21ff9e17bb07cb60064cfc3be67975e255af Mon Sep 17 00:00:00 2001 From: Denis Redozubov Date: Wed, 28 Jun 2023 16:01:34 +0400 Subject: [PATCH] Fix various warnings --- README.MD | 4 +++- src/bin/main.rs | 2 +- src/dsl/dsl.rs | 4 +++- src/midi/core.rs | 23 +++++++++++++++-------- src/midi/time.rs | 15 +++++---------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/README.MD b/README.MD index 5b54ec7..604cc1d 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,8 @@ # Poly -Polyrhythmically-inclinded drum generator. +Poly is a command-line assistant designed to generate MIDI file from the description of drum parts. It provides a convenient way to input a DSL (Domain-Specific Language) in the command line, then it calculates when the drum parts will converge together, making it easy to compose polyrhythimic parts with frequent shifts over the bar lines. Additionally, it has the capability to generate a bass MIDI track that follows the kick drum. + +Poly is specifically designed to assist musicians and composers working in genres such as modern progressive rock, metal, djent, fusion, and Indian Carnatic music. It aims to simplify the process of creating complex polyrhythmic drum patterns, enabling users to focus on the creative aspects of their compositions. # Motivation diff --git a/src/bin/main.rs b/src/bin/main.rs index f309f00..8769ab5 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::process::exit; use std::str::FromStr; -use poly::dsl::dsl::{self, flatten_groups, KnownLength}; +use poly::dsl::dsl; use poly::midi::core::{create_smf, DrumPart}; use poly::midi::time::TimeSignature; diff --git a/src/dsl/dsl.rs b/src/dsl/dsl.rs index 4a2ebc1..38243c6 100644 --- a/src/dsl/dsl.rs +++ b/src/dsl/dsl.rs @@ -209,6 +209,7 @@ pub enum Note { Rest, } +#[allow(unused_imports)] use Note::*; #[allow(dead_code)] @@ -293,6 +294,7 @@ pub enum GroupOrNote { SingleNote(Note), } +#[allow(unused_imports)] use GroupOrNote::*; /// There are two useful instantiations of this type: @@ -355,7 +357,7 @@ impl KnownLength for Group { fn to_128th(&self) -> u32 { let mut acc = 0; let note_length = self.length.to_128th(); - for group in self.notes.iter() { + for _ in self.notes.iter() { acc += note_length; } acc diff --git a/src/midi/core.rs b/src/midi/core.rs index ad16ee4..9f4283b 100644 --- a/src/midi/core.rs +++ b/src/midi/core.rs @@ -3,20 +3,20 @@ use std::cmp::Ordering; use std::cmp::Ordering::*; use std::collections::BTreeMap; use std::iter::Peekable; -use std::ops::{Add, Mul, Sub}; -use std::str::FromStr; use midly::{ - num::u24, num::u28, num::u4, num::u7, Header, MidiMessage, Smf, Track, TrackEventKind, + num::u24, num::u28, num::u4, num::u7, Header, MidiMessage, Smf, TrackEventKind, }; use midly::{MetaMessage, TrackEvent}; use crate::dsl::dsl::{ - flatten_group, group_or_delimited_group, groups, BasicLength, Group, GroupOrNote, Groups, - KnownLength, Length, ModdedLength, Note, Times, SIXTEENTH, EIGHTH, + BasicLength, Group, GroupOrNote, Groups, + KnownLength, Length, ModdedLength, Note, Times }; use crate::midi::time::TimeSignature; +#[allow(unused_imports)] use GroupOrNote::*; +#[allow(unused_imports)] use Note::*; use Part::*; use DrumPart::*; @@ -93,6 +93,7 @@ pub enum DrumPart { CrashCymbal } +#[allow(unused_imports)] use DrumPart::*; trait ToMidi { @@ -441,7 +442,7 @@ fn group_to_event_grid( Group { notes, length, - times, + .. }: &Group, part: Part, start: &Tick, @@ -565,6 +566,7 @@ pub(crate) struct EventIterator { hihat: Peekable>>, crash: Peekable>>, time_signature: TimeSignature, + bars: u32 } impl EventIterator { @@ -574,6 +576,7 @@ impl EventIterator { hihat_grid: EventGrid, crash_grid: EventGrid, time_signature: TimeSignature, + bars: u32 ) -> EventIterator { let event_iterator = EventIterator { kick: kick_grid.into_iter().peekable(), @@ -581,6 +584,7 @@ impl EventIterator { hihat: hihat_grid.into_iter().peekable(), crash: crash_grid.into_iter().peekable(), time_signature, + bars }; event_iterator } @@ -644,7 +648,8 @@ fn test_event_iterator_impl() { snare1.clone(), empty.clone(), empty.clone(), - TimeSignature::from_str("4/4").unwrap() + TimeSignature::from_str("4/4").unwrap(), + 1 ) .into_iter() .collect::>>(), @@ -674,7 +679,8 @@ fn test_event_iterator_impl() { empty.clone(), empty.clone(), empty.clone(), - TimeSignature::from_str("4/4").unwrap() + TimeSignature::from_str("4/4").unwrap(), + 1 ) .into_iter() .collect::>>(), @@ -739,6 +745,7 @@ fn merge_into_iterator( concat_grid(hihat_grid, Times(hihat_repeats as u16)), concat_grid(crash_grid, Times(crash_repeats as u16)), time_signature, + converges_over_bars ) } diff --git a/src/midi/time.rs b/src/midi/time.rs index 2d9dc17..bf31d03 100644 --- a/src/midi/time.rs +++ b/src/midi/time.rs @@ -1,10 +1,12 @@ extern crate derive_more; -use std::{cmp::Ordering, str::FromStr}; +use std::{str::FromStr}; -use crate::dsl::dsl::{BasicLength, Group, GroupOrNote, KnownLength, Note, Times, EIGHTH, FOURTH}; +use crate::dsl::dsl::{BasicLength, GroupOrNote, KnownLength, Note}; use BasicLength::*; +#[allow(unused_imports)] use Note::*; +#[allow(unused_imports)] use GroupOrNote::*; @@ -15,13 +17,6 @@ pub struct TimeSignature { } impl TimeSignature { - pub(crate) fn new(numerator: u8, denominator: BasicLength) -> Self { - Self { - numerator, - denominator, - } - } - pub(crate) fn to_midi(&self) -> (u8, u8) { let denominator = match self.denominator { Whole => 0, // FIXME: should it be an error? @@ -51,7 +46,7 @@ impl FromStr for TimeSignature { match BasicLength::from_str(d) { Ok(denominator) => match u8::from_str(numerator_str) { Ok(numerator) => Ok(TimeSignature { numerator, denominator }), - Err(e) => Err(format!("Can't parse time signature numerator: {}", s)), + Err(_) => Err(format!("Can't parse time signature numerator: {}", s)), } , Err(e) => Err(e), }