Package jm.music.data

Examples of jm.music.data.Note


            }
            Iterator<Note> noteIterator = partNotes.iterator();
            int measureNumber = 1;
            Measure currentMeasure = createMeasure(score, measureNumber++);
            while (noteIterator.hasNext()) {
                Note note = noteIterator.next();
                NoteElement xmlNote = new NoteElement();
                int length = (int) (getClosestLength(note.getRhythmValue()) * 10000);
                switch(length) {
                case (int) (THIRTYSECOND_NOTE * 10000): xmlNote.setType("32nd"); break;
                case (int) (SIXTEENTH_NOTE * 10000): xmlNote.setType("16th"); break;
                case (int) (EIGHTH_NOTE * 10000): xmlNote.setType("eighth"); break;
                case (int) (QUARTER_NOTE * 10000): xmlNote.setType("quarter"); break;
                case (int) (DOTTED_QUARTER_NOTE * 10000): xmlNote.setType("quarter"); xmlNote.setDot(""); break;
                case (int) (HALF_NOTE * 10000): xmlNote.setType("half"); break;
                case (int) (WHOLE_NOTE * 10000): xmlNote.setType("whole"); break;
                default: xmlNote.setType("/" + (length / 10000d));
                }
                xmlNote.setDuration((int) (note.getRhythmValue() * 2));
                xmlNote.setVoice(idx);
                if (!note.isRest()) {
                    xmlNote.setPitch(new Pitch());
                    int pitch = note.getPitch() % 12;
                    String sPitch = NOTES[pitch];
                    int octave = note.getPitch() / 12 - 1;
                    xmlNote.getPitch().setOctave(octave);
                    if (sPitch.length() > 1) {
                        xmlNote.getPitch().setAlter((byte) (sPitch.contains("#") ? 1 : -1));
                        sPitch = sPitch.substring(0, 1);
                    }
                    xmlNote.getPitch().setStep(sPitch);
                } else {
                    xmlNote.setRest(new RestElement());
                }

                currentMeasure.getNotes().add(xmlNote);
                currentMeasureSize += note.getRhythmValue();
                if (currentMeasureSize >= normalizedMeasureSize) {
                    currentMeasureSize = 0;
                    xmlPart.getMeasures().add(currentMeasure);
                    currentMeasure = createMeasure(score, measureNumber++);
                }
View Full Code Here


        int[] rhythm = new int[this.rhythmDepth];
        int[] dynamic = new int[this.dynamicDepth];
        //Make an array of default notes as long as required by numOfNotes
        Note[] noteList = new Note[numOfNotes];
        for (int i = 0; i < numOfNotes; i++) {
            noteList[i] = new Note();
        }
                /*
        for(int i=0;i<this.depth;i++){
      pitch[i] = notes[i].getPitch();
      dynamic[i] = notes[i].getDynamic();
View Full Code Here

                double length =
                        curNote[phrIndex].getRhythmValue();
                curNote[phrIndex].setRhythmValue(
                        length + newTime);
            } else {
                Note restNote = new Note(REST, newTime, 0);
                restNote.setPan(midiChannel);
                restNote.setDuration(newTime);
                restNote.setOffset(0.0);
                ((Phrase) phrVct.elementAt(phrIndex)).
                        addNote(restNote);
            }
            currentLength[phrIndex] += newTime;
        }
        // get end time
        double time = MidiUtil.getEndEvt(pitch, evtList, i) /
                (double) smf.getPPQN();
        // create the new note
        Note tempNote = new Note(pitch, time, dynamic);
        tempNote.setDuration(time);
        curNote[phrIndex] = tempNote;
        ((Phrase) phrVct.elementAt(phrIndex)).addNote(curNote[phrIndex]);
        currentLength[phrIndex] += curNote[phrIndex].getRhythmValue();
    }
View Full Code Here

                System.out.print(" Phrase " + phraseCounter++ + ":");
                // set a silly starting value to force and initial pan cc event
                double pan = -1.0;
                resetTicker(); // zero the ppqn error calculator
                while (phraseEnum.hasMoreElements()) {
                    Note note = (Note) phraseEnum.nextElement();
                    offsetValue = note.getOffset();
                    // add a pan control change if required
                    if (note.getPan() != pan) {
                        pan = note.getPan();
                        midiEvents.add(new EventPair(startTime + offsetValue, new CChange((short) 10, (short) (pan * 127), (short) inst.getChannel(), 0)));
                    }
                    //check for frequency rather than MIDI notes
                    int pitch = 0;
                    if (note.getPitchType() == Note.FREQUENCY) {
                        System.err.println("jMusic warning: converting note frequency to the closest MIDI pitch for SMF.");
                        //System.exit(1);
                        pitch = Note.freqToMidiPitch(note.getFrequency());
                    } else pitch = note.getPitch();
                    if (pitch != REST) {
                        midiEvents.add(new EventPair(new Double(startTime + offsetValue), new NoteOn((short) pitch, (short) note.getDynamic(), (short) inst.getChannel(), 0)));

                        // Add a NoteOn for the END of the note with 0 dynamic, as recommended.
                        //create a timing event at the end of the notes duration
                        double endTime = startTime + (note.getDuration() * phraseTempoMultiplier);
                        // Add the note-off time to the list
                        midiEvents.add(new EventPair(new Double(endTime + offsetValue), new NoteOn((short) pitch, (short) 0, (short) inst.getChannel(), 0)));
                    }
                    // move the note-on time forward by the rhythmic value
                    startTime += tickRounder(note.getRhythmValue() * phraseTempoMultiplier); //time between start times
                    System.out.print("."); // completed a note
                }
            }
      /*
      //Sort lists so start times are in the right order
View Full Code Here

            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

                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

                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

        int noteCount = 0;
        double endTime = phrase.getEndTime();
        if (endTime == 0.0) {
            return new Possible[0];
        }
        Note downBeat = new Note();
        Note halfBeat = new Note();

        int size = phrase.size();
        final Possible[] chords =
                new Possible[(int) Math.ceil(endTime / beatLength)];
View Full Code Here

    int[] rhythm = new int[this.rhythmDepth];
    int[] dynamic = new int[this.dynamicDepth];
    //Make an array of default notes as long as required by numOfNotes
    Note[] noteList = new Note[numOfNotes];
    for(int i=0;i<numOfNotes;i++){
      noteList[i] = new Note();
    }
                /*
    for(int i=0;i<this.depth;i++){
      pitch[i] = notes[i].getPitch();
      dynamic[i] = notes[i].getDynamic();
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.