Package jm.music.data

Examples of jm.music.data.Note


        double[][] tempBeatRVArray =
                new double[(int) phrase.getEndTime() * beatsPerBar][];
        int beatCount = 0;
        int absoluteNotesProcessed = 0;
        double absoluteCumulativeRV = 0;
        Note note;

        while (absoluteNotesProcessed < phrase.size()) {
            int originalNotesProcessed = absoluteNotesProcessed;
            double originalCumulativeRV = absoluteCumulativeRV;

            int notesProcessed = absoluteNotesProcessed;
            double cumulativeRV = absoluteCumulativeRV;

            double[] tempRVArray = new double[phrase.size()];
            int count = 0;
            note = phrase.getNote(notesProcessed++);
            double rhythmValue = note.getRhythmValue();
            tempRVArray[count++] = rhythmValue;
            if (note.getPitch() == Note.REST) {
                tempRVArray[count - 1] *= -1;
            }


            cumulativeRV += rhythmValue;
            while (cumulativeRV != Math.ceil(cumulativeRV)) {
                note = phrase.getNote(notesProcessed++);
                rhythmValue = note.getRhythmValue();
                tempRVArray[count++] = rhythmValue;
                if (note.getPitch() == Note.REST) {
                    tempRVArray[count - 1] *= -1;
                }

                cumulativeRV += rhythmValue;
            }
            double[] RVArray = new double[count];
            System.arraycopy(tempRVArray, 0, RVArray, 0, count);
            tempBeatRVArray[beatCount++] = RVArray;

            absoluteNotesProcessed = notesProcessed;
            absoluteCumulativeRV = cumulativeRV;

            while (cumulativeRV < originalCumulativeRV + (double) beatsPerBar
                    && notesProcessed < phrase.size()) {
                note = phrase.getNote(notesProcessed++);
                rhythmValue = note.getRhythmValue();
                tempRVArray[count++] = rhythmValue;
                if (note.getPitch() == Note.REST) {
                    tempRVArray[count - 1] *= -1;
                }

                cumulativeRV += rhythmValue;
                while (cumulativeRV != Math.ceil(cumulativeRV)) {
                    note = phrase.getNote(notesProcessed++);
                    rhythmValue = note.getRhythmValue();
                    tempRVArray[count++] = rhythmValue;
                    if (note.getPitch() == Note.REST) {
                        tempRVArray[count - 1] *= -1;
                    }

                    cumulativeRV += rhythmValue;
                }
View Full Code Here


                pitch = currentPitch;
            }
            currentPitch--;
        }

        return new Note(pitch, 1.0);
    }
View Full Code Here

                        previousPitch = nextHarmoniousNote;
                    } else {
                        previousPitch = nextHarmoniousNote;
                    }
                }
                phrase.addNote(new Note(previousPitch, 2.0));
//                for (int i = 0; i < beatsPerBar - 2; i++) {                    
//                    addNote(phrase, target, targetBeat, 1.0, intervalArray, climax,
//                            lowerlimit);
//                }
            } else {
View Full Code Here

//        phrase.addNote(target);

    }

    private void addAppropriateTarget(final Phrase phrase, final Note target) {
        Note targetToAdd = target.copy();
        int lastIndex = phrase.size();
        int lastPitch;
        do {
            lastPitch = phrase.getNote(--lastIndex).getPitch();
        } while (lastPitch == Note.REST);
        int targetPitch = target.getPitch();
        if (lastPitch + 7 < targetPitch) {
            do {
                targetPitch -= 12;
            } while (targetPitch - 12 > lastPitch);
            targetToAdd.setPitch(targetPitch);
        }
        phrase.addNote(targetToAdd);
    }
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

            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 {
            searchForSelectedNote(e);
            theApp.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            // check for a click on a note  - head?
        }
        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 ((!button1Down) || (!theApp.editable))
            return;
        //theApp.dragNote(e.getX(), e.getY());
        if (selectedNote >= 0) {
            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]);
                        // update duration value
                        n.setDuration(n.getRhythmValue() * 0.9);
                    }
                }
                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]);
                    // update duration value
                    n.setDuration(n.getRhythmValue() * 0.9);
                    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

                < 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

        theApp.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    public void actionPerformed(ActionEvent e) {
        Phrase phrase = theApp.getPhrase();
        Note note = phrase.getNote(selectedNote);
        if (e.getSource() == editNote) {
            Frame editorFrame
                    = new Frame("Edit this Note");
            editorFrame.setSize(400, 400);
            editorFrame.setResizable(true);
            NoteEditor noteEditor
                    = new NoteEditor(editorFrame);
            noteEditor.editNote(note, 20, 20);
        } else if (e.getSource() == repeatNote) {
            Note newNote = note.copy();
            phrase.getNoteList().insertElementAt(
                    newNote,
                    selectedNote
            );
        } else if (e.getSource() == makeRest) {
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

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.