Beispiel #1
0
        private void FinalizeStagingClip()
        {
            mCurrentInstSet = mLoadedClip.mInstrumentSet;

            InstrumentListPanelUI listPanel = InstrumentListPanelUI.Instance;

            for (int i = 0; i < mCurrentInstSet.mInstruments.Count; i++)
            {
                listPanel.AddInstrument(mCurrentInstSet.mInstruments[i]);
                InstrumentListUIObject icon = listPanel.mInstrumentIcons[listPanel.mInstrumentIcons.Count - 1];
                icon.ToggleSelected();
                bool isPercussion = icon.mInstrument.mData.InstrumentType.Contains("p_") ? true : false;
                icon.SetDropdown(isPercussion);

                InstrumentPanelUI.Instance.SetInstrument(icon.mInstrument);
                mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[i];
            }
            InstrumentPanelUI.Instance.SetInstrument(mCurrentInstSet.mInstruments[0]);
            mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[0];

            mClipIsRepeating.isOn = mLoadedClip.mIsRepeating;
            mCurrentMeasure.value = 0;
            mLoadedClip.SetState(eClipState.Stop);
            mMusicGenerator.ClipLoaded.Invoke(mCurrenClipSave);
            mMusicGenerator.ResetPlayer();
            mMusicGenerator.SetState(eGeneratorState.editing);
            ToggleHelperNotes();
            UIToggleAllInstruments();
            mStaffPlayer.ChangeTimeSignature((int)mCurrentInstSet.mTimeSignature.Signature);
        }
Beispiel #2
0
        /// Changes our time signature.
        public void ChangeTimeSignature(int timeSignature = -1)
        {
            if (timeSignature != -1)             //if we're actually trying to force the ui to change. The UI will pass in -1.
            {
                mTimeSignatureDropdown.value = timeSignature;
                return;
            }
            eTimeSignature signature = (eTimeSignature)mTimeSignatureDropdown.value;

            InstrumentSet set = (MusicGenerator.Instance.mState >= eGeneratorState.editorInitializing) ? mMeasureEditor.mCurrentInstSet : MusicGenerator.Instance.mInstrumentSet;

            set.SetTimeSignature(signature);

            float xPos    = mBarLines[0].localPosition.x;
            float nextPos = mTotalBarlineDistance / (set.mTimeSignature.mStepsPerMeasure - 1);

            for (int i = 0; i < mBarLinesImages.Count; i++)
            {
                if (i < set.mTimeSignature.mStepsPerMeasure)
                {
                    mBarLinesImages[i].enabled = true;
                    Vector3 pos = mBarLines[i].localPosition;
                    mBarLines[i].localPosition = new Vector3(xPos, pos.y, pos.z);
                    xPos += nextPos;
                }
                else
                {
                    mBarLinesImages[i].enabled = false;
                }
            }
        }
Beispiel #3
0
        /// Updates our chord progression text
        private void UpdateChordProgressionText(InstrumentSet set)
        {
            bool dirty = false;

            for (int i = 0; i < mMusicGenerator.ChordProgression.Length; i++)
            {
                if (mCurrentChordProgression[i] != mMusicGenerator.ChordProgression[i])
                {
                    mCurrentChordProgression[i] = mMusicGenerator.ChordProgression[i];
                    dirty = true;
                }
            }
            int stepsTaken = set.ProgressionStepsTaken >= 0 ? set.ProgressionStepsTaken : 0;

            if (mCurrentChordProgression[stepsTaken] != mCurrentStep)
            {
                mCurrentStep = mCurrentChordProgression[stepsTaken];
                dirty        = true;
            }

            if (dirty)
            {
                mCurrentProgStep.text = "{" +
                                        mCurrentChordProgression[0] + "-" +
                                        mCurrentChordProgression[1] + "-" +
                                        mCurrentChordProgression[2] + "-" +
                                        mCurrentChordProgression[3] + "}" + " :" +
                                        mCurrentStep;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Async loads the instrument data.
        /// </summary>
        /// <param name="argResourceDirectory"></param>
        /// <returns></returns>
        public IEnumerator AsyncLoadInstrumentsData(string argResourceDirectory)
        {
            ///Load the instruments:
            InstrumentSet set = MusicGenerator.Instance.mInstrumentSet;

            for (int i = 0; i < MusicGenerator.mMaxInstruments; i++)
            {
                string path = MusicFileConfig.GetConfigDirectory(argResourceDirectory) + "/instruments" + i.ToString() + ".txt";
                if (File.Exists(path))
                {
                    InstrumentData instrumentData = InstrumentData.LoadData(argResourceDirectory, "/instruments" + i.ToString() + ".txt");
                    if (instrumentData == null)
                    {
                        yield break;
                    }
                    MusicGenerator.Instance.AddInstrument(set);
                    yield return(null);

                    set.mInstruments[set.mInstruments.Count - 1].LoadInstrument(instrumentData);
                    int index = 999;
                    yield return(StartCoroutine(MusicGenerator.Instance.AsyncLoadBaseClips(set.mInstruments[set.mInstruments.Count - 1].mData.InstrumentType, ((x) => { index = x; }))));

                    set.mInstruments[set.mInstruments.Count - 1].InstrumentTypeIndex = index;
                }
            }
            yield return(null);
        }
Beispiel #5
0
        // Update is called once per frame
        void Update()
        {
            if (mMusicGenerator == null)
            {
                return;
            }
            if (mFileCurrentlyWriting != "")
            {
                bool completed = MusicHelpers.CheckClipwriteComplete(mFileCurrentlyWriting);
                if (completed)
                {
                    Debug.Log(mFileCurrentlyWriting + " clip save complete");
                    AddPresetOption(mFileCurrentlyWriting + ".txt");
                    mFileCurrentlyWriting   = "";
                    mPlayClipDropdown.value = mPlayClipDropdown.options.Count - 1;
                }
            }

            else if (mMusicGenerator.mState >= eGeneratorState.editorInitializing)
            {
                InstrumentSet instrumentSet = mLoadedClip.mInstrumentSet;
                instrumentSet.mData.Tempo = mTempo.value;
                mCurrentInstSet.mData.RepeatMeasuresNum = mNumberOfMeasures.value;
                mCurrentInstSet.mRepeatCount            = mCurrentMeasure.value;
                if (mInstrumentPanel.mInstrument != null)
                {
                    int currentInstIndex = (int)mInstrumentPanel.mInstrument.InstrumentIndex;
                    mStaffPlayer.SetEditorNotes(instrumentSet.mInstruments[currentInstIndex]);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Loads the data for an instrument.
        /// </summary>
        /// <param name="resourceDirectory"></param>
        private IEnumerator LoadInstrumentsData(string argDirectory, bool async = false)
        {
            UnitySystemConsoleRedirector.Redirect();
            InstrumentSet set = MusicGenerator.Instance.mInstrumentSet;

            for (int i = 0; i < MusicGenerator.mMaxInstruments; i++)
            {
                string path = "/instruments" + i.ToString() + ".txt";

                string data = null;
                yield return(MusicHelpers.GetUWR(mSavesPath + "/" + argDirectory + path, (x) => { data = x.downloadHandler.text; }));

                if (string.IsNullOrEmpty(data))
                {
                    yield break;
                }

                InstrumentData instrumentData = null;
                InstrumentData.LoadData(data, argDirectory, (x) => { instrumentData = x; });
                MusicGenerator.Instance.AddInstrument(set);
                set.mInstruments[set.mInstruments.Count - 1].LoadInstrument(instrumentData);
                int index = 0;
                if (async)
                {
                    yield return(StartCoroutine(MusicGenerator.Instance.AsyncLoadBaseClips(set.mInstruments[set.mInstruments.Count - 1].mData.InstrumentType, ((x) => { index = x; }))));
                }
                else
                {
                    index = MusicGenerator.Instance.LoadBaseClips(set.mInstruments[set.mInstruments.Count - 1].mData.InstrumentType);
                }
                set.mInstruments[set.mInstruments.Count - 1].InstrumentTypeIndex = index;
            }
            yield return(null);
        }
        /// <summary>
        /// Plays the notes for this timestep
        /// </summary>
        /// <param name="set"></param>
        /// <param name="instrument"></param>
        /// <param name="stepsTaken"></param>
        /// <param name="instIndex"></param>
        private void PlayNotes(InstrumentSet set, Instrument instrument, int stepsTaken, int instIndex)
        {
            // we want to fill this whether we play it or not:
            int progressionStep = set.mMusicGenerator.ChordProgression[stepsTaken];

            int[] clip = instrument.GetProgressionNotes(progressionStep);
            if (instrument.mData.StrumLength == 0.0f || instrument.mData.mSuccessionType != eSuccessionType.rhythm)
            {
                for (int j = 0; j < clip.Length; j++)
                {
                    if (clip[j] != InstrumentSet.mUnplayed)                     //we ignore -1
                    {
                        try
                        {
                            set.mMusicGenerator.PlayAudioClip(set, (int)instrument.InstrumentTypeIndex, clip[j], instrument.mData.Volume, instIndex);
                            set.mMusicGenerator.UIStaffNotePlayed.Invoke(clip[j], (int)instrument.mData.mStaffPlayerColor);
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                            throw new ArgumentOutOfRangeException(e.Message);
                        }
                    }
                }
            }
            else
            {
                set.Strum(clip, instIndex);
            }
        }
Beispiel #8
0
 public NotePlayedArgs(InstrumentSet argSet, int argClipIndexX, int argClipIndexY, float argVolumeIN, int argInstrumentIndex)
 {
     set             = argSet;
     clipIndexX      = argClipIndexX;
     clipIndexY      = argClipIndexY;
     volume          = argVolumeIN;
     instrumentIndex = argInstrumentIndex;
 }
Beispiel #9
0
 public RepeatNoteArgs(int indexAIN, int indexBIN, int repeatingCountIN, int instrumentSubIndexIN, InstrumentSet setIN)
 {
     indexA             = indexAIN;
     indexB             = indexBIN;
     repeatingCount     = repeatingCountIN;
     instrumentSubIndex = instrumentSubIndexIN;
     instrumentSet      = setIN;
 }
        /// <summary>
        /// Sets our notes to repeat.
        /// </summary>
        private void SetRepeatNotes()
        {
            InstrumentSet set   = mMusicGenerator.mInstrumentSet;
            int           count = set.SixteenthStepsTaken + (set.mRepeatCount * set.mTimeSignature.mStepsPerMeasure);

            for (int i = 0; i < mProgressionNotes.Length; i++)
            {
                mRepeatingNotes[count][i] = mProgressionNotes[i];
            }
        }
Beispiel #11
0
        /// Destroys instrument.
        public void RemoveInstrument()
        {
            InstrumentSet set = (mMusicGenerator.mState >= eGeneratorState.editorInitializing) ? MeasureEditor.Instance.mCurrentInstSet : mMusicGenerator.mInstrumentSet;

            mMusicGenerator.RemoveInstrument((int)mInstrument.InstrumentIndex, set);
            mInstrumentListPanelUI.RemoveInstrument((int)mInstrument.InstrumentIndex);
            if (mbIsSelected)
            {
                mInstrumentPanelUI.mInstrument = null;
            }
            Destroy(this.gameObject);
        }
        /// <summary>
        /// Plays through the next step in the measure.
        /// </summary>
        /// <param name="set"></param>
        public override void PlayMeasure(InstrumentSet set)
        {
            if (set.mMusicGenerator == null)
            {
                return;
            }
            set.UpdateTempo();
            set.mSixteenthStepTimer -= Time.deltaTime;
            if (set.mSixteenthStepTimer <= 0 && set.SixteenthStepsTaken < set.mTimeSignature.mStepsPerMeasure)
            {
                set.mMusicGenerator.BarlineColorSet.Invoke(set.SixteenthStepsTaken, false);

                if (set.SixteenthStepsTaken % (int)set.mData.mProgressionRate == set.mTimeSignature.Whole)
                {
                    set.ProgressionStepsTaken += 1;
                    set.ProgressionStepsTaken  = set.ProgressionStepsTaken % set.mMusicGenerator.ChordProgression.Length;
                    set.mMusicGenerator.CheckKeyChange();
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Half == 0)
                {
                    TakeStep(set, eTimestep.eighth, set.ProgressionStepsTaken);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Quarter == 0)
                {
                    TakeStep(set, eTimestep.quarter, set.ProgressionStepsTaken);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Eighth == 0)
                {
                    TakeStep(set, eTimestep.half, set.ProgressionStepsTaken);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Sixteenth == 0)
                {
                    TakeStep(set, eTimestep.whole, set.ProgressionStepsTaken);
                    set.mMeasureStartTimer = 0.0f;
                }

                TakeStep(set, eTimestep.sixteenth, set.ProgressionStepsTaken);

                set.mSixteenthStepTimer  = set.mBeatLength;
                set.SixteenthStepsTaken += 1;
            }
            else if (set.SixteenthStepsTaken == set.mTimeSignature.mStepsPerMeasure)
            {
                set.mMeasureStartTimer += Time.deltaTime;

                if (set.mMeasureStartTimer > set.mBeatLength)                 //We don't actually want to reset until the next beat.
                {
                    set.mMusicGenerator.GenerateNewProgression();
                    ResetMeasure(set, set.mMusicGenerator.SetThemeRepeat);
                }
            }
        }
        private void StartInitialization(ClipSave save)
        {
            mInstrumentSet = new InstrumentSet();
            mInstrumentSet.Init();
            mInstrumentSet.LoadData(new InstrumentSetData());
            mTempo            = save.mTempo;
            mNumMeasures      = save.mNumberOfMeasures;
            mSixteenthMeasure = 60 / mTempo;
            mIsRepeating      = save.mClipIsRepeating;

            mInstrumentSet.mData.Tempo = mTempo;
            mInstrumentSet.SetProgressionRate(save.mProgressionRate);
            mInstrumentSet.mData.RepeatMeasuresNum = mNumMeasures;
        }
Beispiel #14
0
        /// Adds an instrument to our ui object list:
        public void AddInstrument(Instrument instrumentIN)
        {
            InstrumentSet     set         = (mMusicGenerator.mState >= eGeneratorState.editorInitializing) ? MeasureEditor.Instance.mCurrentInstSet : mMusicGenerator.mInstrumentSet;
            List <Instrument> instruments = set.mInstruments;

            if (instruments.Count <= MusicGenerator.mMaxInstruments)
            {
                mInstrumentIcons.Add((Instantiate(mInstrumentUIObjectBase, transform) as GameObject).GetComponent <InstrumentListUIObject>());
                InstrumentListUIObject icon = mInstrumentIcons[mInstrumentIcons.Count - 1];
                icon.Init(mMusicGenerator);
                icon.transform.position            = mAddInstrumentPoint.transform.position;
                mAddInstrumentPoint.localPosition -= new Vector3(0, mAddInstrumentPoint.rect.height * mIconPadding, 0);
                icon.mInstrument = instrumentIN;
                Color color = StaffPlayerUI.Instance.mColors[(int)icon.mInstrument.mData.mStaffPlayerColor];
                icon.mPanelBack.color = color;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Resets a regular measure.
        /// </summary>
        /// <param name="set"></param>
        /// <param name="SetThemeRepeat"></param>
        /// <param name="hardReset"></param>
        /// <param name="isRepeating"></param>
        protected void ResetRegularMeasure(InstrumentSet set, Action SetThemeRepeat = null, bool hardReset = false, bool isRepeating = true)
        {
            if (set.mMusicGenerator == null)
            {
                throw new ArgumentNullException("music generator does not exist. Please ensure a game object with this class exists");
            }

            set.mRepeatCount += 1;

            if (SetThemeRepeat != null)
            {
                SetThemeRepeat();
            }

            for (int i = 0; i < set.mInstruments.Count; i++)
            {
                set.mInstruments[i].ClearPatternNotes();
                set.mInstruments[i].ResetPatternStepsTaken();
                set.mInstruments[i].ClearPlayedLeadNotes();
                set.mInstruments[i].GenerateArpeggio();
            }
            set.SixteenthStepsTaken = 0;

            //select groups:
            set.SelectGroups();

            if (set.ProgressionStepsTaken >= InstrumentSet.mMaxFullstepsTaken - 1)
            {
                set.ProgressionStepsTaken = -1;
            }

            if (set.mMusicGenerator.mGeneratorData.mThemeRepeatOptions == eThemeRepeatOptions.eNone)
            {
                set.mRepeatCount = 0;
                for (int i = 0; i < set.mInstruments.Count; i++)
                {
                    set.mInstruments[i].ClearRepeatingNotes();
                }
            }

            set.mMeasureStartTimer  = 0.0f;
            set.mSixteenthStepTimer = 0.0f;

            set.ResetMultipliers();
        }
Beispiel #16
0
        /// non async changes the instrument.
        private bool NonAsyncInstrumentChange()
        {
            if (mMusicGenerator.mState < eGeneratorState.ready)
            {
                return(true);
            }

            InstrumentSet set = (mMusicGenerator.mState >= eGeneratorState.editorInitializing) ?
                                MeasureEditor.Instance.mCurrentInstSet : mMusicGenerator.mInstrumentSet;

            int    typeToRemove    = (int)mInstrument.InstrumentTypeIndex;
            int    instrumentIndex = 0;
            string name            = mInstrumentDropdown.options[mInstrumentDropdown.value].text;

            if (name == "dummyEntry")
            {
                return(false);
            }
            string instrumentType = mInstrumentDropdown.options[mInstrumentDropdown.value].text;

            instrumentType = instrumentType.ToLower();

            if (mMusicGenerator.LoadedInstrumentNames.Contains(instrumentType) == false)
            {
                instrumentIndex = mMusicGenerator.LoadBaseClips(instrumentType);
            }
            else
            {
                instrumentIndex = mMusicGenerator.LoadedInstrumentNames.IndexOf(instrumentType);
            }

            List <Instrument> instruments = set.mInstruments;

            int value = GetComponentInChildren <Dropdown>().value;

            if (mInstrument != null)
            {
                instruments[(int)mInstrument.InstrumentIndex].InstrumentTypeIndex  = instrumentIndex;
                instruments[(int)mInstrument.InstrumentIndex].mData.InstrumentType = instrumentType;
                mMuteToggle.isOn = instruments[(int)mInstrument.InstrumentIndex].mData.mIsMuted;
            }
            mMusicGenerator.RemoveBaseClip(typeToRemove, set);
            mMusicGenerator.CleanUpInstrumentTypeIndices(set);
            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// Loads the data for an instrument.
        /// </summary>
        /// <param name="folderIN"></param>
        private static void LoadInstrumentsData(string folderIN)
        {
            InstrumentSet set       = MusicGenerator.Instance.mInstrumentSet;
            string        configDir = GetConfigDirectory(folderIN);

            for (int i = 0; i < MusicGenerator.mMaxInstruments; i++)
            {
                string path = configDir + "/instruments" + i.ToString() + ".txt";
                if (File.Exists(path))
                {
                    InstrumentData instrumentData = InstrumentData.LoadData(folderIN, "/instruments" + i.ToString() + ".txt");
                    MusicGenerator.Instance.AddInstrument(set);
                    set.mInstruments[set.mInstruments.Count - 1].LoadInstrument(instrumentData);
                    int index = MusicGenerator.Instance.LoadBaseClips(set.mInstruments[set.mInstruments.Count - 1].mData.InstrumentType);
                    set.mInstruments[set.mInstruments.Count - 1].InstrumentTypeIndex = index;
                }
            }
        }
        /// <summary>
        /// Plays the next step in the measure.
        /// </summary>
        /// <param name="set"></param>
        /// <param name="timeStepIN"></param>
        /// <param name="stepsTaken"></param>
        public override void TakeStep(InstrumentSet set, eTimestep timeStepIN, int stepsTaken = 0)
        {
            for (int instIndex = 0; instIndex < set.mInstruments.Count; instIndex++)
            {
                if (set.mInstruments[instIndex].mData.Group >= set.mMusicGenerator.mGeneratorData.mGroupOdds.Count || set.mData.mProgressionRate < 0)
                {
                    return;
                }

                Instrument instrument     = set.mInstruments[instIndex];
                bool       groupIsPlaying = set.mMusicGenerator.mGroupIsPlaying[(int)instrument.mData.Group];

                if (instrument.mData.mTimeStep == timeStepIN && groupIsPlaying && instrument.mData.mIsMuted == false)
                {
                    PlayNotes(set, instrument, stepsTaken, instIndex);
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Plays the next sequence in the measure.
        /// </summary>
        /// <param name="set"></param>
        public override void PlayMeasure(InstrumentSet set)
        {
            if (set.mMusicGenerator == null)
            {
                return;
            }

            set.UpdateTempo();
            set.mSixteenthStepTimer -= Time.deltaTime;
            if (set.mSixteenthStepTimer <= 0 && set.SixteenthStepsTaken < set.mTimeSignature.mStepsPerMeasure)
            {
                set.mMusicGenerator.BarlineColorSet.Invoke(set.SixteenthStepsTaken, true);
                if (set.SixteenthStepsTaken % set.mTimeSignature.Half == 0)
                {
                    TakeStep(set, eTimestep.eighth);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Quarter == 0)
                {
                    TakeStep(set, eTimestep.quarter);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Eighth == 0)
                {
                    TakeStep(set, eTimestep.half);
                }
                if (set.SixteenthStepsTaken % set.mTimeSignature.Sixteenth == 0)
                {
                    TakeStep(set, eTimestep.whole);
                    set.mMeasureStartTimer = 0.0f;
                }

                TakeStep(set, (int)eTimestep.sixteenth);
                set.SixteenthRepeatCount += 1;
                set.mSixteenthStepTimer   = set.mBeatLength;
                set.SixteenthStepsTaken  += 1;
            }
            else if (set.SixteenthStepsTaken == set.mTimeSignature.mStepsPerMeasure)
            {
                set.mMeasureStartTimer += Time.deltaTime;
                if (set.mMeasureStartTimer > set.mBeatLength)
                {
                    ResetMeasure(set);
                }
            }
        }
Beispiel #20
0
        /// Adds an instrument to the Music generator and creates its ui object.
        public void AddMusicGeneratorInstrument(bool isPercussion)
        {
            InstrumentSet     set         = (mMusicGenerator.mState >= eGeneratorState.editorInitializing) ? MeasureEditor.Instance.mCurrentInstSet : mMusicGenerator.mInstrumentSet;
            List <Instrument> instruments = set.mInstruments;

            if (instruments.Count < MusicGenerator.mMaxInstruments)
            {
                mMusicGenerator.AddInstrument(set);
                Instrument instrument = set.mInstruments[set.mInstruments.Count - 1];
                AddInstrument(instrument);
                InstrumentListUIObject icon = mInstrumentIcons[mInstrumentIcons.Count - 1];

                icon.mInstrument = instruments[instruments.Count - 1];
                Color color = StaffPlayerUI.Instance.mColors[(int)icon.mInstrument.mData.mStaffPlayerColor];
                icon.mPanelBack.color = color;

                icon.SetDropdown(isPercussion);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Plays the repeating notes for this timestep.
 /// </summary>
 /// <param name="set"></param>
 /// <param name="instrument"></param>
 /// <param name="instIndex"></param>
 /// <param name="instSubIndex"></param>
 private void PlayRepeatNotes(InstrumentSet set, Instrument instrument, int instIndex, int instSubIndex)
 {
     for (int chordNote = 0; chordNote < instrument.mData.ChordSize; chordNote++)
     {
         if (instrument.mRepeatingNotes.Length > set.SixteenthRepeatCount && instrument.mRepeatingNotes[set.SixteenthRepeatCount][chordNote] != InstrumentSet.mUnplayed)
         {
             if (instrument.mData.StrumLength == 0.0f)
             {
                 set.mMusicGenerator.PlayAudioClip(set, (int)instrument.InstrumentTypeIndex, instrument.mRepeatingNotes[set.SixteenthRepeatCount][chordNote], instrument.mData.Volume, instIndex);
                 set.mMusicGenerator.UIStaffNotePlayed.Invoke(instrument.mRepeatingNotes[set.SixteenthRepeatCount][chordNote], (int)instrument.mData.mStaffPlayerColor);
             }
             else
             {
                 int[] clip = instrument.mThemeNotes[set.SixteenthRepeatCount];
                 set.Strum(clip, instIndex);
                 break;
             }
         }
     }
 }
        /// <summary>
        /// async init.
        /// </summary>
        /// <param name="save"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator AsyncInit(ClipSave save, System.Action <bool> callback)
        {
            mInstrumentSet = new InstrumentSet();
            mInstrumentSet.Init();
            mTempo            = save.mTempo;
            mNumMeasures      = save.mNumberOfMeasures;
            mSixteenthMeasure = 60 / mTempo;
            mIsRepeating      = save.mClipIsRepeating;

            mInstrumentSet.mData.Tempo = mTempo;
            mInstrumentSet.SetProgressionRate(save.mProgressionRate);
            mInstrumentSet.mData.RepeatMeasuresNum = mNumMeasures;
            bool isFinished = false;

            StartCoroutine(AsyncLoadInstruments(save, ((x) => { isFinished = x; })));
            yield return(new WaitUntil(() => isFinished));

            callback(isFinished);
            yield return(null);
        }
Beispiel #23
0
        /// Updates the helper notes showing/not showing, whether mShowEditorHints.isOn.
        public void ToggleHelperNotes(Dropdown colorDropdownIN = null)
        {
            if (mMusicGenerator.mState >= eGeneratorState.editing)
            {
                if (mShowEditorHints.isOn)
                {
                    if (mLoadedClip.mInstrumentSet.mInstruments.Count == 0)
                    {
                        return;
                    }

                    int currentInstIndex = (int)mInstrumentPanel.mInstrument.InstrumentIndex;
                    if (colorDropdownIN != null)
                    {
                        mLoadedClip.mInstrumentSet.mInstruments[currentInstIndex].mData.mStaffPlayerColor = (eStaffPlayerColors)colorDropdownIN.value;
                    }

                    mStaffPlayer.ClearNotes(true, true);
                    Instrument instrument = mLoadedClip.mInstrumentSet.mInstruments[currentInstIndex];
                    mStaffPlayer.ShowHighlightedNotes(instrument);
                    if (mShowAllInstruments.isOn)
                    {
                        InstrumentSet set = mLoadedClip.mInstrumentSet;
                        for (int i = 0; i < set.mInstruments.Count; i++)
                        {
                            int[][] notes = set.mInstruments[i].mClipNotes[mCurrentMeasure.value];
                            mStaffPlayer.ShowSetEditorNotes(notes, i);
                        }
                    }
                    else
                    {
                        mStaffPlayer.ShowSetEditorNotes(instrument.mClipNotes[mCurrentMeasure.value], instrument.InstrumentIndex);
                    }
                }
                else
                {
                    mStaffPlayer.ClearNotes(false, true);
                }
            }
        }
Beispiel #24
0
        /// Displays a note on the staff player:
        public void DisplayNote(int noteIN, int colorIN, bool useShadow, InstrumentSet setIN, bool strummed = false)
        {
            int sixteenStepsTaken = setIN.SixteenthStepsTaken;

            if (useShadow == false)
            {
                mPlayedNotes[mCurrentNote].gameObject.SetActive(true);
                if (strummed == false)
                {
                    mPlayedNotes[mCurrentNote].transform.position = new Vector3(mBarLines[sixteenStepsTaken].position.x, mStaffLines[noteIN].transform.position.y, 0);
                }
                else
                {
                    mPlayedNotes[mCurrentNote].transform.position = new Vector3(mTimerBar.transform.position.x, mStaffLines[noteIN].transform.position.y, 0);
                }
                mPlayedNotes[mCurrentNote].mBaseImage.color = mColors[colorIN];
            }
            else
            {
                mShadowNotes[mCurrentNote].gameObject.SetActive(true);
                if (strummed == false)
                {
                    mShadowNotes[mCurrentNote].transform.position = new Vector2(mBarLines[sixteenStepsTaken].position.x, mStaffLines[noteIN].transform.position.y);
                }
                else
                {
                    mShadowNotes[mCurrentNote].transform.position = new Vector2(mTimerBar.transform.position.x, mStaffLines[noteIN].transform.position.y);
                }

                Component[] components2 = mShadowNotes[mCurrentNote].GetComponentsInChildren <Image>();
                foreach (Component cp in components2)
                {
                    if (cp.name != "shadow")
                    {
                        cp.GetComponent <Image>().color = mColors[colorIN];
                    }
                }
            }
            IncreaseCurrentNoteCount(ref mCurrentNote, mMaxPlayedNotes);
        }
Beispiel #25
0
        /// <summary>
        /// Resets a repeating measure.
        /// </summary>
        /// <param name="set"></param>
        /// <param name="SetThemeRepeat"></param>
        /// <param name="hardReset"></param>
        /// <param name="isRepeating"></param>
        protected void ResetRepeatMeasure(InstrumentSet set, Action SetThemeRepeat = null, bool hardReset = false, bool isRepeating = true)
        {
            set.mMusicGenerator.RepeatedMeasureExited.Invoke(set.mMusicGenerator.mState);

            set.mRepeatCount += 1;

            set.mMeasureStartTimer  = 0.0f;
            set.mSixteenthStepTimer = 0.0f;
            set.ResetMultipliers();
            set.SixteenthStepsTaken = 0;

            if (isRepeating == false)
            {
                return;
            }

            //if we've repeated all the measures set to repeat in their entirety, reset the step counts.
            bool isEditing = set.mMusicGenerator.OnUIPlayerIsEditing();
            int  repeatNum = isEditing ? set.mData.RepeatMeasuresNum + 1 : set.mData.RepeatMeasuresNum * 2;

            if (set.mRepeatCount >= repeatNum || isEditing || hardReset)
            {
                if (isEditing == false || hardReset)
                {
                    set.mRepeatCount = 0;
                }

                set.SixteenthRepeatCount = 0;
                for (int i = 0; i < set.mInstruments.Count; i++)
                {
                    set.mInstruments[i].ClearRepeatingNotes();
                }

                if (set.mMusicGenerator.mState > eGeneratorState.stopped && set.mMusicGenerator.mState < eGeneratorState.editorInitializing)
                {
                    set.mMusicGenerator.SetState(eGeneratorState.playing);
                }
            }
        }
        /// <summary>
        /// Sets the pattern variables. Mostly for readability in other functions :\
        /// </summary>
        /// <param name="progressionStep"></param>
        private void SetupNoteGeneration(int progressionStep)
        {
            InstrumentSet set         = mMusicGenerator.mInstrumentSet;
            int           invProgRate = set.GetInverseProgressionRate((int)mData.mTimeStep);
            int           progRate    = set.GetProgressionRate((int)mData.mTimeStep);

            // chord progressions are set in their sensible way: I-IV-V for example starting on 1.
            // it's easier to leave like that as it's readable (from a music perspective, anyhow) and adjust here, rather than 0 based:
            mCurrentProgressionStep = progressionStep - ((progressionStep < 0) ? -1 : 1);

            mPatternstepsTaken  = (int)(set.SixteenthStepsTaken / invProgRate);
            mCurrentPatternStep = mPatternstepsTaken % mData.PatternLength;

            mbAreRepeatingPattern = (mPatternstepsTaken >= mData.PatternLength && mPatternstepsTaken < progRate - mData.PatternRelease);
            mbAreSettingPattern   = (mPatternstepsTaken < mData.PatternLength);

            if (mCurrentPatternStep < mPatternNoteOffset.Length - 1)
            {
                mCurrentPatternNotes  = mPatternNoteOffset[(int)mCurrentPatternStep];
                mCurrentPatternOctave = mPatternOctaveOffset[(int)mCurrentPatternStep];
            }
        }
Beispiel #27
0
        /// <summary>
        /// Plays the next steps in the measure.
        /// </summary>
        /// <param name="set"></param>
        public override void PlayMeasure(InstrumentSet set)
        {
            set.UpdateTempo();

            if (set.mMusicGenerator == null)
            {
                return;
            }

            set.mSixteenthStepTimer -= Time.deltaTime;
            // we'll take a step when the timer hits zero, or it's the first step
            if (set.mSixteenthStepTimer <= 0 && set.SixteenthStepsTaken < set.mTimeSignature.mStepsPerMeasure)
            {
                if (set.SixteenthStepsTaken % (int)set.mData.mProgressionRate == 0)
                {
                    set.ProgressionStepsTaken += 1;
                }
                if (set.ProgressionStepsTaken > InstrumentSet.mMaxFullstepsTaken - 1)
                {
                    set.ProgressionStepsTaken = -1;
                }

                TakeStep(set, (int)eTimestep.sixteenth, set.SixteenthRepeatCount);
                set.SixteenthRepeatCount += 1;
                set.mSixteenthStepTimer   = set.mBeatLength;

                set.SixteenthStepsTaken += 1;
            }
            // Reset once we've reached the end
            else if (set.SixteenthStepsTaken == set.mTimeSignature.mStepsPerMeasure)
            {
                set.mMeasureStartTimer += Time.deltaTime;
                if (set.mMeasureStartTimer > set.mBeatLength)
                {
                    bool hardReset = false;
                    ResetMeasure(set, set.mMusicGenerator.SetThemeRepeat, hardReset, true);
                }
            }
        }
Beispiel #28
0
        ///stages a clip for playing. Async version (will load assets on the fly).
        public IEnumerator AsyncStageClipForPlaying()
        {
            ClearCurrentInstruments();

            bool isFinished = false;

            StartCoroutine(AsyncLoadClip(((x) => { isFinished = x; }), mPlayClipDropdown.options[mPlayClipDropdown.value].text));
            yield return(new WaitUntil(() => isFinished));

            mCurrentInstSet = mLoadedClip.mInstrumentSet;

            InstrumentListPanelUI listPanel = InstrumentListPanelUI.Instance;

            for (int i = 0; i < mCurrentInstSet.mInstruments.Count; i++)
            {
                listPanel.AddInstrument(mCurrentInstSet.mInstruments[i]);
                InstrumentListUIObject icon = listPanel.mInstrumentIcons[listPanel.mInstrumentIcons.Count - 1];
                icon.mInstrument = mCurrentInstSet.mInstruments[i];
                icon.ToggleSelected();
                bool isPercussion = icon.mInstrument.mData.InstrumentType.Contains("p_") ? true : false;
                icon.SetDropdown(isPercussion);

                InstrumentPanelUI.Instance.SetInstrument(icon.mInstrument);
                mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[i];
            }
            InstrumentPanelUI.Instance.SetInstrument(mCurrentInstSet.mInstruments[0]);
            mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[0];

            mClipIsRepeating.isOn = mLoadedClip.mIsRepeating;
            mCurrentMeasure.value = 0;
            mLoadedClip.SetState(eClipState.Stop);
            mMusicGenerator.ClipLoaded.Invoke(mCurrenClipSave);
            mMusicGenerator.ResetPlayer();
            mMusicGenerator.SetState(eGeneratorState.editing);
            ToggleHelperNotes();
            UIToggleAllInstruments();
            yield return(null);
        }
Beispiel #29
0
        /// Takes a measure step.
        public override void TakeStep(InstrumentSet set, eTimestep timeStepIN, int value = 0)
        {
            for (int i = 0; i < set.mInstruments.Count; i++)
            {
                if (set.mInstruments[i].mData.mIsMuted == false)
                {
                    for (int j = 0; j < set.mInstruments[i].mData.ChordSize; j++)
                    {
                        int note = set.mInstruments[i].mClipNotes[set.mRepeatCount][value][j];
                        if (note != InstrumentSet.mUnplayed)
                        {
                            /// set percussion to 0
                            if (set.mInstruments[i].mData.InstrumentType.Contains("p_"))
                            {
                                note = 0;
                            }

                            set.mMusicGenerator.PlayAudioClip(set, (int)set.mInstruments[i].InstrumentTypeIndex, note, set.mInstruments[i].mData.Volume, i);
                        }
                    }
                }
            }
        }
Beispiel #30
0
        void Update()
        {
            if (mMusicGenerator == null)
            {
                return;
            }

            if (mMusicGenerator.mState == eGeneratorState.editorInitializing)
            {
                return;
            }

            InstrumentSet set = (mMusicGenerator.mState >= eGeneratorState.editorInitializing) ? mMeasureEditor.mCurrentInstSet : mMusicGenerator.mInstrumentSet;

            if (mCurrentChordProgression != mMusicGenerator.ChordProgression)
            {
                UpdateChordProgressionText(set);
            }

            float sixteenthStepTimer = set.mSixteenthStepTimer;
            int   sixteenStepsTaken  = set.SixteenthStepsTaken - 1;
            float sixteenthMeasure   = set.mBeatLength;

            float dist = mBarLines[1].position.x - mBarLines[0].position.x;
            float perc = (sixteenthStepTimer / sixteenthMeasure);

            if (sixteenStepsTaken < 0)
            {
                mTimerBar.gameObject.transform.position = new Vector3(mBarLines[0].position.x,
                                                                      mTimerBar.transform.position.y, mTimerBar.transform.position.z);
            }
            else
            {
                mTimerBar.gameObject.transform.position = new Vector3(mBarLines[sixteenStepsTaken].position.x +
                                                                      dist * (1.0f - perc), mTimerBar.transform.position.y, mTimerBar.transform.position.z);
            }
        }