/// <summary>
        /// load the clip:
        /// </summary>
        /// <param name="save"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public IEnumerator AsyncLoadInstruments(ClipSave save, System.Action <bool> callback)
        {
            for (int i = 0; i < save.mClipInstrumentSaves.Count; i++)
            {
                ClipInstrumentSave instrumentSave = save.mClipInstrumentSaves[i];
                mInstrumentSet.mInstruments.Add(new Instrument());
                mInstrumentSet.mInstruments[i].Init(i);

                Instrument instrument = mInstrumentSet.mInstruments[i];

                for (int x = 0; x < instrumentSave.mClipMeasures.Count; x++)
                {
                    for (int y = 0; y < instrumentSave.mClipMeasures[x].timestep.Count; y++)
                    {
                        for (int z = 0; z < instrumentSave.mClipMeasures[x].timestep[y].notes.Count; z++)
                        {
                            instrument.mClipNotes[x][y][z] = instrumentSave.mClipMeasures[x].timestep[y].notes[z];
                        }
                    }
                }
                int index = 999;
                yield return(StartCoroutine(MusicGenerator.Instance.AsyncLoadBaseClips(instrumentSave.mInstrumentType, ((x) => { index = x; }))));

                //yield return new WaitUntil(() => index != 999);
                instrument.mData.InstrumentType    = instrumentSave.mInstrumentType;
                instrument.mData.Volume            = instrumentSave.mVolume;
                instrument.InstrumentTypeIndex     = index;
                instrument.mData.mStaffPlayerColor = (eStaffPlayerColors)instrumentSave.mStaffPlayerColor;
                instrument.mData.mTimeStep         = instrumentSave.mTimestep;
                instrument.mData.mSuccessionType   = instrumentSave.mSuccessionType;
                instrument.mData.StereoPan         = instrumentSave.mStereoPan;
            }
            callback(true);
            yield return(null);
        }
        ///load the clip:
        public void LoadInstruments(ClipSave save)
        {
            for (int i = 0; i < save.mClipInstrumentSaves.Count; i++)
            {
                ClipInstrumentSave instrumentSave = save.mClipInstrumentSaves[i];
                mInstrumentSet.mInstruments.Add(new Instrument());
                mInstrumentSet.mInstruments[i].Init(i);

                Instrument instrument = mInstrumentSet.mInstruments[i];

                for (int x = 0; x < instrumentSave.mClipMeasures.Count; x++)
                {
                    for (int y = 0; y < instrumentSave.mClipMeasures[x].timestep.Count; y++)
                    {
                        for (int z = 0; z < instrumentSave.mClipMeasures[x].timestep[y].notes.Count; z++)
                        {
                            instrument.mClipNotes[x][y][z] = instrumentSave.mClipMeasures[x].timestep[y].notes[z];
                        }
                    }
                }
                instrument.mData.Volume = instrumentSave.mVolume;
                int index = MusicGenerator.Instance.LoadBaseClips(instrumentSave.mInstrumentType);
                instrument.mData.InstrumentType    = instrumentSave.mInstrumentType;
                instrument.InstrumentTypeIndex     = index;
                instrument.mData.mStaffPlayerColor = ((eStaffPlayerColors)instrumentSave.mStaffPlayerColor);
                instrument.mData.mTimeStep         = instrumentSave.mTimestep;
                instrument.mData.mSuccessionType   = (instrumentSave.mSuccessionType);
                instrument.mData.StereoPan         = (instrumentSave.mStereoPan);
            }
        }
Beispiel #3
0
 public ClipLoadedArgs(ClipSave clipConfig)
 {
     mTempo = clipConfig.mTempo;
     mKey   = (int)clipConfig.mKey;
     mScale = (int)clipConfig.mScale;
     mMode  = (int)clipConfig.mMode;
 }
 public void OnClipLoaded(ClipSave e)
 {
     MeasureEditor.Instance.mKey.value   = (int)e.mKey;
     MeasureEditor.Instance.mScale.value = (int)e.mScale;
     MeasureEditor.Instance.mMode.value  = (int)e.mMode;
     MeasureEditor.Instance.mTempo.value = e.mTempo;
 }
Beispiel #5
0
        ///async loads a music clip
        public IEnumerator AsyncLoadClip(System.Action <bool> callback, string fileName = "")
        {
            fileName    = (fileName == "") ? "AAADefault.txt" : fileName;
            mLoadedClip = gameObject.AddComponent <SingleClip>();
#if !UNITY_EDITOR && UNITY_ANDROID
            yield return(StartCoroutine(mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(fileName, (x) => { mCurrenClipSave = x; })));
#else
            mCurrenClipSave = mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(fileName);
#endif //!UNITY_EDITOR && UNITY_ANDROID

            mTempo.value            = mCurrenClipSave.mTempo;
            mProgressionRate.value  = mCurrenClipSave.mProgressionRate;
            mNumberOfMeasures.value = mCurrenClipSave.mNumberOfMeasures;
            mKey.value            = (int)mCurrenClipSave.mKey;
            mScale.value          = (int)mCurrenClipSave.mScale;
            mMode.value           = (int)mCurrenClipSave.mMode;
            mClipIsRepeating.isOn = mCurrenClipSave.mClipIsRepeating;

            bool isFinished = false;
            StartCoroutine(mLoadedClip.AsyncInit(mCurrenClipSave, ((x) => { isFinished = x; })));
            yield return(new WaitUntil(() => isFinished));

            callback(isFinished);
            yield return(null);
        }
Beispiel #6
0
        //saves clip notes:
        public void SaveClip(string fileNameIN)
        {
            mCurrenClipSave       = GetSaveClip();
            mFileCurrentlyWriting = fileNameIN;

            string stringSave = JsonUtility.ToJson(mCurrenClipSave);

            mMusicGenerator.mMusicFileConfig.SaveClipConfiguration(fileNameIN, stringSave);
            ExportMobilePresets();
        }
        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 #8
0
        /// Plays a single clips
        private IEnumerator PlaySingleClip(Toggle isRepeatingToggle)
        {
            if (mSingleClip == null)
            {
                mSingleClip = gameObject.AddComponent <SingleClip>();
                string   clipName = "AAADefault.txt";               /// This already exists in the IntrumentClips folder. we load it below with Init().
                ClipSave clipSave = null;
                yield return(StartCoroutine(mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(clipName, (x) => { clipSave = x; })));

                mSingleClip.Init(clipSave);
                mSingleClip.mIsRepeating = isRepeatingToggle.isOn;
            }
            //	mSingleClip.ResetClip();///Just in case it was already playing
            mSingleClip.SetState(eClipState.Play);
        }
Beispiel #9
0
        /// <summary>
        /// Loads a clip configuration.
        /// </summary>
        /// <param name="fileNameIN"></param>
        /// <returns></returns>
        public IEnumerator LoadClipConfigurations(string argFileName, System.Action <ClipSave> argCallback)
        {
            string clipSaveString = "";

            yield return(StartCoroutine(MusicHelpers.GetUWR(mClipsPath + "/" + argFileName, (x) => { clipSaveString = x.downloadHandler.text; })));

            ClipSave clipSave = JsonUtility.FromJson <ClipSave>(clipSaveString);

            if (clipSave == null)
            {
                throw new ArgumentNullException("clipSave was null");
            }

            argCallback(clipSave);
            yield return(null);
        }
Beispiel #10
0
        private ClipSave GetSaveClip()
        {
            ClipSave clipsave = new ClipSave();

            clipsave.mTempo            = mTempo.value;
            clipsave.mProgressionRate  = mProgressionRate.value;
            clipsave.mNumberOfMeasures = mNumberOfMeasures.value;
            clipsave.mKey             = MusicGenerator.Instance.mGeneratorData.mKey;
            clipsave.mScale           = MusicGenerator.Instance.mGeneratorData.mScale;
            clipsave.mMode            = MusicGenerator.Instance.mGeneratorData.mMode;
            clipsave.mClipIsRepeating = mClipIsRepeating.isOn;

            List <ClipInstrumentSave> instrumentSaves = clipsave.mClipInstrumentSaves;

            for (int i = 0; i < mCurrentInstSet.mInstruments.Count; i++)
            {
                ClipInstrumentSave save       = new ClipInstrumentSave();
                Instrument         instrument = mCurrentInstSet.mInstruments[i];
                /// unity isn't saving multidimensional lists, so we're converting here.
                for (int x = 0; x < instrument.mClipNotes.Length; x++)
                {
                    save.mClipMeasures.Add(new ClipNotesMeasure());
                    for (int y = 0; y < instrument.mClipNotes[x].Length; y++)
                    {
                        save.mClipMeasures[x].timestep.Add(new ClipNotesTimeStep());
                        for (int z = 0; z < instrument.mClipNotes[x][y].Length; z++)
                        {
                            save.mClipMeasures[x].timestep[y].notes.Add(instrument.mClipNotes[x][y][z]);
                        }
                    }
                }

                save.mInstrumentType   = instrument.mData.InstrumentType;
                save.mVolume           = instrument.mData.Volume;
                save.mStaffPlayerColor = (int)instrument.mData.mStaffPlayerColor;
                save.mTimestep         = instrument.mData.mTimeStep;
                save.mSuccessionType   = instrument.mData.mSuccessionType;
                save.mStereoPan        = instrument.mData.mStereoPan;

                instrumentSaves.Add(save);
            }

            return(clipsave);
        }
        /// <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 #12
0
        /// <summary>
        /// Loads a clip configuration.
        /// </summary>
        /// <param name="argFileName"></param>
        /// <returns></returns>
        public ClipSave LoadClipConfigurations(string argFileName)
        {
            string clipSaveString = File.Exists(mPersistentClipsPath + "/" + argFileName) ?
                                    clipSaveString = File.ReadAllText(mPersistentClipsPath + "/" + argFileName) :
                                                     clipSaveString = File.ReadAllText(mStreamingClipsPath + "/" + argFileName);

            if (string.IsNullOrEmpty(clipSaveString))
            {
                throw new ArgumentNullException("clipSave");
            }

            ClipSave clipSave = JsonUtility.FromJson <ClipSave>(clipSaveString);

            if (clipSave == null)
            {
                throw new ArgumentNullException("clipSave");
            }

            return(clipSave);
        }
Beispiel #13
0
        ///loads a music clip
        public void LoadClip(string fileName = "")
        {
            fileName = (fileName == "") ? "AAADefault.txt" : fileName;
            GameObject go = new GameObject();

            go.name = fileName;
            go.AddComponent <SingleClip>();
            //go.transform.parent = transform;
            mLoadedClip     = go.GetComponent <SingleClip>();
            mCurrenClipSave = mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(fileName);

            mTempo.value            = mCurrenClipSave.mTempo;
            mProgressionRate.value  = mCurrenClipSave.mProgressionRate;
            mNumberOfMeasures.value = mCurrenClipSave.mNumberOfMeasures;
            mKey.value            = (int)mCurrenClipSave.mKey;
            mScale.value          = (int)mCurrenClipSave.mScale;
            mMode.value           = (int)mCurrenClipSave.mMode;
            mClipIsRepeating.isOn = mCurrenClipSave.mClipIsRepeating;

            mLoadedClip.Init(mCurrenClipSave);
        }
 /// <summary>
 /// non-async init.
 /// </summary>
 /// <param name="save"></param>
 public void Init(ClipSave save)
 {
     StartInitialization(save);
     LoadInstruments(save);
 }
Beispiel #15
0
        ///loads a music clip
        public IEnumerator LoadClip(string fileName = "", System.Action <bool> callback = null)
        {
            fileName = (fileName == "") ? "AAADefault.txt" : fileName;
            GameObject go = new GameObject();

            go.name = fileName;
            go.AddComponent <SingleClip>();
            //go.transform.parent = transform;
            mLoadedClip = go.GetComponent <SingleClip>();
            yield return(StartCoroutine(mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(fileName, (x) => { mCurrenClipSave = x; })));

            mTempo.value            = mCurrenClipSave.mTempo;
            mProgressionRate.value  = mCurrenClipSave.mProgressionRate;
            mNumberOfMeasures.value = mCurrenClipSave.mNumberOfMeasures;
            mKey.value            = (int)mCurrenClipSave.mKey;
            mScale.value          = (int)mCurrenClipSave.mScale;
            mMode.value           = (int)mCurrenClipSave.mMode;
            mClipIsRepeating.isOn = mCurrenClipSave.mClipIsRepeating;

            mLoadedClip.Init(mCurrenClipSave);

            callback(true);
            yield return(null);
        }