Skip to content

Commit

Permalink
Merge pull request #44 from dual-wield-ray/dev/refactor-for-mvp
Browse files Browse the repository at this point in the history
Further cleanup in preparation for MVP release
  • Loading branch information
dual-wield-ray authored Nov 30, 2022
2 parents 86f2e6a + edf65e6 commit 81d83db
Show file tree
Hide file tree
Showing 29 changed files with 126 additions and 138 deletions.
5 changes: 3 additions & 2 deletions pydrumscore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import logging

# Imports the entire API into the "pydrumscore" namespace
# TODO: Rethink this wildcard import (might be ok in the end)
from pydrumscore.core.api import *
# 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.api import *

# Init logger for all modules
logging.basicConfig(level=logging.INFO)
2 changes: 1 addition & 1 deletion pydrumscore/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions pydrumscore/core/api.py → pydrumscore/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
File renamed without changes.
Empty file removed pydrumscore/core/__init__.py
Empty file.
File renamed without changes.
30 changes: 17 additions & 13 deletions pydrumscore/core/export.py → pydrumscore/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@
pydrumscore_version = version_mod.version
else:
pydrumscore_version = setuptools_scm.get_version(
root="../../", relative_to=__file__
root="../", relative_to=__file__
)

# Read config file
# Note: Due to a bug, it's not possible to get MuseScore version info from CLI on Windows
# 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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -671,7 +676,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):
Expand Down Expand Up @@ -701,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)
Expand Down
10 changes: 5 additions & 5 deletions pydrumscore/test/songs/bass_drum_permutations.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# pylint: disable = missing-module-docstring

import pydrumscore as api
from pydrumscore.core.beats import MONEY_BEAT
import pydrumscore as pds
from pydrumscore.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
Expand Down
13 changes: 6 additions & 7 deletions pydrumscore/test/songs/bass_drum_permutations_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@

import random

import pydrumscore as api
from pydrumscore.core.beats import MONEY_BEAT
import pydrumscore as pds
from pydrumscore.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:
m.bd += [p]
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:
Expand Down
8 changes: 4 additions & 4 deletions pydrumscore/test/songs/flam_1b.py
Original file line number Diff line number Diff line change
@@ -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])
6 changes: 3 additions & 3 deletions pydrumscore/test/songs/ghost_1b.py
Original file line number Diff line number Diff line change
@@ -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])
10 changes: 5 additions & 5 deletions pydrumscore/test/songs/hihat_open_permutations.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# pylint: disable = missing-module-docstring

import pydrumscore as api
from pydrumscore.core.beats import MONEY_BEAT
import pydrumscore as pds
from pydrumscore.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]
Expand Down
6 changes: 3 additions & 3 deletions pydrumscore/test/songs/song_accented_metadata.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pylint: disable = missing-module-docstring

import pydrumscore as api
from pydrumscore.core.beats import SILENCE
import pydrumscore as pds
from pydrumscore.beats import SILENCE

metadata = api.Metadata(workTitle="Rémy's Wonderful Song")
metadata = pds.Metadata(workTitle="Rémy's Wonderful Song")

measures = [SILENCE]
60 changes: 30 additions & 30 deletions pydrumscore/test/songs/song_highway_to_hell.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# pylint: disable = missing-module-docstring

import pydrumscore as api
from pydrumscore.core.beats import SILENCE, MONEY_BEAT, HIGHWAY_GROOVE, HIGHWAY_GROOVE_O
import pydrumscore as pds
from pydrumscore.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

Expand All @@ -31,20 +31,20 @@

# 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

# 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):
Expand All @@ -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],
Expand All @@ -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:]
Expand All @@ -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....
Expand Down
2 changes: 1 addition & 1 deletion pydrumscore/test/songs/song_king_nothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pydrumscore/test/songs/song_money_beat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable = missing-module-docstring

import pydrumscore as api
from pydrumscore.core.beats import MONEY_BEAT
import pydrumscore as pds
from pydrumscore.beats import MONEY_BEAT

measures = []

metadata = api.Metadata(workTitle="MoneyBeat_1b")
metadata = pds.Metadata(workTitle="MoneyBeat_1b")

measures += MONEY_BEAT
Loading

0 comments on commit 81d83db

Please sign in to comment.