Package jm.music.data

Examples of jm.music.data.Note


     * Ends the motif in a stable tone
     * @param repeatedNotes
     * @param lCtx
     */
    private void stabilize(List<Note> repeatedNotes, MainPartContext lCtx) {
        Note lastNote = repeatedNotes.get(repeatedNotes.size() - 1);
        // if already stable, make it the tonic. If not stable - resolve.
        if (ToneResolver.isStable(lastNote.getPitch(), lCtx.getCurrentScale())) {
            lastNote.setPitch(ToneResolver.resolveToTonic(lastNote.getPitch(), lCtx.getCurrentScale()));
        } else {
            lastNote.setPitch(ToneResolver.resolve(lastNote.getPitch(), lCtx.getCurrentScale()));
        }
    }
View Full Code Here


                    }
                    double lengthToBeat = getLengthToNextDownBeat(lCtx, lCtx.getNormalizedMeasureSize(), measureSize + replacementSize, length, groupSize);
                    if (lengthToBeat != -1 && lengthToBeat < length) {
                        length = lengthToBeat;
                    }
                    Note replacementNote = createNote(lCtx, false, length);
                    // keep the last note of each measure
                    if (measureSize + length >= ctx.getNormalizedMeasureSize()) {
                        replacementNote = note;
                    }
View Full Code Here

        boolean firstNotes = Chance.test(60);
        int erasedNotes = 1 + random.nextInt(3);
        int erasedCounter = 0;
        for (int i = 0; i < repeatedNotes.size(); i ++) {
            if (firstNotes || Chance.test(erasedNotes * 100 / repeatedNotes.size())) {
                Note removed = repeatedNotes.remove(i);
                repeatedNotes.add(i, new Rest(removed.getRhythmValue()));
                erasedCounter++;
            }
            if (erasedCounter >= erasedNotes) {
                break;
            }
View Full Code Here

    }

    void retrograde(List<Note> repeatedNotes) {
        // reverse the pitches
        for (int i = 0; i < repeatedNotes.size() / 2; i ++) {
            Note note = repeatedNotes.get(i);
            Note mirrorNote = repeatedNotes.get(repeatedNotes.size() - 1 - i);
            int pitch = note.getPitch();
            note.setPitch(mirrorNote.getPitch());
            mirrorNote.setPitch(pitch);
        }
    }
View Full Code Here

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

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

                        }
View Full Code Here

        boolean hold = Chance.test(20);
        int notesPerMeasure = (int) Math.pow(2, 0 + random.nextInt(4));
        List<Note> notes = new ArrayList<>();
        double noteLength = normalizedMeasureSize / notesPerMeasure;
        if (singleNote && hold) {
            Note note = NoteFactory.createNote(Pitches.C5 + keyNote, normalizedMeasureSize * measures);
            note.setDynamic(InstrumentGroups.getInstrumentSpecificDynamics(55, instrument));
            notes.add(note);
        } else if (singleNote) {
            for (int i = 0; i < notesPerMeasure; i++) {
                Note note = NoteFactory.createNote(Pitches.C5 + keyNote, noteLength);
                note.setDynamic(InstrumentGroups.getInstrumentSpecificDynamics(55, instrument));
                notes.add(note);
            }
        } else {
            int pitch = Pitches.C5 + keyNote;
            for (int i = 0; i < notesPerMeasure; i++) {
                Note note = NoteFactory.createNote(pitch, noteLength);
                note.setDynamic(InstrumentGroups.getInstrumentSpecificDynamics(50, instrument));
                notes.add(note);
                boolean directionUp = random.nextBoolean();
                int step = random.nextInt(3);
                int toneDegree = Arrays.binarySearch(scale.getDefinition(), pitch % 12);
                if (toneDegree > 0) {
View Full Code Here

            phrase.addRest(new Rest(ctx.getNormalizedMeasureSize()));
        } else {
            int pitch = getRandomPitch(ctx);
            double effectLength = random.nextDouble() * ctx.getNormalizedMeasureSize();
            effectLength = Math.min(effectLength, ctx.getNormalizedMeasureSize());
            Note note = NoteFactory.createNote(pitch, effectLength);
            phrase.add(note);
            double lastRest = ctx.getNormalizedMeasureSize() - effectLength;
            if (lastRest > 0) {
                phrase.add(new Rest(lastRest));
            }
View Full Code Here

        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

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