Package jm.music.data

Examples of jm.music.data.Note


            int[] blackNotes = {1, 3, 6, 8, 10};
            boolean white = true;
            for (int k = 0; k < blackNotes.length; k++) {
                if (newPitch % 12 == blackNotes[k]) newPitch--;
            }
            Note n = new Note(newPitch, 1.0);
            Phrase phr = theApp.getPhrase();
            phr.addNote(n);
            theApp.repaint();
            // set cursor
            theApp.setCursor(new Cursor(Cursor.HAND_CURSOR));
            // get ready to drag it
            selectedNote = phr.size() - 1;
            //theApp.playCurrentNote(selectedNote);
            clickedPosY = e.getY() + theApp.staveDelta;
            clickedPosX = e.getX();
        } else {
            // check for a click on a note  - head?
            for (int i = 0; i < theApp.notePositions.size(); i += 2) {
                Integer tempX = (Integer) theApp.notePositions.elementAt(i);
                Integer tempY = (Integer) theApp.notePositions.elementAt(i + 1);
                if (e.getX() > tempX.intValue() && e.getX() < tempX.intValue() + 15 && e.getY() +
                        theApp.staveDelta > tempY.intValue() + 22 && e.getY() +
                        theApp.staveDelta < tempY.intValue() + 35) {
                    // set cursor
                    theApp.setCursor(new Cursor(Cursor.MOVE_CURSOR));
                    selectedNote = i / 2;
                    clickedPosY = e.getY() + theApp.staveDelta;
                    clickedPosX = e.getX();
                    //System.out.println("Hit note "+ selectedNote);
                    // get out of loop ASAP
                    i = theApp.notePositions.size();
                }
            }
        }
        if (selectedNote < 0) { // no note clicked on or yet made
            // check which note to insert
            for (int j = 0; j < theApp.notePositions.size() - 2; j += 2) {
                Integer tempX = (Integer) theApp.notePositions.elementAt(j);
                Integer nextTempX = (Integer) theApp.notePositions.elementAt(j + 2);
                if (e.getX() > tempX.intValue() + 15 && e.getX() < nextTempX.intValue()) {
                    // change cursor
                    theApp.setCursor(new Cursor(Cursor.HAND_CURSOR));
                    // add new note close to mouse clicked pitch
                    int newPitch = 85 - (e.getY() + theApp.staveDelta - theApp.bPos) / 2;
                    // make sure it is not an accidental
                    int[] blackNotes = {1, 3, 6, 8, 10};
                    boolean white = true;
                    for (int k = 0; k < blackNotes.length; k++) {
                        if (newPitch % 12 == blackNotes[k]) newPitch--;
                    }
                    Note n = new Note(newPitch, 1.0);
                    Phrase phr = theApp.getPhrase();
                    phr.getNoteList().insertElementAt(n, j / 2 + 1);
                    theApp.repaint();
                    // play and update variables for dragging it
                    selectedNote = j / 2 + 1;
View Full Code Here


        if (!theApp.editable) return;
        //theApp.dragNote(e.getX(), e.getY());
        if (selectedNote >= 0) {
            //System.out.println("Dragging "+ selectedNote);
            Phrase phr = theApp.getPhrase();
            Note n = phr.getNote(selectedNote);
            // move note down
            if (e.getY() + theApp.staveDelta > clickedPosY + 2 && theApp.getPhrase().getNote(selectedNote).getPitch() != REST) {
                n.setPitch(n.getPitch() - 1);
                if (n.getPitch() < theApp.getMinPitch()) n.setPitch(theApp.getMinPitch());
                // update the current mouse location
                clickedPosY += 2;
                // update the visual display
                theApp.repaint();
                // keep pitch to reinstate it after displaying a rest
                storedPitch = n.getPitch();
            }
            // move note up
            if (e.getY() + theApp.staveDelta < clickedPosY - 2 && theApp.getPhrase().getNote(selectedNote).getPitch() != REST) {
                n.setPitch(n.getPitch() + 1);
                if (n.getPitch() > theApp.getMaxPitch()) n.setPitch(theApp.getMaxPitch());
                //theApp.playCurrentNote(selectedNote);
                clickedPosY -= 2;
                theApp.repaint();
                storedPitch = n.getPitch();
            }
            // move note right - increase RV
            if (e.getX() > clickedPosX + 6) {
                double tempRV = n.getRhythmValue();
                int tempPitch = n.getPitch();
                // use +100 numbers for rests
                if (tempPitch == REST) tempRV = tempRV + 100;
                int currRVindex = rhythmValues.length;
                // find current rhythm value and update RV
                for (int i = 0; i < rhythmValues.length - 1; i++) {
                    if (tempRV == rhythmValues[i]) n.setRhythmValue(rhythmValues[i + 1]);
                }
                clickedPosX = e.getX();
                // update pitch
                if (n.getRhythmValue() > 100.0) {
                    n.setPitch(REST);
                    n.setRhythmValue(n.getRhythmValue() - 100);
                    // update duration value
                    n.setDuration(n.getRhythmValue() * 0.9);
                } else {
                    if (tempPitch == REST) n.setPitch(storedPitch);
                }
                theApp.repaint();
            }
            // move note left - decrease RV
            if (e.getX() < clickedPosX - 6) {
                double tempRV = n.getRhythmValue();
                int tempPitch = n.getPitch();
                // use +100 numbers for rests
                if (tempPitch == REST) tempRV = tempRV + 100;
                // find current rhythm value position in the array
                int currRVindex = 0;
                for (int i = 0; i < rhythmValues.length; i++) {
                    if (tempRV == rhythmValues[i]) currRVindex = i;
                }
                // update rv
                if (currRVindex > 0) {
                    n.setRhythmValue(rhythmValues[currRVindex - 1]);
                    clickedPosX = e.getX();
                    // update pitch
                    if (n.getRhythmValue() > 100.0) {
                        n.setPitch(REST);
                        n.setRhythmValue(n.getRhythmValue() - 100);
                        // update duration value
                        n.setDuration(n.getRhythmValue() * 0.9);
                    } else {
                        if (tempPitch == REST) n.setPitch(storedPitch);
                    }
                    theApp.repaint();
                }
            }
        }
View Full Code Here

            while (enum2.hasMoreElements()) {
                Phrase phrase = (Phrase) enum2.nextElement();
                Enumeration enum3 = phrase.getNoteList().elements();
                maxWidth = (int) (phrase.getStartTime() * beatWidth);
                while (enum3.hasMoreElements()) {
                    Note aNote = (Note) enum3.nextElement();
                    maxWidth = maxWidth + (int) (aNote.getRhythmValue() * beatWidth);
                }
            }
        }
    }
View Full Code Here

            note.setRhythmValue(note.getRhythmValue() * temp);
            note.setDuration(note.getDuration() * temp);
            testPos += note.getRhythmValue();
            //System.out.println("RTLine: processing a note. Pitch = " + note.getPitch() + " Length = " + (testPos-scorePos) + " Duration = " + note.getDuration());
        } else {
            note = new Note(jm.JMC.REST, (testPos - scorePos));
            note.setRhythmValue(note.getRhythmValue() * temp);
            note.setDuration(note.getRhythmValue());
            //System.out.println("RTLine: adding a rest. Length = " + (testPos-scorePos) + " Sampled processed = " + samplesProcessed);
        }
        inst.renderNote(note, scorePos);
View Full Code Here

                Phrase phrase = (Phrase) enum2.nextElement();
                Enumeration enum3 = phrase.getNoteList().elements();
                double oldStartTime = phrase.getStartTime();

                while (enum3.hasMoreElements()) {
                    Note aNote = (Note) enum3.nextElement();
                    // avoid rests and draw notes
                    int currNote = -1;
                    if (aNote.getPitchType() == Note.MIDI_PITCH) currNote = aNote.getPitch();
                    else currNote = Note.freqToMidiPitch(aNote.getFrequency());
                    if (currNote != REST) {
                        int x = 127 - currNote;
                        int y = (int) Math.round(aNote.getDuration() * beatWidth);
                        int oldY = (int) Math.round(oldStartTime * beatWidth);
                        g.drawLine(oldY, x, oldY + y, x);
                    }
                    oldStartTime += aNote.getRhythmValue();
                }
            }
        }
        // draw new arc
        g.setColor(Color.black);
View Full Code Here

        if (drawPoints.size() > 0) phr = new Phrase(storer[0][0]);
        for (int i = 0; i < storer.length - 1; i++) {
            // prevent out of range notes being generated at the edges
            if (storer[i][1] < 0) storer[i][1] = 0;
            if (storer[i][1] > 127) storer[i][1] = 127;
            Note n = new Note((int) storer[i][1], storer[i + 1][0] - storer[i][0]);
            // avoid unnecessary repeat notes
            if (i > 0 && n.getPitchType() == Note.MIDI_PITCH &&
                    ((Note) (phr.getNoteList().lastElement())).getPitchType() == Note.MIDI_PITCH) {
                if (phr.size() > 0 && n.getPitch() ==
                        ((Note) (phr.getNoteList().lastElement())).getPitch()) {
                    Mod.append(((Note) (phr.getNoteList().lastElement())), n);
                } else {
                    phr.addNote(n);
                }
            } else phr.addNote(n);
        }
        // last note
        if (storer[storer.length - 1][1] < 0) storer[storer.length - 1][1] = 0;
        if (storer[storer.length - 1][1] > 127) storer[storer.length - 1][1] = 127;
        Note n = new Note((int) storer[storer.length - 1][1], storer[storer.length - 1][2]);
        n.setDuration(storer[storer.length - 1][2]);
        phr.addNote(n);

        // add phrase to the score as a new part
        if (phr != null) {
            currentChannel++;
View Full Code Here

                /* Enumerate through all notes */
                int phraseNoteCounter = 0;
                while (enum3.hasMoreElements()) {

                    Note note = (Note) enum3.nextElement();
                    if (note.getFrequency() == (double) REST) { //This a rest ???
                        ntime += phrase_ratio * note.getRhythmValue();
                        continue;
                    }
                    phraseNoteCounter++;
                    if (phraseNoteCounter % 10 == 0) {
                        System.out.print(phraseNoteCounter);
                    } else System.out.print(".");
                    Note new_note = note.copy();
                    //System.out.println("new note pitch = " + new_note.getPitch());
                    new_note.setDuration(phrase_ratio * note.getDuration());
                    new_note.setRhythmValue(phrase_ratio * note.getRhythmValue());
                    Instrument currInst = (Instrument) inst.peek();
                    currInst.setBlock(false);
                    currInst.setFinished(true);
                    currInst.renderNote(new_note, ((double) time + ntime));
                    currInst.setFinished(false);
View Full Code Here

            double rhythm,
            double duration) {

        double restPresent;
        restPresent = getFinalRestRhythm(phrase);
        Note restToAdd;
        if (rhythm - restPresent > 0.001) {
            restToAdd = new Note();
            restToAdd.setFrequency(Note.REST);
            restToAdd.setRhythmValue(
                    rhythm - restPresent);
            restToAdd.setDuration(
                    (rhythm - restPresent) *
                            (duration / rhythm)
            );
            phrase.addNote(restToAdd);
        }
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

                    --pitch;
                }
            }

            // Complete the beat
            returnPhrase.addNote(new Note(pitch,
                    rhythmValueToCompleteBeat));
        }
        return returnPhrase;
    }
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.