Package jm.music.data

Examples of jm.music.data.Phrase


        Part timpaniPart = ctx.getParts().get(PartType.TIMPANI);
        if (timpaniPart == null) {
            return;
        }

        Phrase phrase = new Phrase();
        for (int i = 0; i < ctx.getMeasures(); i++) {
            if (Chance.test(20)) {
                phrase.add(getNote(ctx, ToneType.TONIC));
                phrase.add(getNote(ctx, ToneType.MEDIANT));
                if (Chance.test(20)) {
                    phrase.add(getNote(ctx, ToneType.TONIC));
                } else {
                    phrase.addRest(new Rest(ctx.getNormalizedMeasureSize() / 4));
                }
                phrase.addRest(new Rest(ctx.getNormalizedMeasureSize() / 4));
            } else {
                phrase.addRest(new Rest(ctx.getNormalizedMeasureSize()));
            }
        }
        phrase.setDynamic(100);
        timpaniPart.add(phrase);
    }
View Full Code Here


                if (Chance.test(8)) {
                    percussions = getRandomPercussionPattern();
                }
                // don't use the drums in some measures
                if (Chance.test(6)) {
                    Phrase phr = new Phrase(0.0);
                    phr.addRest(new Rest(ctx.getNormalizedMeasureSize()));
                    fullKit.add(phr);
                    continue;
                }

                for (int j = 0; j < percussions.length; j++) {
                    Phrase phr = new Phrase(0.0);
                    for (short k = 0; k < 16; k++) {
                        int[] chances = PRIMARY_DRUM_PERCENTAGES;
                        if (j % 2 == 1 || percussions[j] == 46) {
                            chances = SECONDARY_DRUM_PERCENTAGES;
                        }
                        if ((useMiddleBeats && k % 2 == 1 && Chance.test(6)) || Chance.test(chances[k / 2])) {
                            Note note = NoteFactory.createNote(percussions[j], beatNoteLength);
                            if (k % 2 == 1) {
                                note.setDynamic(35 + random.nextInt(8));
                            } else {
                                note.setDynamic(45 + random.nextInt(10));
                            }
                            phr.addNote(note);
                        } else {
                            phr.addRest(new Rest(beatNoteLength));
                        }
                    }
                    fullKit.add(phr);
                }
View Full Code Here

                } else { // reset
                    specialNoteType = null;
                }
            }

            Phrase arpeggioPhrase = new Phrase();
            arpeggioPhrase.setTitle("Arpeggio phrase");
            Scale currentScale = ((ExtendedPhrase) phrase).getScale();
            // get copies of the static ones, so that we can shuffle them without affecting the original
            List<Chord> scaleChords = new ArrayList<Chord>(ChordUtils.chords.get(currentScale));
            Collections.shuffle(scaleChords, random);
            Note[] notes = phrase.getNoteArray();
            List<ToneType> firstToneTypes = new ArrayList<>();

            int measures = 0;
            Note[] currentNotes = null;
            boolean useTwoNoteChords = Chance.test(14);
            Chord chord = null;
            for (int i = 0; i < notes.length; i++) {
                Note currentNote = notes[i];
                if (currentNote.getRhythmValue() == 0) {
                    continue; // rhythm value is 0 for the first notes of a (main-part) chord. So progress to the next
                }
                boolean lastMeasure = measures == ctx.getMeasures() - 1;
                if (currentMeasureSize == 0 && !currentNote.isRest() && !lastMeasure) {
                    boolean preferStable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.UNSTABLE);
                    boolean preferUnstable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.STABLE);
                    // change the chord only in 1/4 of the cases
                    if (currentNotes == null || Chance.test(25)) {
                        // no alternatives for now - only 3-note chords
                        Chord previous = chord;
                        chord = ChordUtils.getChord(ctx, currentNote.getPitch(), previous, scaleChords, scaleChords, scaleChords, preferStable, preferUnstable);
                        if (chord != null) {
                            int[] pitches = chord.getPitches();
                            //remove the middle note in some cases (but make it possible to have three-note chords in a generally two-note phrase)
                            if (pitches.length == 3 && useTwoNoteChords && Chance.test(90)) {
                                pitches = ArrayUtils.remove(pitches, 1);
                            }
                            int count = Chance.test(90) ? (Chance.test(80) ? 4 : 2) : (Chance.test(80) ? 3 : 5);

                            currentNotes = new Note[count];
                            double length = normalizedMeasureSize / count;
                            for (int k = 0; k < count; k++) {
                                Note note = NoteFactory.createNote(pitches[random.nextInt(pitches.length)], length);
                                note.setDynamic(InstrumentGroups.getInstrumentSpecificDynamics(65 + random.nextInt(10), part.getInstrument()));
                                if (specialNoteType != null) {
                                    note.setDuration(note.getRhythmValue() * specialNoteType.getValue());
                                }
                                currentNotes[k] = note;
                            }

                        }
                    }
                    if (Chance.test(85) && currentNotes != null) {
                        for (Note note : currentNotes) {
                            arpeggioPhrase.addNote(note);
                        }
                    } else {
                        arpeggioPhrase.addRest(new Rest(normalizedMeasureSize));
                    }
                } else if (currentMeasureSize == 0 && (currentNote.isRest() || lastMeasure)) {
                    arpeggioPhrase.addRest(new Rest(normalizedMeasureSize));
                }

                currentMeasureSize += currentNote.getRhythmValue();
                if (currentMeasureSize >= normalizedMeasureSize) {
                    currentMeasureSize = 0;
View Full Code Here

        }
        Note[] droneNotes = null;
        Part mainPart = ctx.getParts().get(PartType.MAIN);
        Phrase[] phrases = mainPart.getPhraseArray();
        for (Phrase phrase : phrases) {
            Phrase dronePhrase = new Phrase();
            if (!(phrase instanceof ExtendedPhrase) || Chance.test(17)) { // skip the drone for some phrases
                continue;
            }

            ExtendedPhrase ePhrase = (ExtendedPhrase) phrase;

            // change the drone type
            if (droneNotes == null || ePhrase.getScale() == ctx.getAlternativeScale() || Chance.test(10)) {
                droneNotes = getDroneNotes(ePhrase.getScale(), ctx.getKeyNote(), ctx.getNormalizedMeasureSize(), ePhrase.getMeasures(), dronePart.getInstrument());
            }

            // if one note is held the entire time;
            if (droneNotes.length == 1) {
                dronePhrase.addNote(droneNotes[0]);
            } else {
                for (int i = 0; i < ePhrase.getMeasures(); i++) {
                    dronePhrase.addNoteList(droneNotes);
                }
            }
            dronePart.add(dronePhrase);
        }
    }
View Full Code Here

    public void handleScore(Score score, ScoreContext ctx) {
        Part effectsPart = ctx.getParts().get(PartType.EFFECTS);
        if (effectsPart == null) {
            return;
        }
        Phrase phrase = new Phrase();
        int restPercentage = Chance.test(65) ? 75 : 15; //sporadic vs regular
        for (int i = 0; i < ctx.getMeasures(); i++) {
            handleEffects(ctx, phrase, restPercentage);
        }
        effectsPart.add(phrase);
View Full Code Here

    public void handleScore(Score score, ScoreContext ctx) {
        Part drumPart = ctx.getParts().get(PartType.SIMPLE_BEAT);
        if (drumPart == null) {
            return;
        }
        Phrase phrase = new Phrase();
        boolean needsBass = Chance.test(80);
        boolean hasBass = ctx.getParts().get(PartType.BASS) != null;
        // "four on the floor" in case of faster pieces that (in most cases) have a bass
        if (PartConfigurer.isRegularMetre(ctx) && Chance.test(50) && ctx.getParts().get(PartType.PERCUSSIONS) == null && score.getTempo() > 115 && (needsBass ? hasBass : true)) {
            ctx.setFourToTheFloor(true);
            drumPart.setChannel(9);
            for (int i = 0; i < ctx.getMeasures(); i++) {
                for (int k = 0; k < 4; k++) {
                    Note note = NoteFactory.createNote(35 + k % 2, ctx.getNormalizedMeasureSize() / 4);
                    phrase.add(note);
                }
            }
        } else {
            for (int i = 0; i < ctx.getMeasures(); i++) {
                Note note = NoteFactory.createNote(40 + random.nextInt(30), ctx.getNormalizedMeasureSize() / 4);
                phrase.add(note);
                phrase.add(new Rest(ctx.getNormalizedMeasureSize() - note.getRhythmValue()));
            }
        }

        drumPart.add(phrase);
View Full Code Here

            ExtendedPhrase extPhrase = ((ExtendedPhrase) phrase);
            Scale currentScale = extPhrase.getScale();
            if (currentScale.getDefinition().length != 7) { //no bass for irregular scales, for now
                continue;
            }
            Phrase bassPhrase = new Phrase();
            for (int i = 0; i < extPhrase.getMeasures(); i++) {
                for (int k = 0; k < 2; k++) {
                    if (Chance.test(70)) {
                        int degreeIdx = 0;
                        if (dullBass) {
                            degreeIdx = Chance.choose(dullBassPercentages);
                        } else {
                            degreeIdx = Chance.choose(degreePercentages);
                        }
                        Note note = NoteFactory.createNote(JMC.C3 + ctx.getKeyNote() + currentScale.getDefinition()[degreeIdx], ctx.getNormalizedMeasureSize() / 2);
                        note.setDynamic(InstrumentGroups.getInstrumentSpecificDynamics(60 + random.nextInt(15), bassPart.getInstrument()));
                        if (durationModifier > 0) {
                            note.setDuration(note.getRhythmValue() * durationModifier);
                        }
                        bassPhrase.addNote(note);
                    } else {
                        bassPhrase.addRest(new Rest(ctx.getNormalizedMeasureSize() / 2));
                    }
                }
            }
            bassPart.addPhrase(bassPhrase);
        }
View Full Code Here

                /////////////////////////////////////////////////
                // Each phrase represents a new Track element
                // Err no
                // There is a 65? track limit
                // ////////////////////////////
                Phrase phrase = (Phrase) phrases.nextElement();

                //Track currTrack = sequence.createTrack();

                currentTime = phrase.getStartTime();
                long phraseTick = (long) (currentTime * m_ppqn * trackTempoRatio);
                MidiEvent evt;

                if (phrase.getInstrument() != NO_INSTRUMENT) instrument = phrase.getInstrument();
                evt = createProgramChangeEvent(currChannel, instrument, phraseTick);
                currTrack.add(evt);

                m_tempoHistory.push(new Float(m_currentTempo));

                tempo = new Float(phrase.getTempo()).floatValue();
                if (tempo != Phrase.DEFAULT_TEMPO) {
                    m_currentTempo = tempo;
                    //System.out.println("jMusic MidiSynth notification: Phrase TempoEvent (BPM) = " + tempo);
                }

                elementTempoRatio = m_masterTempo / m_currentTempo;

                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);

 
View Full Code Here

            for (int i = 0; i < numOfNotes; i++) {
                noteList[i].setDynamic(retDynamic[i]);
            }
        }

        Phrase phrase = new Phrase();
        phrase.addNoteList(noteList);
        return phrase;
    }
View Full Code Here

            return new Score(elementToPart(elements[0]));
        } else if (XMLStyles.isValidPhraseTag(elements[0].getName())) {
            return new Score(new Part(elementToPhrase(elements[0])));
        } else if (XMLStyles.isValidNoteTag(elements[0].getName())) {
            return new Score(new Part(
                    new Phrase(elementToNote(elements[0]))));
        }
        throw new ConversionException("Unrecognised root element: "
                + elements[0].getName());
    }
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.