private IEnumerator AddPresets()
        {
            if (System.IO.Directory.Exists(Application.persistentDataPath + "/MusicGenerator/InstrumentSaves"))
            {
                foreach (string folder in System.IO.Directory.GetDirectories(Application.persistentDataPath + "/MusicGenerator/InstrumentSaves"))
                {
                    if (mPresetFileNames.Contains(name) == false)
                    {
                        mPresetFileNames.Add(name);
                    }
                }
            }
            string data = null;

            yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/presets.txt", (x) => { data = x.downloadHandler.text; }));

            mPresetFileNames = new List <string>(data.Split(','));
            if (mPresetFileNames != null)
            {
                for (int i = 0; i < mPresetFileNames.Count; i++)
                {
                    mStaffPlayerUI.AddPresetOption(mPresetFileNames[i]);
                }
            }

            yield return(null);
        }
Exemplo n.º 2
0
        /// loads all available presets from the the streaming assets and persisten data paths.
        public IEnumerator LoadPresets()
        {
            if (System.IO.Directory.Exists(Application.persistentDataPath + "/MusicGenerator/InstrumentClips"))
            {
                foreach (string filename in System.IO.Directory.GetFiles(Application.persistentDataPath + "/MusicGenerator/InstrumentClips"))
                {
                    if (filename.Contains(".meta") == false && filename.Contains("presets") == false)
                    {
                        AddPresetOption(Path.GetFileName(filename));
                    }
                }
            }

            string data = null;

            yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentClips/presets.txt", (x) => { data = x.downloadHandler.text; }));

            List <string> presetFileNames = new List <string>(data.Split(','));

            if (presetFileNames != null)
            {
                for (int i = 0; i < presetFileNames.Count; i++)
                {
                    AddPresetOption(presetFileNames[i]);
                }
            }
            yield return(StartCoroutine(StageMobileClipForPlaying()));
        }
        /// <summary>
        /// Loads our instrument set data
        /// </summary>
        /// <param name="pathIN"></param>
        /// <returns></returns>
        public static IEnumerator LoadData(string pathIN, System.Action <InstrumentSetData> callback)
        {
            string data = null;

            yield return(MusicHelpers.GetUWR(MusicFileConfig.mSavesPath + "/" + pathIN + "/InstrumentSetData.txt", (x) => { data = x.downloadHandler.text; }));

            InstrumentSetData saveOUT = JsonUtility.FromJson <InstrumentSetData>(data);

            // Version check and update.
            if (saveOUT.mVersion == 0.0f)
            {
                string generatorData = null;
                yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/generator.txt", (x) => { generatorData = x.downloadHandler.text; }));

                GeneratorSave generatorSave = JsonUtility.FromJson <GeneratorSave>(generatorData);

                /// we need to grab these from the generatorSave as the variables belonged to that in the last version
                saveOUT                   = new InstrumentSetData();
                saveOUT.Tempo             = generatorSave.mTempo;
                saveOUT.RepeatMeasuresNum = generatorSave.mRepeatMeasuresNum;
                saveOUT.mProgressionRate  = (eProgressionRate)generatorSave.mProgressionRate;
                saveOUT.mTimeSignature    = generatorSave.mTimeSignature;
            }
            callback(saveOUT);
            yield return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Loads chord progression data from JSON
        /// </summary>
        /// <param name="pathIN"></param>
        /// <returns></returns>
        public static IEnumerator LoadData(string pathIN, System.Action <ChordProgressionData> callback)
        {
            string data = null;

            yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/ChordProgressionData.txt", (x) => { data = x.downloadHandler.text; }));

            ChordProgressionData saveOUT = JsonUtility.FromJson <ChordProgressionData>(data);

            if (saveOUT.mVersion == 0.0f)
            {
                string generatorData = null;
                yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/generator.txt", (x) => { generatorData = x.downloadHandler.text; }));

                GeneratorSave generatorSave = JsonUtility.FromJson <GeneratorSave>(generatorData);
                /// we need to grab these from the generatorSave as the variables belonged to that in the last version
                saveOUT = new ChordProgressionData();
                saveOUT.DominantInfluence    = generatorSave.mDominantInfluence;
                saveOUT.mExcludedProgSteps   = generatorSave.mExcludedProgSteps.ToArray();
                saveOUT.SubdominantInfluence = generatorSave.mSubdominantInfluence;
                saveOUT.TonicInfluence       = generatorSave.mTonicInfluence;
                saveOUT.TritoneSubInfluence  = generatorSave.mTritoneSubInfluence;
            }

            callback(saveOUT);
            yield return(null);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// loads the tooltips:
        /// </summary>
        /// <returns></returns>
        public static IEnumerator LoadTooltips(System.Action <TooltipSave> callback)
        {
            string tooltipsString = "";

            yield return(MusicHelpers.GetUWR(TOOLTIPS_PATH, (x) => { tooltipsString = x.downloadHandler.text; }, false));

            TooltipSave saveOUT = JsonUtility.FromJson <TooltipSave>(tooltipsString);

            if (saveOUT == null)
            {
                throw new ArgumentNullException("tooltip file was not sucessfully loaded");
            }

            callback(saveOUT);
            yield return(null);
        }
        /// <summary>
        /// Loads our data
        /// </summary>
        /// <param name="pathIN"></param>
        /// <returns></returns>
        public static IEnumerator LoadData(string pathIN, System.Action <MusicGeneratorData> callback)
        {
            string data = null;

            yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/generator.txt", (x) => { data = x.downloadHandler.text; }));

            MusicGeneratorData generatorData = JsonUtility.FromJson <MusicGeneratorData>(data);

            // Version check and update.
            if (generatorData.mVersion != MusicGenerator.Version)
            {
                ChordProgressionData chordSave = new ChordProgressionData();
                string persistentDir           = MusicFileConfig.GetPersistentSaveDirectory(pathIN);

                // apply the needed changes for version 1.1. was null before.
                if (generatorData.mVersion == 0.0f)
                {
                    string generatorSaveData = null;
                    yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/generator.txt", (x) => { generatorSaveData = x.downloadHandler.text; }));

                    GeneratorSave generatorSave = JsonUtility.FromJson <GeneratorSave>(generatorSaveData);

                    generatorData.mDistortion         = new Pair_String_Float("MasterDistortion", generatorSave.mDistortion);
                    generatorData.mCenterFreq         = new Pair_String_Float("MasterCenterFrequency", generatorSave.mCenterFreq);
                    generatorData.mOctaveRange        = new Pair_String_Float("MasterOctaveRange", generatorSave.mOctaveRange);
                    generatorData.mFreqGain           = new Pair_String_Float("MasterFrequencyGain", generatorSave.mFreqGain);
                    generatorData.mLowpassCutoffFreq  = new Pair_String_Float("MasterLowpassCutoffFreq", generatorSave.mLowpassCutoffFreq);
                    generatorData.mLowpassResonance   = new Pair_String_Float("MasterLowpassResonance", generatorSave.mLowpassResonance);
                    generatorData.mHighpassCutoffFreq = new Pair_String_Float("MasterHighpassCutoffFreq", generatorSave.mHighpassCutoffFreq);
                    generatorData.mHighpassResonance  = new Pair_String_Float("MasterHighpassResonance", generatorSave.mHighpassResonance);
                    generatorData.mEchoDelay          = new Pair_String_Float("MasterEchoDelay", generatorSave.mEchoDelay);
                    generatorData.mEchoDecay          = new Pair_String_Float("MasterEchoDecay", generatorSave.mEchoDecay);
                    generatorData.mEchoDry            = new Pair_String_Float("MasterEchoDry", generatorSave.mEchoDry);
                    generatorData.mEchoWet            = new Pair_String_Float("MasterEchoWet", generatorSave.mEchoWet);
                    generatorData.mNumEchoChannels    = new Pair_String_Float("MasterNumEchoChannels", generatorSave.mNumEchoChannels);
                    generatorData.mReverb             = new Pair_String_Float("MasterReverb", generatorSave.mRever);
                    generatorData.mRoomSize           = new Pair_String_Float("MasterRoomSize", generatorSave.mRoomSize);
                    generatorData.mReverbDecay        = new Pair_String_Float("MasterReverbDecay", generatorSave.mReverbDecay);

                    generatorData.mGroupRate = (eGroupRate)generatorSave.mGroupRate;

                    // We also need to create a chord progression data object:
                    chordSave.mExcludedProgSteps   = generatorSave.mExcludedProgSteps.ToArray();
                    chordSave.SubdominantInfluence = generatorSave.mSubdominantInfluence;
                    chordSave.DominantInfluence    = generatorSave.mDominantInfluence;
                    chordSave.TonicInfluence       = generatorSave.mTonicInfluence;
                    chordSave.TritoneSubInfluence  = generatorSave.mTritoneSubInfluence;
                }
                else if (generatorData.mVersion == 1.1f)
                {
                    string generatorSaveData = null;
                    yield return(MusicHelpers.GetUWR("/MusicGenerator/InstrumentSaves/" + pathIN + "/generator.txt", (x) => { generatorSaveData = x.downloadHandler.text; }));

                    GeneratorSave generatorSave = JsonUtility.FromJson <GeneratorSave>(generatorSaveData);

                    generatorData.mGroupOdds.Clear();
                    for (int i = 0; i < generatorSave.mGroupOdds.Count; i++)
                    {
                        generatorData.mGroupOdds.Add(generatorSave.mGroupOdds[i]);
                    }
                }
            }

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