Package com.music.model

Examples of com.music.model.Chord


            List<ToneType> firstToneTypes = new ArrayList<>();
            boolean interMeasureChord = false;
            double measureChordLength = 0;
            boolean canHaveInterMeasureChords = ctx.getMetre()[0] > 3 && ctx.getMetre()[0] % 4 == 0;

            Chord chord = null;
            for (int i = 0; i < notes.length; i++) {
                // shuffle every time, so that we don't always get the same chord for a given note
                Collections.shuffle(scaleChords, random);
                Collections.shuffle(scaleSeventhChords, random);
                Collections.shuffle(scaleOtherChords, random);

                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
                }
                // inter-measure chords only for even-numbered, compound metres
                if (canHaveInterMeasureChords && currentMeasureSize == 0) {
                    interMeasureChord = Chance.test(18);
                }
                double chordLength = interMeasureChord ? normalizedMeasureSize / 2 : normalizedMeasureSize;
                boolean isHalfMeasure = currentMeasureSize == normalizedMeasureSize / 2;

                if (currentNote.getPitch() == 0) {
                    logger.warn("Pitch is 0 in main part.");
                    continue;
                }
                if (!currentNote.isRest() && (currentMeasureSize == 0 || (interMeasureChord && isHalfMeasure))) {
                    boolean preferStable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.UNSTABLE);
                    boolean preferUnstable = ToneResolver.needsContrastingChord(firstToneTypes, ToneGroups.STABLE);
                    Chord previous = chord;
                    chord = ChordUtils.getChord(ctx, currentNote.getPitch(), previous, scaleChords, scaleSeventhChords, scaleOtherChords, preferStable, preferUnstable);
                    if (chord != null && Chance.test(90)) {
                        if (Chance.test(20)) { // change the special note type
                            if (Chance.test(60)) { // to a new value
                                specialNoteType = SpecialNoteType.values()[random.nextInt(SpecialNoteType.values().length)];
View Full Code Here


    private int[] getRandomChord(ExtendedPhrase phrase, ScoreContext ctx, int pitch) {
        // making a copy, so that the original is not shuffled
        List<Chord> list = new ArrayList<>(ChordUtils.chords.get(phrase.getScale()));
        Collections.shuffle(list, random);
        Chord chord = ChordUtils.getChord(ctx, pitch, null, list, null, null, false, false);
        if (chord != null) {
            return chord.getPitches();
        } else {
            return null;
        }
    }
View Full Code Here

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

                // transpose back to the current key (+ctx.getKeyNote())
                int root = pitch - chordDefPitches[currentNoteIdx] + chordDefPitches[0] + ctx.getKeyNote();
                for (int i = 0; i < chordDefPitches.length; i++) {
                    chord[i] = root + (chordDefPitches[i] - chordDefPitches[0]) + ctx.getKeyNote();
                }
                Chord eligibleChord = new Chord();
                eligibleChord.setPitches(chord);
                eligibleChord.setFirstToneType(chordDef.getFirstToneType());
                eligibleChord.setChordType(chordDef.getChordType());

                if (invert) {
                    // sometimes invert all but the root, other times - only the final note(s)
                    for (int i = (Chance.test(50) ? 1 : 2); i < eligibleChord.getPitches().length; i ++) {
                        eligibleChord.getPitches()[i] = eligibleChord.getPitches()[i] - 12;
                    }
                }

                if (trimMiddleNote) {
                    ArrayUtils.remove(eligibleChord.getPitches(), 1);
                }

                // if the current chord doesn't match the preferences, store it as a temp result and continue
                if (preferStable && !ToneGroups.STABLE.getToneTypes().contains(eligibleChord.getFirstToneType())) {
                    alternativeEligibleChords.add(eligibleChord);
                    continue;
                }

                if (preferUnstable && !ToneGroups.UNSTABLE.getToneTypes().contains(eligibleChord.getFirstToneType())) {
                    alternativeEligibleChords.add(eligibleChord);
                    continue;
                }
                eligibleChords.add(eligibleChord);
            }
        }
        for (Iterator<Chord> it = eligibleChords.iterator(); it.hasNext();) {
            Chord chord = it.next();
            if (isDisallowedInProgression(chord, previousChord) && Chance.test(95)) {
                it.remove();
                if (alternativeEligibleChords.isEmpty()) {
                    alternativeEligibleChords.add(chord);
                }
            }
        }

        Chord result = null;
        if (!eligibleChords.isEmpty()) {
            result = eligibleChords.get(random.nextInt(eligibleChords.size()));
        } else  if (eligibleChords.isEmpty() && !alternativeEligibleChords.isEmpty()) { // if no suitable chord is found that matches the preferences, but there's one that's otherwise suitable, return it
            result = alternativeEligibleChords.get(random.nextInt(alternativeEligibleChords.size()));
        }
View Full Code Here

                            otherChordDef = Chords.AUGMENTED; // nothing specific - use default
                        }

                        if (chordDef != null) { // chords in some scales (e.g. Turkish) may not be classified in the above 4 groups. Skip those
                            ToneType firstToneType = ToneType.forDegree(Arrays.binarySearch(scale.getDefinition(), note));
                            Chord chord = getChordDef(note, chordDef);
                            chord.setChordType(ChordType.values()[chordType]);
                            chord.setFirstToneType(firstToneType);
                            scaleChords.add(chord);

                            Chord seventhChord = getChordDef(note, seventhChordDef);
                            seventhChord.setFirstToneType(firstToneType);
                            chord.setChordType(ChordType.values()[chordType]);
                            scaleSeventhChords.add(seventhChord);

                            Chord otherChord = getChordDef(note, otherChordDef);
                            otherChord.setFirstToneType(firstToneType);
                            chord.setChordType(ChordType.values()[chordType]);
                            scaleOtherChords.add(otherChord);
                        }
                    }
                }
View Full Code Here

        int[] chordPitches = new int[chordDef.length + 1];
        chordPitches[0] = note;
        for (int k = 0; k < chordDef.length; k++) {
            chordPitches[k + 1] = chordPitches[0] + chordDef[k];
        }
        Chord chord = new Chord();
        chord.setPitches(chordPitches);
        return chord;
    }
View Full Code Here

TOP

Related Classes of com.music.model.Chord

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.