Esempio n. 1
0
        /// <summary>
        /// loads from json
        /// </summary>
        /// <param name="pathIN"></param>
        /// <returns></returns>
        public static void LoadData(string data, string fileName, System.Action <InstrumentData> callback)
        {
            InstrumentData saveOUT = null;

            saveOUT = JsonUtility.FromJson <InstrumentData>(data);
            saveOUT.mInstrumentType = saveOUT.mInstrumentType.ToLower();
            if (saveOUT.mVersion != MusicGenerator.Version)
            {
                InstrumentSave instrumentSave = JsonUtility.FromJson <InstrumentSave>(data);

                if (saveOUT != null)
                {
                    if (saveOUT.mVersion == 0.0f)
                    {
                        saveOUT.mStaffPlayerColor = (eStaffPlayerColors)instrumentSave.mStaffPlayerColor;
                    }
                    if (saveOUT.mVersion == 1.1f)
                    {
                        for (int i = 0; i < instrumentSave.mOctavesToUse.Count; i++)
                        {
                            saveOUT.mOctavesToUse.Add(instrumentSave.mOctavesToUse[i]);
                        }
                        saveOUT.mIsPentatonic   = false;
                        saveOUT.mLeadAvoidNotes = new int[2] {
                            -1, -1
                        };
                    }
                }

                InstrumentData.SaveData(fileName, saveOUT);
            }
            callback(saveOUT);
        }
Esempio n. 2
0
 /// <summary>
 /// Saves the instrument data
 /// </summary>
 /// <param name="argDirectory"></param>
 private static void SaveInstrumentData(string argDirectory)
 {
     for (int i = 0; i < MusicGenerator.mMaxInstruments; i++)
     {
         string fileName = argDirectory + "/instruments" + i + ".txt";
         if (i < MusicGenerator.Instance.mInstrumentSet.mInstruments.Count)
         {
             Instrument instrument = MusicGenerator.Instance.mInstrumentSet.mInstruments[i];
             InstrumentData.SaveData(fileName, instrument.mData);
         }
         else if (File.Exists(fileName))
         {
             /// If the user has deleted an instrument since the last save,
             /// we need to delete that file.
             File.Delete(fileName);
         }
     }
 }