Skip to content
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

How to use? #211

Closed
Erhannis opened this issue May 27, 2022 · 4 comments
Closed

How to use? #211

Erhannis opened this issue May 27, 2022 · 4 comments

Comments

@Erhannis
Copy link

It's great to have API documentation, info on how to contribute, and all, but none of it gives a good idea how to USE the code. Is there an example, somewhere? A tutorial?

Related - I get the impression this code is supposed to visually render music, but I haven't yet figured out which class does it, and how.

@otsob
Copy link
Owner

otsob commented May 27, 2022

Unfortunately there are no examples yet, they would definitely be useful so I will aim to create some at some point. Wmn4j is mainly intended for handling the content of music notation, e.g., for analysis, so there is no rendering and probably will not be in the near future. The idea is that with being able to output MusicXML, the rendering could be taken care of by any SW able to render notation from MusicXML.

@Erhannis
Copy link
Author

Erhannis commented May 27, 2022

Ah, ok; thank you. Would you happen to know any good MusicXML renderers?

Also, I made some test code; lemme know if I'm doing something wrong, and if not, feel free to copy it into an example file or the README or whatever, if you want.

ScoreBuilder sb = new ScoreBuilder();
sb.addPart(new PartBuilder("melody")
        .add(new MeasureBuilder()
                .setClef(Clef.of(Symbol.G, 2)) // I don't know which line this is supposed to center on
                .setTimeSignature(TimeSignature.of(4, 4))
                .addToVoice(0, new RestBuilder(Duration.of(1, 4)))
                .addToVoice(0, new NoteBuilder(Pitch.of(Pitch.Base.C, Pitch.Accidental.NATURAL, 4), Duration.of(1, 4)))
                .addToVoice(0, new ChordBuilder(Arrays.asList(
                        new NoteBuilder(Pitch.of(Pitch.Base.C, Pitch.Accidental.NATURAL, 4), Duration.of(1, 2)),
                        new NoteBuilder(Pitch.of(Pitch.Base.E, Pitch.Accidental.NATURAL, 4), Duration.of(1, 2)),
                        new NoteBuilder(Pitch.of(Pitch.Base.G, Pitch.Accidental.NATURAL, 4), Duration.of(1, 2))
                )))
        )
);
Score score = sb.build();
try {
    MusicXmlWriter.writerFor(score, new File("example.xml").toPath()).write();
} catch (IOException ex) {
    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}

@otsob
Copy link
Owner

otsob commented May 27, 2022

I think you can render MusicXML with MuseScore and LilyPond. The code snippet looks right, except the G-clef line would typically be 2 when counting from bottom line upwards.

@Erhannis
Copy link
Author

Ok, thanks. And ah - I've figured out that should be "xml" rather than "mxl", or few things will read it. Also I got the note durations wrong. I've edited both things (and the clef) in my previous comment.

@otsob otsob closed this as completed Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants