From 75dc84aad4775ceedd4a066ffe63bcf013600600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lapointe?= <28580319+OmegaLarmor@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:05:03 -0500 Subject: [PATCH 1/5] More cleanup --- pydrumscore/__init__.py | 3 +- pydrumscore/core/api.py | 4 +- .../test/songs/bass_drum_permutations.py | 8 +-- .../songs/bass_drum_permutations_random.py | 11 ++-- pydrumscore/test/songs/flam_1b.py | 8 +-- pydrumscore/test/songs/ghost_1b.py | 6 +- .../test/songs/hihat_open_permutations.py | 8 +-- .../test/songs/song_accented_metadata.py | 4 +- .../test/songs/song_highway_to_hell.py | 58 +++++++++---------- pydrumscore/test/songs/song_money_beat.py | 4 +- .../test/songs/song_money_beat_accents.py | 6 +- pydrumscore/test/songs/song_rock_beat.py | 4 +- .../test/songs/song_rock_beat_wopen.py | 4 +- pydrumscore/test/songs/song_shuffle_beat.py | 4 +- pydrumscore/test/songs/song_silence.py | 4 +- pydrumscore/test/songs/song_template | 16 ----- pydrumscore/test/songs/song_tempo_change.py | 4 +- pydrumscore/test/songs/song_text.py | 4 +- pydrumscore/test/songs/song_uptown_funk.py | 28 ++++----- .../songs/time_eighth_note_denominator.py | 8 +-- 20 files changed, 90 insertions(+), 106 deletions(-) delete mode 100644 pydrumscore/test/songs/song_template diff --git a/pydrumscore/__init__.py b/pydrumscore/__init__.py index 10877c9..39d415a 100644 --- a/pydrumscore/__init__.py +++ b/pydrumscore/__init__.py @@ -4,7 +4,8 @@ import logging # Imports the entire API into the "pydrumscore" namespace -# TODO: Rethink this wildcard import (might be ok in the end) +# Note: This wildcard approach means the API needs to be maintained to not leak symbols +# The approach is similar to what is done in numpy, for example from pydrumscore.core.api import * # Init logger for all modules diff --git a/pydrumscore/core/api.py b/pydrumscore/core/api.py index 0c10373..cbd94c0 100644 --- a/pydrumscore/core/api.py +++ b/pydrumscore/core/api.py @@ -11,7 +11,7 @@ from fractions import Fraction -# Utilities # +# Utilities def note_range( start: float, stop: float, step: float, excl: Optional[List[float]] = None ) -> list: @@ -32,7 +32,7 @@ def note_range( :returns: list: Range of notes from 'start' to 'stop', separated by 'step' """ - # Note: Homemade equivalent of numpy 's 'arange' + # Note: Homemade equivalent of numpy's 'arange' res = [] v = start while v < stop and not math.isclose(v, stop): diff --git a/pydrumscore/test/songs/bass_drum_permutations.py b/pydrumscore/test/songs/bass_drum_permutations.py index 1eadcf1..407d7e0 100644 --- a/pydrumscore/test/songs/bass_drum_permutations.py +++ b/pydrumscore/test/songs/bass_drum_permutations.py @@ -1,18 +1,18 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import MONEY_BEAT -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Bass drum permutations", ) measures = [] -bd_perms = api.note_range(1, api.end(), 0.5) +bd_perms = pds.note_range(1, pds.end(), 0.5) for p in bd_perms: - m = api.Measure(MONEY_BEAT) + m = pds.Measure(MONEY_BEAT) if p not in m.bd: m.bd += [p] measures += m diff --git a/pydrumscore/test/songs/bass_drum_permutations_random.py b/pydrumscore/test/songs/bass_drum_permutations_random.py index 31ceb85..65b5ff9 100644 --- a/pydrumscore/test/songs/bass_drum_permutations_random.py +++ b/pydrumscore/test/songs/bass_drum_permutations_random.py @@ -2,20 +2,20 @@ import random -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import MONEY_BEAT -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Bass drum permutations, shuffled", ) measures = [] NUM_MEASURES = 13 -bd_perms = api.note_range(1, api.end(), 0.5) +bd_perms = pds.note_range(1, pds.end(), 0.5) for n in range(NUM_MEASURES): - m = api.Measure(MONEY_BEAT) + m = pds.Measure(MONEY_BEAT) r = random.randrange(0, len(bd_perms)) p = bd_perms[r] if p not in m.bd: @@ -23,14 +23,13 @@ measures += m measures += MONEY_BEAT - # if n != num_measures-1: measures[-1].has_line_break = True NUM_MEASURES_FULL_SHUFFLE = 10 for n in range(NUM_MEASURES_FULL_SHUFFLE): for _ in range(2): - m = api.Measure(MONEY_BEAT) + m = pds.Measure(MONEY_BEAT) m.no_repeat = True r = random.randrange(0, len(bd_perms)) while bd_perms[r] in m.bd: diff --git a/pydrumscore/test/songs/flam_1b.py b/pydrumscore/test/songs/flam_1b.py index 1d22843..a2cfce1 100644 --- a/pydrumscore/test/songs/flam_1b.py +++ b/pydrumscore/test/songs/flam_1b.py @@ -1,10 +1,10 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds -metadata = api.Metadata(workTitle="Flam_1b") +metadata = pds.Metadata(workTitle="Flam_1b") -# Fill up this array with api.Measure objects +# Fill up this array with Measure objects measures = [] -measures += api.Measure(fm=[1]) +measures += pds.Measure(fm=[1]) diff --git a/pydrumscore/test/songs/ghost_1b.py b/pydrumscore/test/songs/ghost_1b.py index efad642..6f0c513 100644 --- a/pydrumscore/test/songs/ghost_1b.py +++ b/pydrumscore/test/songs/ghost_1b.py @@ -1,9 +1,9 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds -metadata = api.Metadata(workTitle="Ghost_1b") +metadata = pds.Metadata(workTitle="Ghost_1b") # Fill up this array with api.Measure objects measures = [] -measures += api.Measure(sg=[1]) +measures += pds.Measure(sg=[1]) diff --git a/pydrumscore/test/songs/hihat_open_permutations.py b/pydrumscore/test/songs/hihat_open_permutations.py index 9f6843f..ee0026b 100644 --- a/pydrumscore/test/songs/hihat_open_permutations.py +++ b/pydrumscore/test/songs/hihat_open_permutations.py @@ -1,17 +1,17 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import MONEY_BEAT -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Hi-hat open permutations", ) measures = [] -hho_perms = api.note_range(1, api.end(), 0.5) +hho_perms = pds.note_range(1, pds.end(), 0.5) for p in hho_perms: - m = api.Measure(MONEY_BEAT) + m = pds.Measure(MONEY_BEAT) m.hh.remove(p) m.ho += [p] diff --git a/pydrumscore/test/songs/song_accented_metadata.py b/pydrumscore/test/songs/song_accented_metadata.py index 290fba9..463b396 100644 --- a/pydrumscore/test/songs/song_accented_metadata.py +++ b/pydrumscore/test/songs/song_accented_metadata.py @@ -1,8 +1,8 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import SILENCE -metadata = api.Metadata(workTitle="Rémy's Wonderful Song") +metadata = pds.Metadata(workTitle="Rémy's Wonderful Song") measures = [SILENCE] diff --git a/pydrumscore/test/songs/song_highway_to_hell.py b/pydrumscore/test/songs/song_highway_to_hell.py index d716506..032ef9d 100644 --- a/pydrumscore/test/songs/song_highway_to_hell.py +++ b/pydrumscore/test/songs/song_highway_to_hell.py @@ -1,21 +1,21 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import SILENCE, MONEY_BEAT, HIGHWAY_GROOVE, HIGHWAY_GROOVE_O -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Highway to Hell", ) measures = [] -api.set_time_sig("2/4") -first_two = api.Measure() +pds.set_time_sig("2/4") +first_two = pds.Measure() first_two.tempo = 10 -measures += api.Measure(first_two) +measures += pds.Measure(first_two) # Intro -api.set_time_sig("4/4") +pds.set_time_sig("4/4") for i in range(4): measures += SILENCE @@ -31,12 +31,12 @@ # My friends are gonna be there too buildup_section = [ - api.Measure( - sd=[1] + api.note_range(2, api.end(), 0.5), + pds.Measure( + sd=[1] + pds.note_range(2, pds.end(), 0.5), c1=[1], - ft=api.note_range(2, api.end(), 0.5), + ft=pds.note_range(2, pds.end(), 0.5), ), - api.Measure(sd=api.note_range(1, 4, 0.5) + [4], ft=api.note_range(1, 4, 0.5)), + pds.Measure(sd=pds.note_range(1, 4, 0.5) + [4], ft=pds.note_range(1, 4, 0.5)), ] measures += buildup_section @@ -44,7 +44,7 @@ # Chorus chorus_2b = [] chorus_2b += HIGHWAY_GROOVE_O -chorus_2b += api.Measure(sd=[2, 4], bd=[1, 3], ho=api.note_range(1, 3, 0.5), c1=[3, 4]) +chorus_2b += pds.Measure(sd=[2, 4], bd=[1, 3], ho=pds.note_range(1, 3, 0.5), c1=[3, 4]) chorus_section = [] for i in range(3): @@ -54,14 +54,14 @@ # Section before next verse 2 # TODO: Support for hh foot -measures += api.Measure( - sd=[2, 4, 4.5], bd=[1, 3], ho=api.note_range(1, 4, 0.5), c1=[4, 4.5] +measures += pds.Measure( + sd=[2, 4, 4.5], bd=[1, 3], ho=pds.note_range(1, 4, 0.5), c1=[4, 4.5] ) -measures += api.Measure(hh=api.note_range(1, api.end(), 1)) +measures += pds.Measure(hh=pds.note_range(1, pds.end(), 1)) -measures += api.Measure( - hh=api.note_range(1, api.end(), 1), +measures += pds.Measure( + hh=pds.note_range(1, pds.end(), 1), sd=[3.5], mt=[4], c1=[4.5], @@ -71,7 +71,7 @@ # Verse 2 (No stop sign) for i in range(15): - m = api.Measure(HIGHWAY_GROOVE) + m = pds.Measure(HIGHWAY_GROOVE) if i == 0: m.bd = m.bd[1:] @@ -89,35 +89,35 @@ measures += chorus_section # Section before guitar solo -measures += api.Measure( - ho=api.note_range(1, 4, 0.5), +measures += pds.Measure( + ho=pds.note_range(1, 4, 0.5), c1=[4] + [4.5], sd=[2, 4] + [4.5], bd=[1, 3], ) -measures += api.Measure(hh=api.note_range(1, api.end(), 1)) -measures += api.Measure(sd=[1, 2.5, 4], c1=[1, 2.5, 4], bd=[1.5, 2, 3, 3.5]) +measures += pds.Measure(hh=pds.note_range(1, pds.end(), 1)) +measures += pds.Measure(sd=[1, 2.5, 4], c1=[1, 2.5, 4], bd=[1.5, 2, 3, 3.5]) -measures += api.Measure(hh=api.note_range(1, api.end(), 1)) -measures += api.Measure(sd=[1, 2.5, 4], c1=[1, 2.5, 4], bd=[1.5, 2, 3, 3.5, 4.5]) -measures += api.Measure(sd=[1.5], fm=[3, 4], c1=[1.5], bd=[1, 2, 2.5]) +measures += pds.Measure(hh=pds.note_range(1, pds.end(), 1)) +measures += pds.Measure(sd=[1, 2.5, 4], c1=[1, 2.5, 4], bd=[1.5, 2, 3, 3.5, 4.5]) +measures += pds.Measure(sd=[1.5], fm=[3, 4], c1=[1.5], bd=[1, 2, 2.5]) # Guitar solo for i in range(7): measures += chorus_2b -measures += api.Measure( - sd=[2, 4, 4.5], bd=[1, 3], ho=api.note_range(1, 4, 0.5), c1=[4, 4.5] +measures += pds.Measure( + sd=[2, 4, 4.5], bd=[1, 3], ho=pds.note_range(1, 4, 0.5), c1=[4, 4.5] ) -measures += api.Measure(hh=[1, 2], sd=[4], bd=[3], c1=[3, 4]) +measures += pds.Measure(hh=[1, 2], sd=[4], bd=[3], c1=[3, 4]) # Last round of chorus groove measures += chorus_section # Ending fill -measures += api.Measure( - ho=api.note_range(1, 3, 0.5), sd=[2], fm=[3], bd=[1, 4, 4.5], ft=[3.5], c1=[4.5] +measures += pds.Measure( + ho=pds.note_range(1, 3, 0.5), sd=[2], fm=[3], bd=[1, 4, 4.5], ft=[3.5], c1=[4.5] ) # And I'm going down.... diff --git a/pydrumscore/test/songs/song_money_beat.py b/pydrumscore/test/songs/song_money_beat.py index 8d2610a..01a5154 100644 --- a/pydrumscore/test/songs/song_money_beat.py +++ b/pydrumscore/test/songs/song_money_beat.py @@ -1,10 +1,10 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import MONEY_BEAT measures = [] -metadata = api.Metadata(workTitle="MoneyBeat_1b") +metadata = pds.Metadata(workTitle="MoneyBeat_1b") measures += MONEY_BEAT diff --git a/pydrumscore/test/songs/song_money_beat_accents.py b/pydrumscore/test/songs/song_money_beat_accents.py index 1aa4e18..e0c743c 100644 --- a/pydrumscore/test/songs/song_money_beat_accents.py +++ b/pydrumscore/test/songs/song_money_beat_accents.py @@ -1,11 +1,11 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import MONEY_BEAT measures = [] -metadata = api.Metadata(workTitle="MoneyBeat_Accents_1b") +metadata = pds.Metadata(workTitle="MoneyBeat_Accents_1b") -measures += api.Measure(MONEY_BEAT) +measures += pds.Measure(MONEY_BEAT) measures[0].ac = [2, 4] diff --git a/pydrumscore/test/songs/song_rock_beat.py b/pydrumscore/test/songs/song_rock_beat.py index dc41662..72e1e08 100644 --- a/pydrumscore/test/songs/song_rock_beat.py +++ b/pydrumscore/test/songs/song_rock_beat.py @@ -1,8 +1,8 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import ROCK_BEAT -metadata = api.Metadata(workTitle="RockBeat_1b") +metadata = pds.Metadata(workTitle="RockBeat_1b") measures = [ROCK_BEAT] diff --git a/pydrumscore/test/songs/song_rock_beat_wopen.py b/pydrumscore/test/songs/song_rock_beat_wopen.py index 9a00ae0..65e2c04 100644 --- a/pydrumscore/test/songs/song_rock_beat_wopen.py +++ b/pydrumscore/test/songs/song_rock_beat_wopen.py @@ -1,8 +1,8 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import ROCK_BEAT_WOPEN -metadata = api.Metadata(workTitle="RockBeatWOpen_1b") +metadata = pds.Metadata(workTitle="RockBeatWOpen_1b") measures = [ROCK_BEAT_WOPEN] diff --git a/pydrumscore/test/songs/song_shuffle_beat.py b/pydrumscore/test/songs/song_shuffle_beat.py index 8da5a7f..780812c 100644 --- a/pydrumscore/test/songs/song_shuffle_beat.py +++ b/pydrumscore/test/songs/song_shuffle_beat.py @@ -1,8 +1,8 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import SHUFFLE_BEAT -metadata = api.Metadata(workTitle="ShuffleBeat_1b") +metadata = pds.Metadata(workTitle="ShuffleBeat_1b") measures = [SHUFFLE_BEAT] diff --git a/pydrumscore/test/songs/song_silence.py b/pydrumscore/test/songs/song_silence.py index fa8988d..4bcaa9f 100644 --- a/pydrumscore/test/songs/song_silence.py +++ b/pydrumscore/test/songs/song_silence.py @@ -1,8 +1,8 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import SILENCE -metadata = api.Metadata(workTitle="Silence_1b") +metadata = pds.Metadata(workTitle="Silence_1b") measures = [SILENCE] diff --git a/pydrumscore/test/songs/song_template b/pydrumscore/test/songs/song_template deleted file mode 100644 index f6c6001..0000000 --- a/pydrumscore/test/songs/song_template +++ /dev/null @@ -1,16 +0,0 @@ -import pydrumscore as api -import pydrumscore.core.beats as beats - -########### Metadata ########### -metadata = api.Metadata( - workTitle = $workTitle$ - ) -########### End Metadata ########### - - -########### Song creation ########### - -# Fill up this array with api.Measure objects -measures = [] - -########### End song creation ########### diff --git a/pydrumscore/test/songs/song_tempo_change.py b/pydrumscore/test/songs/song_tempo_change.py index f1a2c11..e55750d 100644 --- a/pydrumscore/test/songs/song_tempo_change.py +++ b/pydrumscore/test/songs/song_tempo_change.py @@ -1,10 +1,10 @@ # pylint: disable = missing-module-docstring from typing import List -import pydrumscore as api +import pydrumscore as pds from pydrumscore import Measure -metadata = api.Metadata(workTitle="Test tempo change") +metadata = pds.Metadata(workTitle="Test tempo change") measures: List[Measure] = [] diff --git a/pydrumscore/test/songs/song_text.py b/pydrumscore/test/songs/song_text.py index 0f286d6..97ceeba 100644 --- a/pydrumscore/test/songs/song_text.py +++ b/pydrumscore/test/songs/song_text.py @@ -1,9 +1,9 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds from pydrumscore.core.beats import SILENCE -metadata = api.Metadata(workTitle="Text on first measure") +metadata = pds.Metadata(workTitle="Text on first measure") measures = [SILENCE] diff --git a/pydrumscore/test/songs/song_uptown_funk.py b/pydrumscore/test/songs/song_uptown_funk.py index 693e3e1..54c8b3a 100644 --- a/pydrumscore/test/songs/song_uptown_funk.py +++ b/pydrumscore/test/songs/song_uptown_funk.py @@ -1,11 +1,11 @@ # pylint: disable = missing-module-docstring, missing-function-docstring, redefined-outer-name, global-statement, invalid-name -import pydrumscore as api +import pydrumscore as pds from pydrumscore import Measure, note_range from pydrumscore.core.beats import SILENCE -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Uptown Funk (feat. Bruno Mars)", composer="Mark Ronson, Bruno Mars", ) @@ -30,7 +30,7 @@ def verse(skip_first_m=False): continue m = Measure( - hh=note_range(1, api.end(), 0.5), + hh=note_range(1, pds.end(), 0.5), sd=[2, 4], bd=[1, 2, 3, 4], # ac = [1,2,3,4] @@ -54,7 +54,7 @@ def girls_hit_hallelujah(): # Cause uptown funk gonne give it to ya (buildup) if i >= 4 and i != 7: - m.sd = note_range(1, api.end(), 0.5) + m.sd = note_range(1, pds.end(), 0.5) if i == 7: # Don't believe me just watch! @@ -72,14 +72,14 @@ def girls_hit_hallelujah(): def chorus(): for i in range(8): m = Measure( - hh=note_range(1, api.end(), 0.5), + hh=note_range(1, pds.end(), 0.5), sd=[2, 4], bd=[1, 2, 3, 4], # ac = [1,2,3,4] ) if i % 4 == 3: - m.sd += note_range(3.5, api.end(), 0.25) - m.hh = [hh for hh in m.hh if hh not in note_range(3.5, api.end(), 0.5)] + m.sd += note_range(3.5, pds.end(), 0.25) + m.hh = [hh for hh in m.hh if hh not in note_range(3.5, pds.end(), 0.5)] elif i % 4 == 0: m.replace(m.hh, m.c1, [1]) elif i % 2: @@ -96,7 +96,7 @@ def chorus(): for i in range(4): m = Measure( hh=note_range(1, 3.5, 0.5), - sd=[2, 4] + note_range(3.5, api.end(), 0.25), + sd=[2, 4] + note_range(3.5, pds.end(), 0.25), bd=[1, 2, 3, 4], ) if i == 3: @@ -114,7 +114,7 @@ def chorus(): for i in range(4): m = Measure( hh=note_range(1, 3.5, 0.5), - sd=[2, 4] + note_range(3.5, api.end(), 0.25), + sd=[2, 4] + note_range(3.5, pds.end(), 0.25), bd=[1, 2, 3, 4], ) if i == 3: @@ -132,7 +132,7 @@ def chorus(): m.ho = [4.5] elif i > 3: - m.hh = note_range(1, api.end(), 0.5) + m.hh = note_range(1, pds.end(), 0.5) if i % 2: if i == 11: m.hh.remove(4) @@ -153,7 +153,7 @@ def chorus(): for i in range(4): m = Measure( hh=note_range(1, 3.5, 0.5), - sd=[2, 4] + note_range(3.5, api.end(), 0.25), + sd=[2, 4] + note_range(3.5, pds.end(), 0.25), bd=[1, 2, 3, 4], ) if i == 3: @@ -164,8 +164,8 @@ def chorus(): # Reprise of chorus with ride bell! for i in range(16): m = Measure( - rd=note_range(1, api.end(), 1), - rb=note_range(1.5, api.end(), 1), + rd=note_range(1, pds.end(), 1), + rb=note_range(1.5, pds.end(), 1), sd=[2, 4], bd=[1, 2, 3, 4], ) @@ -177,7 +177,7 @@ def chorus(): m = Measure(ho=[1], sd=[1.5], fm=[2, 3, 4], bd=[1, 2.5, 3.5, 4.25]) elif i == 11: m = Measure( - sd=note_range(1, 3, 0.5) + note_range(3, api.end(), 0.25), + sd=note_range(1, 3, 0.5) + note_range(3, pds.end(), 0.25), bd=[1, 2, 3, 4], ) diff --git a/pydrumscore/test/songs/time_eighth_note_denominator.py b/pydrumscore/test/songs/time_eighth_note_denominator.py index d75f969..21ae4ae 100644 --- a/pydrumscore/test/songs/time_eighth_note_denominator.py +++ b/pydrumscore/test/songs/time_eighth_note_denominator.py @@ -1,13 +1,13 @@ # pylint: disable = missing-module-docstring -import pydrumscore as api +import pydrumscore as pds -metadata = api.Metadata( +metadata = pds.Metadata( workTitle="Eighth Note Denominator", ) measures = [] for n in range(1, 13): - api.set_time_sig(f"{str(n)}/8") - measures += api.Measure(snare=api.note_range(1, api.end(), 0.5)) + pds.set_time_sig(f"{str(n)}/8") + measures += pds.Measure(snare=pds.note_range(1, pds.end(), 0.5)) From f485ecb55a0b24619f4086925559c439507038dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lapointe?= <28580319+OmegaLarmor@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:17:56 -0500 Subject: [PATCH 2/5] Move the main files out of the "core" folder for now --- pydrumscore/__init__.py | 2 +- pydrumscore/__main__.py | 2 +- pydrumscore/{core => }/api.py | 0 pydrumscore/{core => }/beats.py | 0 pydrumscore/core/__init__.py | 0 pydrumscore/{core => }/export.py | 2 +- pydrumscore/test/songs/bass_drum_permutations.py | 2 +- pydrumscore/test/songs/bass_drum_permutations_random.py | 2 +- pydrumscore/test/songs/hihat_open_permutations.py | 2 +- pydrumscore/test/songs/song_accented_metadata.py | 2 +- pydrumscore/test/songs/song_highway_to_hell.py | 2 +- pydrumscore/test/songs/song_king_nothing.py | 2 +- pydrumscore/test/songs/song_money_beat.py | 2 +- pydrumscore/test/songs/song_money_beat_accents.py | 2 +- pydrumscore/test/songs/song_rock_beat.py | 2 +- pydrumscore/test/songs/song_rock_beat_wopen.py | 2 +- pydrumscore/test/songs/song_shuffle_beat.py | 2 +- pydrumscore/test/songs/song_silence.py | 2 +- pydrumscore/test/songs/song_text.py | 2 +- pydrumscore/test/songs/song_uptown_funk.py | 2 +- pydrumscore/test/test_base.py | 2 +- pydrumscore/test/test_cli.py | 2 +- pyproject.toml | 2 +- 23 files changed, 20 insertions(+), 20 deletions(-) rename pydrumscore/{core => }/api.py (100%) rename pydrumscore/{core => }/beats.py (100%) delete mode 100644 pydrumscore/core/__init__.py rename pydrumscore/{core => }/export.py (99%) diff --git a/pydrumscore/__init__.py b/pydrumscore/__init__.py index 39d415a..51f93f0 100644 --- a/pydrumscore/__init__.py +++ b/pydrumscore/__init__.py @@ -6,7 +6,7 @@ # Imports the entire API into the "pydrumscore" namespace # Note: This wildcard approach means the API needs to be maintained to not leak symbols # The approach is similar to what is done in numpy, for example -from pydrumscore.core.api import * +from pydrumscore.api import * # Init logger for all modules logging.basicConfig(level=logging.INFO) diff --git a/pydrumscore/__main__.py b/pydrumscore/__main__.py index e3a4789..70ebb0d 100644 --- a/pydrumscore/__main__.py +++ b/pydrumscore/__main__.py @@ -1,7 +1,7 @@ """ Calls the exporter when running 'pydrumscore' from the command line with 'python -m pydrumscore' """ -from pydrumscore.core import export +from pydrumscore import export if __name__ == "__main__": export.main() diff --git a/pydrumscore/core/api.py b/pydrumscore/api.py similarity index 100% rename from pydrumscore/core/api.py rename to pydrumscore/api.py diff --git a/pydrumscore/core/beats.py b/pydrumscore/beats.py similarity index 100% rename from pydrumscore/core/beats.py rename to pydrumscore/beats.py diff --git a/pydrumscore/core/__init__.py b/pydrumscore/core/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pydrumscore/core/export.py b/pydrumscore/export.py similarity index 99% rename from pydrumscore/core/export.py rename to pydrumscore/export.py index e351932..a847eb1 100644 --- a/pydrumscore/core/export.py +++ b/pydrumscore/export.py @@ -190,7 +190,7 @@ def add_elem( # Inserts an XML file into the 'score' xml variable. xml_part_filepath = str( - Path(from_root(__file__).parent / "..", "refxml", "PartXML.xml") + Path(from_root(__file__).parent, "refxml", "PartXML.xml") ) score.appendChild(minidom.parse(xml_part_filepath).firstChild) diff --git a/pydrumscore/test/songs/bass_drum_permutations.py b/pydrumscore/test/songs/bass_drum_permutations.py index 407d7e0..0994492 100644 --- a/pydrumscore/test/songs/bass_drum_permutations.py +++ b/pydrumscore/test/songs/bass_drum_permutations.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import MONEY_BEAT +from pydrumscore.beats import MONEY_BEAT metadata = pds.Metadata( workTitle="Bass drum permutations", diff --git a/pydrumscore/test/songs/bass_drum_permutations_random.py b/pydrumscore/test/songs/bass_drum_permutations_random.py index 65b5ff9..4fedb11 100644 --- a/pydrumscore/test/songs/bass_drum_permutations_random.py +++ b/pydrumscore/test/songs/bass_drum_permutations_random.py @@ -3,7 +3,7 @@ import random import pydrumscore as pds -from pydrumscore.core.beats import MONEY_BEAT +from pydrumscore.beats import MONEY_BEAT metadata = pds.Metadata( workTitle="Bass drum permutations, shuffled", diff --git a/pydrumscore/test/songs/hihat_open_permutations.py b/pydrumscore/test/songs/hihat_open_permutations.py index ee0026b..6456bc4 100644 --- a/pydrumscore/test/songs/hihat_open_permutations.py +++ b/pydrumscore/test/songs/hihat_open_permutations.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import MONEY_BEAT +from pydrumscore.beats import MONEY_BEAT metadata = pds.Metadata( workTitle="Hi-hat open permutations", diff --git a/pydrumscore/test/songs/song_accented_metadata.py b/pydrumscore/test/songs/song_accented_metadata.py index 463b396..165f8c6 100644 --- a/pydrumscore/test/songs/song_accented_metadata.py +++ b/pydrumscore/test/songs/song_accented_metadata.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import SILENCE +from pydrumscore.beats import SILENCE metadata = pds.Metadata(workTitle="Rémy's Wonderful Song") diff --git a/pydrumscore/test/songs/song_highway_to_hell.py b/pydrumscore/test/songs/song_highway_to_hell.py index 032ef9d..167b1bc 100644 --- a/pydrumscore/test/songs/song_highway_to_hell.py +++ b/pydrumscore/test/songs/song_highway_to_hell.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import SILENCE, MONEY_BEAT, HIGHWAY_GROOVE, HIGHWAY_GROOVE_O +from pydrumscore.beats import SILENCE, MONEY_BEAT, HIGHWAY_GROOVE, HIGHWAY_GROOVE_O metadata = pds.Metadata( workTitle="Highway to Hell", diff --git a/pydrumscore/test/songs/song_king_nothing.py b/pydrumscore/test/songs/song_king_nothing.py index e6fa624..10139ea 100644 --- a/pydrumscore/test/songs/song_king_nothing.py +++ b/pydrumscore/test/songs/song_king_nothing.py @@ -2,7 +2,7 @@ from copy import deepcopy from pydrumscore import Measure, Metadata, note_range, end -from pydrumscore.core.beats import SILENCE +from pydrumscore.beats import SILENCE metadata = Metadata( workTitle="King Nothing", composer="Metallica", subtitle="Drum transcription" diff --git a/pydrumscore/test/songs/song_money_beat.py b/pydrumscore/test/songs/song_money_beat.py index 01a5154..8f3cd01 100644 --- a/pydrumscore/test/songs/song_money_beat.py +++ b/pydrumscore/test/songs/song_money_beat.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import MONEY_BEAT +from pydrumscore.beats import MONEY_BEAT measures = [] diff --git a/pydrumscore/test/songs/song_money_beat_accents.py b/pydrumscore/test/songs/song_money_beat_accents.py index e0c743c..1404d47 100644 --- a/pydrumscore/test/songs/song_money_beat_accents.py +++ b/pydrumscore/test/songs/song_money_beat_accents.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import MONEY_BEAT +from pydrumscore.beats import MONEY_BEAT measures = [] diff --git a/pydrumscore/test/songs/song_rock_beat.py b/pydrumscore/test/songs/song_rock_beat.py index 72e1e08..05cdceb 100644 --- a/pydrumscore/test/songs/song_rock_beat.py +++ b/pydrumscore/test/songs/song_rock_beat.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import ROCK_BEAT +from pydrumscore.beats import ROCK_BEAT metadata = pds.Metadata(workTitle="RockBeat_1b") diff --git a/pydrumscore/test/songs/song_rock_beat_wopen.py b/pydrumscore/test/songs/song_rock_beat_wopen.py index 65e2c04..6abc694 100644 --- a/pydrumscore/test/songs/song_rock_beat_wopen.py +++ b/pydrumscore/test/songs/song_rock_beat_wopen.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import ROCK_BEAT_WOPEN +from pydrumscore.beats import ROCK_BEAT_WOPEN metadata = pds.Metadata(workTitle="RockBeatWOpen_1b") diff --git a/pydrumscore/test/songs/song_shuffle_beat.py b/pydrumscore/test/songs/song_shuffle_beat.py index 780812c..8fd81f8 100644 --- a/pydrumscore/test/songs/song_shuffle_beat.py +++ b/pydrumscore/test/songs/song_shuffle_beat.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import SHUFFLE_BEAT +from pydrumscore.beats import SHUFFLE_BEAT metadata = pds.Metadata(workTitle="ShuffleBeat_1b") diff --git a/pydrumscore/test/songs/song_silence.py b/pydrumscore/test/songs/song_silence.py index 4bcaa9f..31262bc 100644 --- a/pydrumscore/test/songs/song_silence.py +++ b/pydrumscore/test/songs/song_silence.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import SILENCE +from pydrumscore.beats import SILENCE metadata = pds.Metadata(workTitle="Silence_1b") diff --git a/pydrumscore/test/songs/song_text.py b/pydrumscore/test/songs/song_text.py index 97ceeba..48adba5 100644 --- a/pydrumscore/test/songs/song_text.py +++ b/pydrumscore/test/songs/song_text.py @@ -1,7 +1,7 @@ # pylint: disable = missing-module-docstring import pydrumscore as pds -from pydrumscore.core.beats import SILENCE +from pydrumscore.beats import SILENCE metadata = pds.Metadata(workTitle="Text on first measure") diff --git a/pydrumscore/test/songs/song_uptown_funk.py b/pydrumscore/test/songs/song_uptown_funk.py index 54c8b3a..c525cb0 100644 --- a/pydrumscore/test/songs/song_uptown_funk.py +++ b/pydrumscore/test/songs/song_uptown_funk.py @@ -3,7 +3,7 @@ import pydrumscore as pds from pydrumscore import Measure, note_range -from pydrumscore.core.beats import SILENCE +from pydrumscore.beats import SILENCE metadata = pds.Metadata( workTitle="Uptown Funk (feat. Bruno Mars)", diff --git a/pydrumscore/test/test_base.py b/pydrumscore/test/test_base.py index 0be6bac..a692e34 100644 --- a/pydrumscore/test/test_base.py +++ b/pydrumscore/test/test_base.py @@ -12,7 +12,7 @@ from xmldiff import main # Local modules -from pydrumscore.core import export +from pydrumscore import export CURRPATH = os.path.abspath(os.path.dirname(__file__)) diff --git a/pydrumscore/test/test_cli.py b/pydrumscore/test/test_cli.py index 7567ad4..a9faa01 100644 --- a/pydrumscore/test/test_cli.py +++ b/pydrumscore/test/test_cli.py @@ -3,7 +3,7 @@ """ import unittest -from pydrumscore.core.export import export_from_filename +from pydrumscore.export import export_from_filename from pydrumscore.test.songs import song_silence diff --git a/pyproject.toml b/pyproject.toml index d5b1acb..2955f58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ dynamic = ["version"] [project.scripts] -pydrumscore = "pydrumscore.core.export:main" +pydrumscore = "pydrumscore.export:main" # Gets version number from source control [tool.setuptools_scm] From 7c7e3e20e1778081e866419da9724cbebaacc353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lapointe?= <28580319+OmegaLarmor@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:42:17 -0500 Subject: [PATCH 3/5] Fix path search bug --- pydrumscore/export.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydrumscore/export.py b/pydrumscore/export.py index a847eb1..31c8f54 100644 --- a/pydrumscore/export.py +++ b/pydrumscore/export.py @@ -671,7 +671,8 @@ def find_relpath_by_walk(): return -1 # Trim the relpath in case the module is used in a virtual environment (thus contains venv/site-packages...) - found_rel_path = "pydrumscore" + found_rel_path.split("pydrumscore")[-1] + if "site-packages" in found_rel_path: + found_rel_path = "pydrumscore" + found_rel_path.split("pydrumscore")[-1] # Use result to craft module str and begin export def build_module_str(filename, relpath): From 854934e000c0f92ad6e13b42e270f45d98eed22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lapointe?= <28580319+OmegaLarmor@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:28:13 -0500 Subject: [PATCH 4/5] Set up default_config file to allow user to use their own --- .../{config.ini => default_config.ini} | 0 pydrumscore/export.py | 25 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) rename pydrumscore/{config.ini => default_config.ini} (100%) diff --git a/pydrumscore/config.ini b/pydrumscore/default_config.ini similarity index 100% rename from pydrumscore/config.ini rename to pydrumscore/default_config.ini diff --git a/pydrumscore/export.py b/pydrumscore/export.py index 31c8f54..9bf407f 100644 --- a/pydrumscore/export.py +++ b/pydrumscore/export.py @@ -48,12 +48,19 @@ # Perhaps revisit sometime if it has been done, or do it ourselves... configur = ConfigParser() -config_root = from_root() -if config_root.stem != "pydrumscore": - # Work around apparent issue in "from_root" where cloned and pip installed setup differ by one level - config_root = config_root / "pydrumscore" - -configur.read(config_root / "config.ini") +config_path = Path("config.ini") +if Path.exists(config_path): + configur.read(config_path) +else: + config_root = from_root() + if config_root.stem != "pydrumscore": + # Work around apparent issue in "from_root" where cloned and pip installed setup differ by one level + config_root = config_root / "pydrumscore" + logging.getLogger(__name__).warning( + "Using default config, which may have the wrong version of MuseScore set up. Create a 'config.ini' in the folder from which you execute PyDrumScore. \ +This will be improved in future versions, for now refer to the tutorials in the documentation." + ) + configur.read(config_root / "default_config.ini") MS_VERSION = configur.get("msversion", "msversion") PROGRAM_VERSION = configur.get("msversion", "program_version") @@ -189,9 +196,7 @@ def add_elem( add_elem("metaTag", score, [("name", tag)], inner_txt=getattr(metadata, tag)) # Inserts an XML file into the 'score' xml variable. - xml_part_filepath = str( - Path(from_root(__file__).parent, "refxml", "PartXML.xml") - ) + xml_part_filepath = str(Path(from_root(__file__).parent, "refxml", "PartXML.xml")) score.appendChild(minidom.parse(xml_part_filepath).firstChild) # Boilerplate for Staff @@ -702,8 +707,6 @@ def main(): Example for a song file "my_song.py": pydrumscore my_song - - The song file can be in any folder of the configured song directory (TODO). """ # Allows importing local, user-created modules with the "name only" format (without python -m) From edf65e6bc426c5cfddc4449a67db814b089b810e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Lapointe?= <28580319+OmegaLarmor@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:38:50 -0500 Subject: [PATCH 5/5] Fix path following core removal --- pydrumscore/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydrumscore/export.py b/pydrumscore/export.py index 9bf407f..0d72061 100644 --- a/pydrumscore/export.py +++ b/pydrumscore/export.py @@ -40,7 +40,7 @@ pydrumscore_version = version_mod.version else: pydrumscore_version = setuptools_scm.get_version( - root="../../", relative_to=__file__ + root="../", relative_to=__file__ ) # Read config file