-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utilities to split scores into chunks #380
Comments
There is no built-in functionality to do this, but some workarounds are possible:
I hope that helps! |
Thanks for your help! However, this would not allow exporting back each score part as musicxml, does it? Extracting the note array results in loosing some information (rests, context information), right? Ideally, I would like to be able to input a score and a performance, and being able to split the score and the performances into chunks of n measures, like I'm currently working on something along those lines. I'll post it here once finished. EDIT: I need exporting them back into musicxml as some baselines I want to work with deal directly with musicxml without using partitura. |
ah I see in this case I'd check out the score variant
be aware that the partitura musicxml export might not support all attributes you're interested in, the output scores might look different. |
Oh I missed this object, I'm going to take a look at it! |
This seems to kind of work, but not all the time. I tried the following little script: from pathlib import Path
import partitura as pt
import partitura.score
SCORE_PATH = Path('/home/user/Documents/datasets/nasap-dataset/Rachmaninoff/Preludes_op_32/5/xml_score.musicxml')
MAX_MEASURES = 10
NUM_MEASURES_PER_CHUNK = 3
OUT_DIR = Path("/tmp/score_parts")
score = pt.load_musicxml(SCORE_PATH)
assert len(score.parts) == 1
part = score.parts[0]
OUT_DIR.mkdir(exist_ok=True)
for start_measure_idx in range(0, MAX_MEASURES):
end_measure_idx = start_measure_idx + NUM_MEASURES_PER_CHUNK
print(f"Chunk {start_measure_idx}-{end_measure_idx}")
start_measure = part.measures[start_measure_idx]
end_measure = part.measures[end_measure_idx - 1]
print(start_measure)
print(end_measure)
# Create a new ScoreVariant
sv = pt.score.ScoreVariant(part)
sv.add_segment(start_measure.start, end_measure.end)
new_chunk = sv.create_variant_part()
# Set the new part
pt.save_musicxml(new_chunk, OUT_DIR / f"chunk_{start_measure_idx}-{end_measure_idx}.musicxml") with a Rachmaninoff piece from (n)-ASAP. The first chunks seem ok (except that apart for the very first one key/time signatures are missing, but adding them manually won't be a problem), but it seems that some issues appear at measure 9, with some weird rendering of the quintuplet (quintuplets do not cause issue in the first measures) and MuseScore complaining that the xml has issues. New measure 9 after splitting using I don't know what causes this behavior, but when I manually build the chunks by iterating on all elements and copying them into a new part, this measure is correctly exported. |
good catch! Maybe we should open a separate issue for this ScoreVariant bug? Could you also attach your implementation iterating over all objects and creating a new part for comparison? Thanks a lot! |
I'll do that tomorrow! |
I opened the issue, to summarize, the problem seems to come from a bug in how |
Hello,
First of all, thank you for your work!
I was wondering if Partitura has utilities to split scores (and aligned performances) into chunks of n measures. For what I've seen, it seems not (it should be possible by hand, but I wanted to ask first just in case I missed something).
If that's not the case, I think that it could be a nice enhancement. One purpose of Partitura is to apply machine/deep learning techniques to symbolic music, and it could help to build datasets for such applications. Sometimes, scores are too large to fit in one part in some training contexts, and it would be nice to be able to feed models with chunks of n measures extracted from the score. To be useful, I think such splits should take the context into account: if I extract measures 4 to 8, it should gather earlier some time signature/key into the newly created chunk.
Ideally, it would be very interesting to be able to link this with an aligned performance, so that I could easily take the measures 4-8 of the score, as well as the measures 4-8 of the performance.
The text was updated successfully, but these errors were encountered: