Package jm.music.data

Examples of jm.music.data.Phrase


    /* The height of the notate window */
    private int height = 0;
    private int width = 700;

    public Notate() {
        this(new Phrase(), 0, 0);
        clearZoom();
    }
View Full Code Here


        this(new Phrase(), 0, 0);
        clearZoom();
    }

    public Notate(int locX, int locY) {
        this(new Phrase(), locX, locY);
        clearZoom();
    }
View Full Code Here

    }

    private void makeAppropriateStaves() {
        Stave[] tempStaveArray = new Stave[staveArray.length];
        for (int i = 0; i < score.size(); i++) {
            Phrase currentPhrase = score.getPart(i).getPhrase(0);
            tempStaveArray[i] = new PianoStave();
            if (currentPhrase.getHighestPitch() < A6 &&
                    currentPhrase.getLowestPitch() > FS3) tempStaveArray[i] = new TrebleStave();
            else if (currentPhrase.getHighestPitch() < F4 &&
                    currentPhrase.getLowestPitch() > B1) tempStaveArray[i] = new BassStave();
            else if (currentPhrase.getHighestPitch() > A6 ||
                    currentPhrase.getLowestPitch() < B1) tempStaveArray[i] = new GrandStave();
        }
        updateAllStaves(tempStaveArray);

    }
View Full Code Here

     */
    public Phrase readMidiPhrase() {
        FileDialog loadMidi = new FileDialog(this, "Select a MIDI file.", FileDialog.LOAD);
        loadMidi.show();
        String fileName = loadMidi.getFile();
        Phrase phr = new Phrase(0.0);
        Score scr = new Score();
        if (fileName != null) {
            Read.midi(scr, loadMidi.getDirectory() + fileName);
        }
        scr.clean();
View Full Code Here

        );
        panel.add(populationLabel);
    }

    public Phrase[] initPopulation(final Phrase phrase, final int beatsPerBar) {
        Phrase seed = completeFinalBeat(phrase, beatsPerBar);
        int size;
        if (modifyAll) {
            size = 0;
        } else size = seed.size();
        double[][] beatRhythmArray = generateBeatRhythmArray(seed, beatsPerBar);
        int[] intervalArray = generateIntervalArray(seed);


        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;
                }
            }
View Full Code Here

        return population;
    }

    private Phrase completeFinalBeat(final Phrase phrase, int beatsPerBar) {
        Phrase returnPhrase = phrase.copy();

        double length = returnPhrase.getEndTime();

        // Because beats are integer multiples of a 1, a crotchet
        double rhythmValueToCompleteBeat = Math.ceil(length) - length;

        // If the melody's length isn't a whole number of beats
        if (rhythmValueToCompleteBeat > 0) {

            int[] intervals = generateIntervalArray(phrase);
            int counter = returnPhrase.size() - 1;
            int pitch = (int) Note.REST;
            while (pitch == Note.REST) {
                pitch = returnPhrase.getNote(counter--)
                        .getPitch();
            }
            pitch += intervals[(int) (Math.random() * intervals.length)];
            if (!isScale(pitch)) {
                if (Math.random() < 0.5) {
                    ++pitch;
                } else {
                    --pitch;
                }
            }

            // Complete the beat
            returnPhrase.addNote(new Note(pitch,
                    rhythmValueToCompleteBeat));
        }
        return returnPhrase;
    }
View Full Code Here

        return champion;
    }

    private Phrase crossover(int crossoverBar, Phrase mother, Phrase father,
                             boolean isFatherFirst, int beatsPerBar) {
        Phrase returnPhrase = new Phrase();

        Phrase currentPhrase = isFatherFirst ? father : mother;
        int currentNote = 0;

        while (returnPhrase.getEndTime()
                + currentPhrase.getNote(currentNote).getRhythmValue()
                < 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++));
        }
        return returnPhrase;
    }
View Full Code Here

            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;
                    clickedPosY = e.getY() + theApp.staveDelta;
                    clickedPosX = e.getX();
View Full Code Here

    public void mouseDragged(MouseEvent e) {
        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
View Full Code Here

        keySelected = false;
        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) {
            note.setFrequency(Note.REST);
        } else if (e.getSource() == deleteNote) {
            phrase.getNoteList().removeElementAt(selectedNote);
        }
        selectedNote = -1;
        theApp.repaint();
    }
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.