Package jm.music.data

Examples of jm.music.data.Note


        if (! XMLStyles.isValidNoteTag(element.getName())) {
            throw new ConversionException(
                    "Invalid element: " + element.getName() + ".  The only "
                    + "accepted tag name is '" + xmlStyle.getNoteTagName() + "'.");
        }
        Note returnNote = new Note();
        String attributeValue;

        attributeValue = XMLStyles.getPitchAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setPitch(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getPitchAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java integer.");
            }
        }
    attributeValue = XMLStyles.getFrequencyAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                double tempVal = Double.valueOf(attributeValue).doubleValue();
                returnNote.setFrequency(tempVal);
            } catch (NumberFormatException e) {
                throw new ConversionException(
          "Invalid attribute value: " + attributeValue + ".  The "
          + "attribute '" + xmlStyle.getFrequencyAttributeName() + "' of element '"
          + xmlStyle.getNoteTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getDynamicAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setDynamic(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getDynamicAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getRhythmValueAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setRhythmValue(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getRhythmValueAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getPanAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setPan(Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getPanAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getDurationAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setDuration(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getDurationAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getOffsetAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setOffset(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getOffsetAttributeName() + "' of element '"
                        + xmlStyle.getNoteTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getSampleStartTimeAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnNote.setSampleStartTime(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getSampleStartTimeAttributeName() + "' of "
View Full Code Here


    private void addNote(Phrase phrase, Note target, int targetBeat,
                         double rhythmValue, int[] intervalArray, int climax,
                         final int lowerlimit) {
        if (rhythmValue < 0.0) {
            phrase.addNote(new Note(Note.REST, 0.0 - rhythmValue));
        } else {
            // select previous non rest
            int noteIndex = phrase.size() - 1;
            int previousPitch = phrase.getNote(noteIndex).getPitch();
            while (previousPitch == Note.REST) {
                previousPitch = phrase.getNote(--noteIndex).getPitch();
            }
           
            double originalRatio = (target.getPitch() - previousPitch)
                                   / (targetBeat - phrase.getEndTime());
            int selectedInterval = intervalArray[
                    (int) (Math.random() * intervalArray.length)];
            int currentInterval = target.getPitch() - previousPitch;
            double intervalRatio = selectedInterval / (double) currentInterval;
            if (intervalRatio < 0) {
                if (Math.random() < (2.5 / (targetBeat - phrase.getEndTime()))) {
                    selectedInterval = 0 - selectedInterval;
                }
            }
            double currentRatio = currentInterval
                                  / (targetBeat - phrase.getEndTime());
            double ratioOfRatios = currentRatio / originalRatio;
            if (ratioOfRatios >= 2.0 || ratioOfRatios <= 0.5) {
                selectedInterval /= 2;
            }

            int pitch = previousPitch + selectedInterval;
            if (pitch >= climax || pitch < lowerlimit) {
                pitch = previousPitch - selectedInterval;
            }
            if (pitch >= climax || pitch < lowerlimit) {
                pitch = previousPitch - selectedInterval / 2;
            }
            if (pitch >= climax || pitch < lowerlimit) {
                pitch = previousPitch - selectedInterval / 4;
            }

            phrase.addNote(new Note(pitch, rhythmValue));
        }
    }       
View Full Code Here

    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

    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

               < crossoverBar * beatsPerBar) {
            returnPhrase.addNote(currentPhrase.getNote(currentNote++).copy());
        }
        double rhythmValue = crossoverBar * beatsPerBar
                             - returnPhrase.getEndTime();
        returnPhrase.addNote(new Note(
                currentPhrase.getNote(currentNote).getPitch(),
                crossoverBar * beatsPerBar - returnPhrase.getEndTime()));
        currentNote = -1;
        currentPhrase = isFatherFirst ? mother : father;
        double currentRhythmValue = 0;
        while (currentRhythmValue <= crossoverBar * beatsPerBar) {
            currentNote++;
            currentRhythmValue +=
                    currentPhrase.getNote(currentNote).getRhythmValue();
        }
        returnPhrase.addNote(new Note(
                currentPhrase.getNote(currentNote++).getPitch(),
                currentRhythmValue - crossoverBar * beatsPerBar));
        while (currentNote < currentPhrase.size()) {
            returnPhrase.addNote(currentPhrase.getNote(currentNote++));
        }
View Full Code Here

                double lastPanPosition = -1.0
                int offSetTime = 0;         
                /// Each note
                Enumeration notes = phrase.getNoteList().elements();
                while(notes.hasMoreElements()) {
                    Note note = (Note) notes.nextElement();
                    // deal with offset
                    offSetTime = (int)(note.getOffset() * m_ppqn * elementTempoRatio);

          //handle frequency pitch types
          int pitch = -1;
          if(note.getPitchType() == Note.MIDI_PITCH) {
            pitch = note.getPitch();
          } else {
            pitch = Note.freqToMidiPitch(note.getFrequency());
          }

                    int dynamic = note.getDynamic();

                    if (pitch == Note.REST) {
                        phraseTick += note.getRhythmValue() * m_ppqn * elementTempoRatio;
                        continue;
                    }

                    long onTick = (long)(phraseTick);
                    // pan
                    if (note.getPan() != lastPanPosition) {
      evt = createCChangeEvent(currChannel, 10, (int)(note.getPan()*127), onTick);
      currTrack.add(evt);
      lastPanPosition = note.getPan();
        }

                    evt = createNoteOnEvent(currChannel, pitch, dynamic, onTick + offSetTime);
                    currTrack.add(evt);

                    long offTick = (long)(phraseTick + note.getDuration() * m_ppqn * elementTempoRatio);

                    evt = createNoteOffEvent(currChannel, pitch, dynamic, offTick + offSetTime);
                    currTrack.add(evt);

                    phraseTick += note.getRhythmValue() * m_ppqn * elementTempoRatio;

                    // TODO:  Should this be ticks since we have tempo stuff
                    // to worry about
                    //System.out.println("offtick = " + offTick + " ppq = " +
      //         m_ppqn + " score length = " + score.getEndTime() +
View Full Code Here

                n2change3 = (int) Math.floor(n2change2);
            }
            Vector vector = (Vector) individual.getNoteList().clone();
            for (int j = 0; j < n2change3; j++) {
                int r1 = (int) (Math.random() * (n1 - 1));
                Note note5 = (Note) vector.elementAt(initialSize + r1);
                int pitch5 = note5.getPitch();
                double rhythmValue5 = note5.getRhythmValue();
                if (rhythmValue5 >= 1.0 && rhythmValue5%1.0 == 0 &&
                        rhythmValue5 * 2.0 == Math.ceil(rhythmValue5 * 2.0)) {
                    vector.removeElementAt(initialSize + r1);
                    vector.insertElementAt(new Note(pitch5,
                                                    rhythmValue5 / 2.0),
                                           initialSize + r1);
                    vector.insertElementAt(new Note(pitch5,
                                                    rhythmValue5 / 2.0),
                                           initialSize + r1);
                    n1++;
                } else {
                    double rhythmValue6 = rhythmValue5 + ((Note)
                            vector.elementAt(initialSize + r1 + 1))
                                  .getRhythmValue();
                    if (rhythmValue6 <= 2.0) {
                        vector.removeElementAt(initialSize + r1);
                        vector.removeElementAt(initialSize + r1);
                        vector.insertElementAt(new Note(pitch5,
                                                        rhythmValue6),
                                               initialSize + r1);
                        n1--;
                    }
                }
            }
            individual.addNoteList(vector, false);
           
           
            // 4. Step interpolation
            vector = (Vector) individual.getNoteList().clone();
            int currentPitch;
            double currentRV;
            int previousPitch = (int)Note.REST;
            double previousRV = 0;
            int index1 = initialSize;
            while (index1 < vector.size() && previousPitch == Note.REST) {
                previousPitch = ((Note) vector.elementAt(index1)).getPitch();
                previousRV = ((Note) vector.elementAt(index1)).getRhythmValue();
                index1++;
            }
            int k = index1;
            while (k < vector.size()) {
                currentPitch = ((Note) vector.elementAt(k)).getPitch();
                currentRV = ((Note) vector.elementAt(k)).getRhythmValue();
                if (currentPitch != Note.REST) {
                    int interval = currentPitch - previousPitch;
                    if ((Math.abs(interval) == 4 || Math.abs(interval) == 3)
                            && Math.random() < (MUTATE_PERCENTAGE[3] / 100.0)) {
                        int scalePitch = 0;
                        if (interval > 0) {
                            scalePitch = currentPitch - 1;
                            if (!isScale(scalePitch)) {
                                scalePitch--;
                            }
                        } else {
                            scalePitch = currentPitch + 1;
                            if (!isScale(scalePitch)) {
                                scalePitch++;
                            }
                        }
                        if (currentRV > previousRV) {
                            if (currentRV >= 0.5
                                    && (int) Math.ceil(currentRV * 2)
                                       == (int) (currentRV * 2)) {
                                vector.removeElementAt(k);
                                vector.insertElementAt(new Note(currentPitch,
                                        currentRV / 2.0), k);
                                vector.insertElementAt(new Note(scalePitch,
                                        currentRV / 2.0), k);
                                k++;
                            }
                        } else {
                            if (previousRV >= 0.5
                                    && (int) Math.ceil(previousRV * 2)
                                       == (int) (previousRV * 2)) {
                                vector.removeElementAt(k - 1);
                                vector.insertElementAt(new Note(scalePitch,
                                        previousRV / 2.0), k - 1);
                                vector.insertElementAt(new Note(previousPitch,
                                        previousRV / 2.0), k - 1);
                                k++;
                            }
                        }
                    }
View Full Code Here

                    && (degree == 0 || degree == 7)
                    && Math.random() < (2.0 / rhythmValue)
                                       * (MUTATE_PERCENTAGE[4] / 100.0)) {
                vector.removeElementAt(j - count);
                vector.removeElementAt(j - count);
                vector.insertElementAt(new Note(pitch, rhythmValue),
                                       j - count);
                rhythmValueCount += phrase.getNote(j).getRhythmValue();
                j++;
                count++;
            }
View Full Code Here

            super(new Instrument[] {new AudioSampleInst(fileName)});
    }
   
    public synchronized Note getNextNote() {
        // duration and pitch are disregarded by the instrument
        Note n;
        if(firstTime) {
            n = new Note(67, 1.0);
            firstTime = false;
        } else n = new Note(jm.JMC.REST, 1.0);
        return n;
    }
View Full Code Here

        Phrase[] population = new Phrase[populationSize];
        for (int i = 0; i < populationSize; i++) {
            population[i] = seed.copy();

            Note target;
            int targetBeat;
            int climax = 0;

   
            // Set target
            if (isClimaxAccepted(seed, beatsPerBar)) {
                climax = findClimax(seed);
                target = new Note(TONIC, (double) beatsPerBar);
                targetBeat = 7 * beatsPerBar;
            } else {
                int lowestPitch = Note.MAX_PITCH;
                for (int j = 0; j < seed.size(); j++) {
                    int currentPitch = seed.getNote(j).getPitch();
                    if (currentPitch != Note.REST && currentPitch < lowestPitch) {
                        lowestPitch = currentPitch;
                    }
                }
                target = generateClimax(lowestPitch);
                climax = target.getPitch();
                targetBeat = 4 * beatsPerBar;
            }


            /* Find the absolute minimum pitch which is the lower of an octave
             * below the starting note or a fifth below middle C (53),.
             */
            int lowerlimit = -1;
            for (int j = 0; j < seed.size(); j++) {
                int pitch = seed.getNote(j).getPitch();
                if (pitch != Note.REST) {
                    lowerlimit = pitch - 12;
                    break;
                }
            }
            if (lowerlimit < 53) {
                lowerlimit = 53;
            }


            // Extend to target
            extend(population[i], target, targetBeat, beatRhythmArray,
                   intervalArray, climax, beatsPerBar, lowerlimit);
            addAppropriateTarget(population[i], target);
//            population[i].addNote(target);


            // If the melody isn't complete, extend to final note
            if (population[i].getEndTime() != 8 * beatsPerBar) {
                target = new Note(TONIC, (double) beatsPerBar);
                targetBeat = 7 * beatsPerBar;
                extend(population[i], target, targetBeat,
                              beatRhythmArray, intervalArray, climax,
                              beatsPerBar, lowerlimit);

                /* Check last note */
                int noteIndex = population[i].size() - 1;
                int previousPitch = population[i].getNote(noteIndex).getPitch();
                while (previousPitch == Note.REST) {
                    previousPitch = population[i].getNote(--noteIndex).getPitch();
                }

                /* Find tonic closest to previous pitch */
                int targetPitch = target.getPitch();
                if (previousPitch < targetPitch) {
                    if (targetPitch - previousPitch > 6) {
                        target.setPitch(targetPitch - 12);
                    }
                } else if (previousPitch > targetPitch) {
                    if (previousPitch - targetPitch > 6) {
                        target.setPitch(targetPitch + 12);
                    }
                }
                population[i].addNote(target);
            }

View Full Code Here

TOP

Related Classes of jm.music.data.Note

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.