/// <summary> /// Returns true if this note should be avoided in pentatonic scales. /// </summary> /// <param name="noteIN"></param> /// <returns></returns> private bool IsPentatonicAvoid(int noteIN) { int note = MusicHelpers.SafeLoop(noteIN - 1, Instrument.mScaleLength); int progressionstep = mInstrument.mCurrentProgressionStep < 0 ? mInstrument.mCurrentProgressionStep * -1 : mInstrument.mCurrentProgressionStep; // currently does not respect modal changes and avoids the interval instead. add mMusicGenerator.mGeneratorData.mMode to change with modes int scaleNote = MusicHelpers.SafeLoop(note + progressionstep, Instrument.mScaleLength); if (mIsStandardPentatonic) { if (mMusicGenerator.mGeneratorData.mScale == eScale.Major || mMusicGenerator.mGeneratorData.mScale == eScale.HarmonicMajor) { return(scaleNote == mMajorPentatonicAvoid[0] || scaleNote == mMajorPentatonicAvoid[1]); } else if (mMusicGenerator.mGeneratorData.mScale == eScale.NatMinor || mMusicGenerator.mGeneratorData.mScale == eScale.HarmonicMinor || mMusicGenerator.mGeneratorData.mScale == eScale.mMelodicMinor) { return(scaleNote == mMinorPentatonicAvoid[0] || scaleNote == mMinorPentatonicAvoid[1]); } } else { return((mAvoidNotes[0] > 0 && scaleNote == mAvoidNotes[0]) || (mAvoidNotes[1] > 0 && scaleNote == mAvoidNotes[1])); } return(false); }
/// Sets our lead avoid notes from data. public void SetLeadAvoidNotes() { int avoid1 = mInstrument.mData.mLeadAvoidNotes[0] >= 0 ? MusicHelpers.SafeLoop(mInstrument.mData.mLeadAvoidNotes[0] + 1, 7) : -1; int avoid2 = mInstrument.mData.mLeadAvoidNotes[1] >= 0 ? MusicHelpers.SafeLoop(mInstrument.mData.mLeadAvoidNotes[1] + 1, 7) : -1; for (int i = 0; i < mLeadAvoidSteps.Length; i++) { mLeadAvoidSteps[i].isOn = i == avoid1 || i == avoid2 ? true : false; } }
/// <summary> /// Checks for out of range notes in our list and forces it back within range. /// </summary> private void CheckValidity() { if (mProgressionNotes.Length != mSeventhChord.Length) { throw new Exception("We haven't fully filled our note array. Something has gone wrong."); } for (int i = 0; i < mProgressionNotes.Length; i++) { int note = mProgressionNotes[i]; int clipArraySize = MusicGenerator.mMaxInstrumentNotes; if (note == mUnplayed || (note < clipArraySize && note >= mUnplayed)) { continue; } if (note < 0) { note = MusicHelpers.SafeLoop(note, mOctave); } else if (note >= clipArraySize) { note = MusicHelpers.SafeLoop(note, mOctave); note += (mData.mUsePattern && mbAreRepeatingPattern) ? mCurrentPatternOctave[i] * mOctave : 2 * mOctave; } /// if somehow this is still out of range, we've utterly broken things... if (note < 0 || note > clipArraySize) { Debug.Log("something's gone wrong note is out of range."); note = 0; } mProgressionNotes[i] = note; } }
/// <summary> /// Returns true if this lead note is a half step above a chord note: /// </summary> /// <param name="noteIN"></param> /// <returns></returns> private bool IsAvoidNote(int noteIN) { if (IsPentatonicAvoid(noteIN)) { return(true); } int note = MusicHelpers.SafeLoop(noteIN - 1, Instrument.mScaleLength); int progressionstep = mInstrument.mCurrentProgressionStep < 0 ? mInstrument.mCurrentProgressionStep * -1 : mInstrument.mCurrentProgressionStep; int scaleNote = MusicHelpers.SafeLoop(note + (int)mMusicGenerator.mGeneratorData.mMode + progressionstep, Instrument.mScaleLength); int[] scale = Instrument.mMusicScales[(int)mMusicGenerator.mGeneratorData.mScale]; bool isHalfStep = scale[scaleNote] == Instrument.mHalfStep; bool isAboveChordNode = (note == Instrument.mSeventhChord[0] || note == Instrument.mSeventhChord[1] || note == Instrument.mSeventhChord[2] || (note == Instrument.mSeventhChord[3] && mInstrument.mData.ChordSize == Instrument.mSeventhChord.Length)); bool isSeventh = (mInstrument.mData.ChordSize != Instrument.mSeventhChord.Length && note == Instrument.mSeventhChord[3] - 1); return((isHalfStep && isAboveChordNode) || isSeventh); }
/// Updates data values from UI settings for lead avoid notes. public void UpdateLeadAvoidNotes() { if (mInstrument.mData.mSuccessionType != eSuccessionType.lead) { for (int i = 0; i < mLeadAvoidSteps.Length; i++) { mInstrument.mData.mLeadAvoidNotes[0] = -1; mInstrument.mData.mLeadAvoidNotes[1] = -1; } return; } int[] majorPent = NoteGenerator_Lead.mMajorPentatonicAvoid; int[] minorPent = NoteGenerator_Lead.mMinorPentatonicAvoid; // If our 'standard' pentatonic is enabled, force values to generic pentatonic. if (mPentatonic.isOn) { if (mMusicGenerator.mGeneratorData.mScale == eScale.Major || mMusicGenerator.mGeneratorData.mScale == eScale.HarmonicMajor) { mInstrument.mData.mLeadAvoidNotes[0] = majorPent[0]; mInstrument.mData.mLeadAvoidNotes[1] = majorPent[1]; for (int i = 0; i < mLeadAvoidSteps.Length; i++) { bool isOn = i == majorPent[0] + 1 || i == majorPent[1] + 1 ? true : false; mLeadAvoidSteps[i].isOn = isOn; } } else if (mMusicGenerator.mGeneratorData.mScale == eScale.NatMinor || mMusicGenerator.mGeneratorData.mScale == eScale.HarmonicMinor || mMusicGenerator.mGeneratorData.mScale == eScale.mMelodicMinor) { mInstrument.mData.mLeadAvoidNotes[0] = minorPent[0]; mInstrument.mData.mLeadAvoidNotes[1] = minorPent[1]; for (int i = 0; i < mLeadAvoidSteps.Length; i++) { mLeadAvoidSteps[i].isOn = i == minorPent[0] + 1 || i == minorPent[1] + 1 ? true : false; } } else { mPentatonic.isOn = false; } return; } int index = 0; mInstrument.mData.mLeadAvoidNotes[0] = -1; mInstrument.mData.mLeadAvoidNotes[1] = -1; // otherwise set custom avoid notes for (int i = 0; i < mLeadAvoidSteps.Length; i++) { if (mLeadAvoidSteps[i].isOn) { if (index < 2) { mInstrument.mData.mLeadAvoidNotes[index] = MusicHelpers.SafeLoop(i - 1, 7); index++; } else { mLeadAvoidSteps[i].isOn = false; } } } }