Package jm.music.data

Examples of jm.music.data.Score


    public InputStream getPieceMusicXml(long id) throws IOException {
        Piece piece = dao.getById(Piece.class, id);
        try (InputStream is = fileStorageService.getFile(getMidiFilePath(id))) {
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            Score score = new Score();
            SMFTools localSMF = new SMFTools();
            localSMF.read(is);
            SMFTools.SMFToScore(score, localSMF);
            score.setTitle(piece.getTitle());
            score.setNumerator(piece.getMetreNumerator());
            score.setDenominator(piece.getMetreDenominator());
            MusicXmlRenderer.render(score, result);
            return new ByteArrayInputStream(result.toByteArray());
        }
    }
View Full Code Here


            try {
                InputStream is = pieceService.getPieceMidiFile(piece.getId());
                byte[] midi = IOUtils.toByteArray(is);
                File tmp = File.createTempFile("tmp", "mid");
                FileUtils.writeByteArrayToFile(tmp, midi);
                Score score = new Score();
                Read.midi(score, tmp.getAbsolutePath());
                double variation = MainPartGenerator.calculateVariation(score.getPart(0));
                piece.setVariation(variation);
                pieceService.save(piece);
                tmp.delete();
            } catch (Exception ex) {
                logger.error("Problem seting variety", ex);
View Full Code Here

        //initJMusicSynthesizer();
    }

    public ScoreContext generatePiece() {
        Score score = new Score();
        final ScoreContext ctx = new ScoreContext();

        ctx.setScore(score);
        for (ScoreManipulator manipulator : manipulators) {
            manipulator.handleScore(score, ctx);
View Full Code Here

    }

    public static void mainMusicXml(String[] args) throws Exception {
        InputStream is = new FileInputStream("C:\\Users\\bozho\\Downloads\\7743.midi");
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        Score score = new Score();
        SMFTools localSMF = new SMFTools();
        localSMF.read(is);
        SMFTools.SMFToScore(score, localSMF);
        score.setTitle("foo");
        score.setNumerator(12);
        score.setDenominator(16);
        MusicXmlRenderer.render(score, result);
        System.out.println(new String(result.toByteArray()));
        is.close();

    }
View Full Code Here

        System.out.println(new String(result.toByteArray()));
        is.close();

    }
    public static void main(String[] args) throws Exception {
        Score score1 = new Score();
        Read.midi(score1, "c:/tmp/gen.midi");
        for (Part part : score1.getPartArray()) {
            System.out.println(part.getInstrument());
        }
        new StartupListener().contextInitialized(null);
        Generator generator = new Generator();
        generator.configLocation = "c:/config/music";
        generator.maxConcurrentGenerations = 5;
        generator.init();

        UserPreferences prefs = new UserPreferences();
        prefs.setElectronic(Ternary.YES);
        //prefs.setSimpleMotif(Ternary.YES);
        //prefs.setMood(Mood.MAJOR);
        //prefs.setDrums(Ternary.YES);
        //prefs.setClassical(true);
        prefs.setAccompaniment(Ternary.YES);
        prefs.setElectronic(Ternary.YES);
        final ScoreContext ctx = generator.generatePiece();
        Score score = ctx.getScore();
        for (Part part : score.getPartArray()) {
            System.out.println(part.getTitle() + ": " + part.getInstrument());
        }

        System.out.println("Metre: " + ctx.getMetre()[0] + "/" + ctx.getMetre()[1]);
        System.out.println(ctx);
        Write.midi(score, "c:/tmp/gen.midi");

        new Thread(new Runnable() {

            @Override
            public void run() {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setBounds(0, 0, 500, 500);
                frame.setVisible(true);
                Part part = ctx.getParts().get(PartType.MAIN);
                Note[] notes = part.getPhrase(0).getNoteArray();
                List<Integer> pitches = new ArrayList<Integer>();
                for (Note note : notes) {
                    if (!note.isRest()) {
                        pitches.add(note.getPitch());
                    }
                }
                GraphicsPanel gp = new GraphicsPanel(pitches);
                frame.setContentPane(gp);
            }
        }).start();

        DecimalFormat df = new DecimalFormat("#.##");

        for (Part part : score.getPartArray()) {
            StringBuilder sb = new StringBuilder();
            printStatistics(ctx, part);
            System.out.println("------------ " + part.getTitle() + "-----------------");
            Phrase[] phrases = part.getPhraseArray();
            for (Phrase phr : phrases) {
View Full Code Here

        }
        Element element = elements[0];
        if (XMLStyles.isValidScoreTag(elements[0].getName())) {
            return elementToScore(elements[0]);
        } else if (XMLStyles.isValidPartTag(elements[0].getName())) {
            return new Score(elementToPart(elements[0]));
        } else if (XMLStyles.isValidPhraseTag(elements[0].getName())) {
            return new Score(new Part(elementToPhrase(elements[0])));
        } else if (XMLStyles.isValidNoteTag(elements[0].getName())) {
            return new Score(new Part(
                    new Phrase(elementToNote(elements[0]))));
        }
        throw new ConversionException("Unrecognised root element: "
                + elements[0].getName());
    }
View Full Code Here

                    "The root element must have the name '"
                            + xmlStyle.getScoreTagName() + "'.  The invalid name used "
                            + "was '" + element.getName() + "'."
            );
        }
        Score returnScore = new Score();
        String attributeValue;

        attributeValue = XMLStyles.getTitleAttributeValue(element);
        if (!attributeValue.equals("")) {
            returnScore.setTitle(attributeValue);
        }
        attributeValue = XMLStyles.getTempoAttributeValue(element);
        if (!attributeValue.equals("")) {
            try {
                returnScore.setTempo(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                                + "attribute '" + xmlStyle.getTempoAttributeName() + "' of element '"
                                + xmlStyle.getScoreTagName() + "' must represent a Java double."
                );
            }
        }
        attributeValue = XMLStyles.getKeySignatureAttributeValue(element);
        if (!attributeValue.equals("")) {
            try {
                returnScore.setKeySignature(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                                + "attribute '" + xmlStyle.getKeySignatureAttributeName() + "' of element '"
                                + xmlStyle.getScoreTagName() + "' must represent a Java integer."
                );
            }
        }
        attributeValue = XMLStyles.getKeyQualityAttributeValue(element);
        if (!attributeValue.equals("")) {
            try {
                returnScore.setKeyQuality(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                                + "attribute '" + xmlStyle.getKeyQualityAttributeName() + "' of element '"
                                + xmlStyle.getScoreTagName() + "' must represent a Java integer."
                );
            }
        }
        attributeValue = XMLStyles.getNumeratorAttributeValue(element);
        if (!attributeValue.equals("")) {
            try {
                returnScore.setNumerator(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                                + "attribute '" + xmlStyle.getNumeratorAttributeName() + "' of element '"
                                + xmlStyle.getScoreTagName() + "' must represent a Java integer."
                );
            }
        }
        attributeValue = XMLStyles.getDenominatorAttributeValue(element);
        if (!attributeValue.equals("")) {
            try {
                returnScore.setDenominator(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                                + "attribute '" + xmlStyle.getDenominatorAttributeName() + "' of element '"
                                + xmlStyle.getScoreTagName() + "' must represent a Java integer."
                );
            }
        }
        Element[] children = element.getChildren();
        for (int i = 0; i < children.length; i++) {
            if (XMLStyles.isValidPartTag(children[i].getName())) {
                returnScore.addPart(elementToPart(children[i]));
            }
        }
        return returnScore;
    }
View Full Code Here

    public Score readFile(final String directoryName, final String fileName) {
        if (directoryName == null || fileName == null) {
            return null;
        }

        Score score = null;
        String message = null;

        /** Attempt to read file */
        try {
            SMF smf = new SMF();
            score = new Score(fileName);
            InputStream is = new FileInputStream(directoryName + fileName);
            smf.read(is);
            jm.midi.MidiParser.SMFToScore(score, smf);
        } catch (IOException e1) {
            message = e1.getMessage();
View Full Code Here

     * Playback a MIDI file from disk.
     *
     * @param fileName The name of the file to play back.
     */
    public static void mid(String fileName) {
        Score score = new Score();
        Read.midi(score, fileName);
        Play.midi(score);
    }
View Full Code Here

     * @param n    The note to be played
     * @param exit Hold program open for the duration of playback, then close ready to exit? true or false.
     */
    public static void midi(Note n, boolean exit) {
        //System.out.println("in midi(Note n, boolean exit)");
        Score s = new Score("One note score", 60);
        s.addPart(new Part(new Phrase(n)));
        midi(s, exit);
    }
View Full Code Here

TOP

Related Classes of jm.music.data.Score

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.