Package jm.music.data

Examples of jm.music.data.Phrase


    private int[] secondChords = new int[0];
    private String[] chordStrings = {"I", "II", "III", "IV", "V", "VI", "VII",
            "."};

    public JGrandStave() {
        this(new Phrase());
        bPos = 110;
        panelHeight = 310;
        this.setSize((int) (beatWidth * 40), panelHeight);
    }
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 {
            // 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;
                    clickedPosY = e.getY() + theApp.staveDelta;
                    clickedPosX = e.getX();
View Full Code Here

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

        while (enum1.hasMoreElements()) {
            Part part = (Part) enum1.nextElement();
            maxParts++;
            Enumeration enum2 = part.getPhraseList().elements();
            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

    /**
     * Constructs a new stave to display a blank Phrase using the default stave
     * images.
     */
    public Stave() {
        this(new Phrase(), new ToolkitImages());
    }
View Full Code Here

     *
     * @param images Images representing notes, rest and other stave elements
     *               to use within the compenent
     */
    public Stave(Images images) {
        this(new Phrase(), images);
    }
View Full Code Here

    * start at time 0.0.
    */
    public Phrase addRequiredRests(Phrase phrase) {
        // add rests if required at the start
        if (phrase.getStartTime() > 0.0) {
            Phrase tempPhrase = new Phrase(0.0);
            double remTime = phrase.getStartTime();
            while (remTime >= 4.0) {
                tempPhrase.addNote(REST, 4.0);
                remTime -= 4.0;
            }
            while (remTime >= 1.0) {
                tempPhrase.addNote(REST, 1.0);
                remTime -= 1.0;
            }
            tempPhrase.addNote(REST, remTime);
            jm.music.tools.Mod.append(tempPhrase, phrase);
            phrase = tempPhrase;
        }
        return phrase;
    }
View Full Code Here

            g.setColor(theColors[i % 10]);
            i++;

            Enumeration enum2 = part.getPhraseList().elements();
            while (enum2.hasMoreElements()) {
                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;
View Full Code Here

        newWidth = 50;
        repaint();
    }

    private void convertLineToPhrase(boolean hiRes) {
        Phrase phr = null;
        double[][] storer = new double[drawPoints.size() / 4][3];
        Enumeration drawEnum = drawPoints.elements();
        int counter = 0;
        while (drawEnum.hasMoreElements()) {
            int x1 = ((Integer) (drawEnum.nextElement())).intValue();
            int y1 = ((Integer) (drawEnum.nextElement())).intValue();
            int x2 = ((Integer) (drawEnum.nextElement())).intValue();
            int y2 = ((Integer) (drawEnum.nextElement())).intValue();
            //System.out.println("Values are "+x1/beatWidth+" "+y1 /beatWidth+" "+x2 /beatWidth+" "+y2 /beatWidth);
            if (hiRes) { // was the option key held down
                // fine grade
                for (int i = 0; i < Math.abs(y1 - y2); i++) {
                    storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4)).
                            intValue()) / beatWidth +
                            ((double) Math.abs(x2 - x1) / beatWidth / (double) (Math.abs(y1 - y2)) + 1.0) /
                                    (Math.abs(y1 - y2) + 1); //onset time
                    if ((int) ((Integer) drawPoints.elementAt(counter * 4)).intValue() >
                            (int) ((Integer) drawPoints.elementAt(counter * 4 + 2)).intValue()) {
                        //revised onset time for drawing backwards
                        storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4 + 2)).
                                intValue()) / beatWidth / (double) (Math.abs(y1 - y2)) + 1.0;
                    }
                    //pitch
                    storer[counter][1] = (double) (127 - y1 + i);
                    //duration
                    storer[counter][2] = (double) Math.abs(x2 - x1) / beatWidth /
                            (double) (Math.abs(y1 - y2)) + 1.0;
                }
            } else {

                // course grade
                storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4)).
                        intValue()) / beatWidth; //onset time
                if ((int) ((Integer) drawPoints.elementAt(counter * 4)).intValue() >
                        (int) ((Integer) drawPoints.elementAt(counter * 4 + 2)).intValue()) {
                    //revised onset time for drawing backwards
                    storer[counter][0] = (double) (((Integer) drawPoints.elementAt(counter * 4 + 2)).
                            intValue()) / beatWidth;
                }
                storer[counter][1] = (double) (127 - y1); //pitch
                storer[counter][2] = (double) Math.abs(x2 - x1) / beatWidth; //duration
            }
            counter++;
        }
        // sort notes into onset order
        quickSort(storer, 0, storer.length - 1);

        // put notes into a phrase
        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++;
            if (currentChannel > 15) currentChannel = scoreChannels;
View Full Code Here

      /* Enumerate through all phrases */
            Enumeration enum2 = part.getPhraseList().elements();
            int phraseCounter = 0;
            while (enum2.hasMoreElements()) {
                Phrase phr = (Phrase) enum2.nextElement();
                //get phrase tempo
                double phrase_ratio = part_ratio;
                if (phr.getTempo() > 0.0) {
                    System.out.println("A: " + phrase_ratio);
                    phrase_ratio = 60.0 / phr.getTempo();
                    System.out.println("B: " + phrase_ratio);
                }
        /* Get the instrument being used for this phrase */
                if (phr.getInstrument() != NO_INSTRUMENT) {
                    try {
                        // add phrase instrument to stack
                        inst.push(instList[phr.getInstrument()]);
                    } catch (ArrayIndexOutOfBoundsException npe) {
                        System.out.println("jMusic Audio warning: Can't find the instrument number " +
                                phr.getInstrument() + " that you have specified for" +
                                " the phrase named " + phr.getTitle() + ".");
                    }
                }
                double time = part_ratio * phr.getStartTime(); //start time of phrase
                double ntime = 0.0; //notes distance from phrases start time
                Enumeration enum3 = phr.getNoteList().elements();
                System.out.print("    Phrase " + phraseCounter++ + " '" + phr.getTitle() + "'" +
                        " starting at beat " + phr.getStartTime() + ": ");

                /* 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);
                    currInst.iterateChain();
                    ntime += phrase_ratio * note.getRhythmValue();
                }

                System.out.println();
                // remove phrase instrument from stack
                if (phr.getInstrument() != NO_INSTRUMENT) inst.pop();
            }

        }
    }
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.