Exemple #1
0
 /// <summary>
 /// Loads the instrument set data.
 /// </summary>
 /// <param name="data"></param>
 public void LoadData(InstrumentSetData data)
 {
     mData = data;
     mTimeSignature.SetTimeSignature(data.mTimeSignature);
     mRepeatCount = 0;
     UpdateTempo();
 }
        /// <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);
        }
        /// <summary>
        /// Saves our instrument set data
        /// </summary>
        /// <param name="pathIN"></param>
        /// <param name="data"></param>
        public static void SaveData(string pathIN, InstrumentSetData data)
        {
            data.mVersion = MusicGenerator.Version;
            pathIN        = pathIN + "/InstrumentSetData.txt";
            string save = JsonUtility.ToJson(data);

            File.WriteAllText(pathIN, save);
            UnityEngine.Debug.Log("file successfully written to " + pathIN);
        }
Exemple #4
0
        /// <summary>
        /// Loads data for the instrument set.
        /// </summary>
        /// <param name="folderIN"></param>
        private IEnumerator LoadInstrumentSetData(string argDirectory)
        {
            InstrumentSetData setData = null;

            yield return(StartCoroutine(InstrumentSetData.LoadData(argDirectory, (x) => { setData = x; })));

            MusicGenerator.Instance.mInstrumentSet.LoadData(setData);
            yield return(null);
        }
Exemple #5
0
        /// <summary>
        /// saves a global configuration: instruments, instrument and global settings.
        /// </summary>
        /// <param name="argFileName"></param>
        public static void SaveConfiguration(string argFileName)
        {
            string directory = GetPersistentSaveDirectory(argFileName);

            MusicGeneratorData.SaveData(directory, MusicGenerator.Instance.mGeneratorData);
            InstrumentSetData.SaveData(directory, MusicGenerator.Instance.mInstrumentSet.mData);
            ChordProgressionData.SaveData(directory, MusicGenerator.Instance.mChordProgressions.mData);
            SaveInstrumentData(directory);
            UnityEngine.Debug.Log(directory + " was successfully written to file");
        }
 private static InstrumentSetData UpdateVersion(string pathIN, InstrumentSetData save)
 {
     if (save == null || save.mVersion == 0.0f)
     {
         string generatorPath = MusicFileConfig.GetConfigDirectory(pathIN) + "/generator.txt";
         /// we need to grab these from the generatorSave as the variables belonged to that in the last version
         if (File.Exists(generatorPath))
         {
             GeneratorSave generatorSave = JsonUtility.FromJson <GeneratorSave>(File.ReadAllText(generatorPath));
             save                   = new InstrumentSetData();
             save.Tempo             = generatorSave.mTempo;
             save.RepeatMeasuresNum = generatorSave.mRepeatMeasuresNum;
             save.mProgressionRate  = (eProgressionRate)generatorSave.mProgressionRate;
             save.mTimeSignature    = generatorSave.mTimeSignature;
         }
     }
     return(save);
 }
        /// <summary>
        /// Loads our instrument set data
        /// </summary>
        /// <param name="pathIN"></param>
        /// <returns></returns>
        public static InstrumentSetData LoadData(string pathIN)
        {
            string data = "";
            string instrumentSetDataPath = MusicFileConfig.GetConfigDirectory(pathIN) + "/InstrumentSetData.txt";

            if (File.Exists(instrumentSetDataPath))
            {
                data = File.ReadAllText(instrumentSetDataPath);
            }
            else
            {
                throw new ArgumentNullException("Instrument set configuration does not exist at " + pathIN);
            }
            InstrumentSetData saveOUT = JsonUtility.FromJson <InstrumentSetData>(data);

            if (saveOUT == null || saveOUT.mVersion != MusicGenerator.Version)
            {
                return(UpdateVersion(pathIN, saveOUT));
            }

            return(saveOUT);
        }
Exemple #8
0
        /// <summary>
        /// Loads data for the instrument set.
        /// </summary>
        /// <param name="folderIN"></param>
        private static void LoadInstrumentSetData(string folderIN)
        {
            InstrumentSetData setData = InstrumentSetData.LoadData(folderIN);

            MusicGenerator.Instance.mInstrumentSet.LoadData(setData);
        }