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 # 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 # Motivation

View file

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::process::exit; use std::process::exit;
use std::str::FromStr; 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::core::{create_smf, DrumPart};
use poly::midi::time::TimeSignature; use poly::midi::time::TimeSignature;

View file

@ -209,6 +209,7 @@ pub enum Note {
Rest, Rest,
} }
#[allow(unused_imports)]
use Note::*; use Note::*;
#[allow(dead_code)] #[allow(dead_code)]
@ -293,6 +294,7 @@ pub enum GroupOrNote<T> {
SingleNote(Note), SingleNote(Note),
} }
#[allow(unused_imports)]
use GroupOrNote::*; use GroupOrNote::*;
/// There are two useful instantiations of this type: /// There are two useful instantiations of this type:
@ -355,7 +357,7 @@ impl KnownLength for Group<Note, ()> {
fn to_128th(&self) -> u32 { fn to_128th(&self) -> u32 {
let mut acc = 0; let mut acc = 0;
let note_length = self.length.to_128th(); let note_length = self.length.to_128th();
for group in self.notes.iter() { for _ in self.notes.iter() {
acc += note_length; acc += note_length;
} }
acc acc

View file

@ -3,20 +3,20 @@ use std::cmp::Ordering;
use std::cmp::Ordering::*; use std::cmp::Ordering::*;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::iter::Peekable; use std::iter::Peekable;
use std::ops::{Add, Mul, Sub};
use std::str::FromStr;
use midly::{ 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 midly::{MetaMessage, TrackEvent};
use crate::dsl::dsl::{ use crate::dsl::dsl::{
flatten_group, group_or_delimited_group, groups, BasicLength, Group, GroupOrNote, Groups, BasicLength, Group, GroupOrNote, Groups,
KnownLength, Length, ModdedLength, Note, Times, SIXTEENTH, EIGHTH, KnownLength, Length, ModdedLength, Note, Times
}; };
use crate::midi::time::TimeSignature; use crate::midi::time::TimeSignature;
#[allow(unused_imports)]
use GroupOrNote::*; use GroupOrNote::*;
#[allow(unused_imports)]
use Note::*; use Note::*;
use Part::*; use Part::*;
use DrumPart::*; use DrumPart::*;
@ -93,6 +93,7 @@ pub enum DrumPart {
CrashCymbal CrashCymbal
} }
#[allow(unused_imports)]
use DrumPart::*; use DrumPart::*;
trait ToMidi { trait ToMidi {
@ -441,7 +442,7 @@ fn group_to_event_grid(
Group { Group {
notes, notes,
length, length,
times, ..
}: &Group<Note, ()>, }: &Group<Note, ()>,
part: Part, part: Part,
start: &Tick, start: &Tick,
@ -565,6 +566,7 @@ pub(crate) struct EventIterator {
hihat: Peekable<std::vec::IntoIter<Event<Tick>>>, hihat: Peekable<std::vec::IntoIter<Event<Tick>>>,
crash: Peekable<std::vec::IntoIter<Event<Tick>>>, crash: Peekable<std::vec::IntoIter<Event<Tick>>>,
time_signature: TimeSignature, time_signature: TimeSignature,
bars: u32
} }
impl EventIterator { impl EventIterator {
@ -574,6 +576,7 @@ impl EventIterator {
hihat_grid: EventGrid<Tick>, hihat_grid: EventGrid<Tick>,
crash_grid: EventGrid<Tick>, crash_grid: EventGrid<Tick>,
time_signature: TimeSignature, time_signature: TimeSignature,
bars: u32
) -> EventIterator { ) -> EventIterator {
let event_iterator = EventIterator { let event_iterator = EventIterator {
kick: kick_grid.into_iter().peekable(), kick: kick_grid.into_iter().peekable(),
@ -581,6 +584,7 @@ impl EventIterator {
hihat: hihat_grid.into_iter().peekable(), hihat: hihat_grid.into_iter().peekable(),
crash: crash_grid.into_iter().peekable(), crash: crash_grid.into_iter().peekable(),
time_signature, time_signature,
bars
}; };
event_iterator event_iterator
} }
@ -644,7 +648,8 @@ fn test_event_iterator_impl() {
snare1.clone(), snare1.clone(),
empty.clone(), empty.clone(),
empty.clone(), empty.clone(),
TimeSignature::from_str("4/4").unwrap() TimeSignature::from_str("4/4").unwrap(),
1
) )
.into_iter() .into_iter()
.collect::<Vec<Event<Tick>>>(), .collect::<Vec<Event<Tick>>>(),
@ -674,7 +679,8 @@ fn test_event_iterator_impl() {
empty.clone(), empty.clone(),
empty.clone(), empty.clone(),
empty.clone(), empty.clone(),
TimeSignature::from_str("4/4").unwrap() TimeSignature::from_str("4/4").unwrap(),
1
) )
.into_iter() .into_iter()
.collect::<Vec<Event<Tick>>>(), .collect::<Vec<Event<Tick>>>(),
@ -739,6 +745,7 @@ fn merge_into_iterator(
concat_grid(hihat_grid, Times(hihat_repeats as u16)), concat_grid(hihat_grid, Times(hihat_repeats as u16)),
concat_grid(crash_grid, Times(crash_repeats as u16)), concat_grid(crash_grid, Times(crash_repeats as u16)),
time_signature, time_signature,
converges_over_bars
) )
} }

View file

@ -1,10 +1,12 @@
extern crate derive_more; 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::*; use BasicLength::*;
#[allow(unused_imports)]
use Note::*; use Note::*;
#[allow(unused_imports)]
use GroupOrNote::*; use GroupOrNote::*;
@ -15,13 +17,6 @@ pub struct TimeSignature {
} }
impl TimeSignature { impl TimeSignature {
pub(crate) fn new(numerator: u8, denominator: BasicLength) -> Self {
Self {
numerator,
denominator,
}
}
pub(crate) fn to_midi(&self) -> (u8, u8) { pub(crate) fn to_midi(&self) -> (u8, u8) {
let denominator = match self.denominator { let denominator = match self.denominator {
Whole => 0, // FIXME: should it be an error? Whole => 0, // FIXME: should it be an error?
@ -51,7 +46,7 @@ impl FromStr for TimeSignature {
match BasicLength::from_str(d) { match BasicLength::from_str(d) {
Ok(denominator) => match u8::from_str(numerator_str) { Ok(denominator) => match u8::from_str(numerator_str) {
Ok(numerator) => Ok(TimeSignature { numerator, denominator }), 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), Err(e) => Err(e),
} }