Package jm.music.data

Examples of jm.music.data.Phrase


     * @param string String of value separated by commas
     * @return Phrase described by the String.
     */
    public static Phrase pitchAndRhythmStringToPhrase(final String string) {
        StringProcessor processor = new StringProcessor(string);
        Phrase phrase = new Phrase();
        try {
            while (true) {
                phrase.addNote(new Note(
                        (int) processor.getNextRhythm(), processor.getNextRhythm()));
            }
        } catch (EOSException e) {
            /* This is okay.  Continue. */
        }
View Full Code Here


     * @param string String of value separated by commas
     * @return Phrase described by the String.
     */
    public static Phrase pitchRhythmAndDynamicStringToPhrase(final String string) {
        StringProcessor processor = new StringProcessor(string);
        Phrase phrase = new Phrase();
        try {
            while (true) {
                phrase.addNote(new Note(
                        (int) processor.getNextRhythm(),
                        processor.getNextRhythm(),
                        (int) processor.getNextRhythm()));
            }
        } catch (EOSException e) {
View Full Code Here

     * This method should be overridden by classes that
     * extend the HelperGUI class.
     */
    protected Score compose() {
        // Simple example composition
        Phrase phrase = new Phrase();
        Score s = new Score(new Part(phrase));
        //for(int i = 0; i < 8; i++) {
        Note n = new Note(48 + (int) (Math.random() * variableA), 0.5 + variableB * 0.25);
        phrase.addNote(n);
        //}

        //Instrument[] tempInsts = {new SineInst(44100)};
        //insts = tempInsts;
        return s;
View Full Code Here

        while (enum1.hasMoreElements()) {
            Part part = (Part) enum1.nextElement();

            Enumeration enum2 = part.getPhraseList().elements();
            while (enum2.hasMoreElements()) {
                Phrase phrase = (Phrase) enum2.nextElement();

                Enumeration enum3 = phrase.getNoteList().elements();
                double oldXBeat = phrase.getStartTime();
                oldX = (int) (Math.round(oldXBeat * beatWidth));
                // calc the phrase rectangles
                rectLeft = oldX;
                rectTop = 100000;
                rectRight = oldX;
View Full Code Here

     * @param String fileName
     */
    public static void jm(Phrase phr, String fileName) {
        if (phr == null) {
            System.err.println("jMusic Read.jm error: The phrase is not initialised! I'm doing it for you.");
            phr = new Phrase();
        }
        phr.empty();
        Part p = new Part();
        jm(p, fileName);
        phr.addNoteList(p.getPhrase(0).getNoteArray());
View Full Code Here

     * @param String fileName
     */
    public static void xml(Phrase phr, String fileName) {
        if (phr == null) {
            System.err.println("jMusic Read.xml error: The phrase is not initialised! I'm doing it for you.");
            phr = new Phrase();
        }
        phr.empty();
        Part p = new Part();
        xml(p, fileName);
        phr.addNoteList(p.getPhrase(0).getNoteArray());
View Full Code Here

    }

    // Play the notes in the input edit control to hear if
    // you want to add them to the phrase
    private void playNotes() {
        Phrase savePhrase = phrase.copy();
        initializeUpdate();
        String s = notesInput.getText();
        for (int i = 0; i < s.length(); ++i) {
            processChar(Character.toUpperCase(s.charAt(i)));
        }
        for (int i = 0; i < savePhrase.size(); ++i) {
            phrase.removeNote(0);
        }
        try {
            JmMidiPlayer midiPlayer = new JmMidiPlayer();
            Score sc = new Score();
            Part p = new Part();
            sc.addPart(p);
            p.addPhrase(phrase);
            Write.midi(sc, midiPlayer);
            midiPlayer.play();
            midiPlayer.close();
        } catch (MidiUnavailableException ex) {
            System.out.println(
                    "Midi Not Available"
            );
        }
        phrase.empty();
        for (int i = 0; i < savePhrase.size(); ++i) {
            phrase.addNote(savePhrase.getNote(i));
        }
    }
View Full Code Here

        Enumeration enum1 = score.getPartList().elements();
        while (enum1.hasMoreElements()) {
            Part part = (Part) enum1.nextElement();
            Enumeration enum2 = part.getPhraseList().elements();
            while (enum2.hasMoreElements()) {
                Phrase phrase = (Phrase) enum2.nextElement();
                Enumeration enum3 = phrase.getNoteList().elements();
                while (enum3.hasMoreElements()) {
                    Note note = (Note) enum3.nextElement();
                    // ignore notes with frequency as a pitch
                    if (note.getPitchType() == Note.MIDI_PITCH) {
                        if (note.getPitch() != REST) {
View Full Code Here

        Part pad1 = ctx.getParts().get(PartType.PAD1);
        Part pad2 = ctx.getParts().get(PartType.PAD2);
        if (pad1 == null) {
            return;
        }
        Phrase pad1Phrase = new Phrase();
        pad1Phrase.setInstrument(pad1.getInstrument());
        pad1.add(pad1Phrase);

        Phrase pad2Phrase = null;
        if (pad2 != null) {
            pad2Phrase = new Phrase();
            pad2Phrase.setInstrument(pad2.getInstrument());
            pad2.add(pad2Phrase);
        }

        boolean pad1Long = Chance.test(40);
        boolean pad2Long = Chance.test(40);
View Full Code Here

        // small offset of all chords from the start of the measure
        // misaligning it slightly with the main part
        double measureOffset = Chance.test(5) ? 0.15 : 0;

        for (Phrase phrase : mainPart.getPhraseArray()) {
            Phrase accompanimentPhrase = new Phrase();
            accompanimentPhrase.setTitle("Accompaniment phrase");
            Scale currentScale = ((ExtendedPhrase) phrase).getScale();
            // get copies of the static ones, so that we can shuffle them without affecting the original
            List<Chord> scaleChords = new ArrayList<Chord>(ChordUtils.chords.get(currentScale));
            List<Chord> scaleSeventhChords = new ArrayList<Chord>(ChordUtils.seventhChords.get(currentScale));
            List<Chord> scaleOtherChords = new ArrayList<Chord>(ChordUtils.otherChords.get(currentScale));

            Note[] notes = phrase.getNoteArray();
            List<ToneType> firstToneTypes = new ArrayList<>();
            boolean interMeasureChord = false;
            double measureChordLength = 0;
            boolean canHaveInterMeasureChords = ctx.getMetre()[0] > 3 && ctx.getMetre()[0] % 4 == 0;

            Chord chord = null;
            for (int i = 0; i < notes.length; i++) {
                // shuffle every time, so that we don't always get the same chord for a given note
                Collections.shuffle(scaleChords, random);
                Collections.shuffle(scaleSeventhChords, random);
                Collections.shuffle(scaleOtherChords, random);

                Note currentNote = notes[i];
                if (currentNote.getRhythmValue() == 0) {
                    continue; // rhythm value is 0 for the first notes of a (main-part) chord. So progress to the next
                }
                // inter-measure chords only for even-numbered, compound metres
                if (canHaveInterMeasureChords && currentMeasureSize == 0) {
                    interMeasureChord = Chance.test(18);
                }
                double chordLength = interMeasureChord ? normalizedMeasureSize / 2 : normalizedMeasureSize;
                boolean isHalfMeasure = currentMeasureSize == normalizedMeasureSize / 2;

                if (currentNote.getPitch() == 0) {
                    logger.warn("Pitch is 0 in main part.");
                    continue;
                }
                if (!currentNote.isRest() && (currentMeasureSize == 0 || (interMeasureChord && isHalfMeasure))) {
                    boolean preferStable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.UNSTABLE);
                    boolean preferUnstable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.STABLE);
                    Chord previous = chord;
                    chord = ChordUtils.getChord(ctx, currentNote.getPitch(), previous, scaleChords, scaleSeventhChords, scaleOtherChords, preferStable, preferUnstable);
                    if (chord != null && Chance.test(90)) {
                        if (Chance.test(20)) { // change the special note type
                            if (Chance.test(60)) { // to a new value
                                specialNoteType = SpecialNoteType.values()[random.nextInt(SpecialNoteType.values().length)];
                            } else { // reset
                                specialNoteType = null;
                            }
                        }
                        firstToneTypes.add(chord.getFirstToneType());
                        int[] chordPitches = chord.getPitches();
                        logger.debug(Arrays.toString(chordPitches) + " : " + currentNote.getPitch());

                        postProcessPitches(accompanimentPart, chordPitches);

                        int dynamics = InstrumentGroups.getInstrumentSpecificDynamics(65 + random.nextInt(20), accompanimentPart.getInstrument());
                        // in some cases repeat the chord
                        if (Chance.test(82)) {
                            if (Chance.test(75)) { //full chord
                                addChord(chordPitches, chordLength, dynamics, accompanimentPhrase,
                                        specialNoteType, preferChordNotesOffset, measureOffset);
                            } else { //partial chord + rest
                                // make the filling rest between 1/16 and 1/4
                                double restLength = 0.125 * Math.pow(2, random.nextInt(4));
                                if (restLength >= chordLength) {
                                    restLength = chordLength / 2;
                                }
                                addChord(chordPitches, chordLength - restLength, dynamics,
                                        accompanimentPhrase, specialNoteType, preferChordNotesOffset,
                                        measureOffset);
                                accompanimentPhrase.addRest(new Rest(restLength));
                            }
                        } else {
                            addChord(chordPitches, chordLength / 2, dynamics, accompanimentPhrase,
                                    specialNoteType, preferChordNotesOffset, measureOffset);
                            addChord(chordPitches, chordLength / 2, dynamics, accompanimentPhrase,
                                    specialNoteType, preferChordNotesOffset, measureOffset);
                        }
                    } else {
                        accompanimentPhrase.addRest(new Rest(chordLength));
                    }

                    measureChordLength += chordLength;
                }

                if (currentNote.isRest() && (currentMeasureSize == 0 || (interMeasureChord && isHalfMeasure))) {
                    accompanimentPhrase.addRest(new Rest(chordLength));
                    measureChordLength += chordLength;
                }

                currentMeasureSize += currentNote.getRhythmValue();
                if (currentMeasureSize >= normalizedMeasureSize) {
                    // when there's a long note and so no inter-measure chord is possible, fill the measure with a rest
                    if (measureChordLength != currentMeasureSize) {
                        double fillingSize = normalizedMeasureSize - measureChordLength;
                        accompanimentPhrase.addRest(new Rest(fillingSize));
                    }
                    currentMeasureSize = 0;
                    measureChordLength = 0;
                }
            }
View Full Code Here

TOP

Related Classes of jm.music.data.Phrase

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.