Fix various warnings

This commit is contained in:
Denis Redozubov 2023-06-28 16:01:34 +04:00
parent b60408379a
commit 50da21ff9e
5 changed files with 27 additions and 21 deletions

View file

@ -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

View file

@ -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;

View file

@ -209,6 +209,7 @@ pub enum Note {
Rest,
}
#[allow(unused_imports)]
use Note::*;
#[allow(dead_code)]
@ -293,6 +294,7 @@ pub enum GroupOrNote<T> {
SingleNote(Note),
}
#[allow(unused_imports)]
use GroupOrNote::*;
/// There are two useful instantiations of this type:
@ -355,7 +357,7 @@ impl KnownLength for Group<Note, ()> {
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

View file

@ -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<Note, ()>,
part: Part,
start: &Tick,
@ -565,6 +566,7 @@ pub(crate) struct EventIterator {
hihat: Peekable<std::vec::IntoIter<Event<Tick>>>,
crash: Peekable<std::vec::IntoIter<Event<Tick>>>,
time_signature: TimeSignature,
bars: u32
}
impl EventIterator {
@ -574,6 +576,7 @@ impl EventIterator {
hihat_grid: EventGrid<Tick>,
crash_grid: EventGrid<Tick>,
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::<Vec<Event<Tick>>>(),
@ -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::<Vec<Event<Tick>>>(),
@ -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
)
}

View file

@ -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),
}