Esempio n. 1
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);
        }
Esempio n. 2
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. 3
0
        /// <summary>
        /// Saves to json
        /// </summary>
        /// <param name="pathIN"></param>
        /// <param name="data"></param>
        public static void SaveData(string pathIN, InstrumentData data)
        {
            data.mVersion = MusicGenerator.Version;
            string save = JsonUtility.ToJson(data);

            File.WriteAllText(pathIN, save);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /////////////////////////////////////////
        /// Save / Load functions.
        /////////////////////////////////////////

        /// <summary>
        /// loads and sets values from save file.
        /// </summary>
        /// <param name="data"></param>
        public void LoadInstrument(InstrumentData data)
        {
            mData = data;
            string stringIndex = InstrumentIndex.ToString();

            mMusicGenerator.mMixer.SetFloat("Volume" + stringIndex, data.AudioSourceVolume);
            mMusicGenerator.mMixer.SetFloat("Reverb" + stringIndex, mData.Reverb);
            mMusicGenerator.mMixer.SetFloat("RoomSize" + stringIndex, mData.RoomSize);
            mMusicGenerator.mMixer.SetFloat("Chorus" + stringIndex, mData.Chorus);
            mMusicGenerator.mMixer.SetFloat("Flange" + stringIndex, mData.Flanger);
            mMusicGenerator.mMixer.SetFloat("Distortion" + stringIndex, mData.Distortion);
            mMusicGenerator.mMixer.SetFloat("Echo" + stringIndex, mData.Echo);
            mMusicGenerator.mMixer.SetFloat("EchoDelay" + stringIndex, mData.EchoDelay);
            mMusicGenerator.mMixer.SetFloat("EchoDecay" + stringIndex, mData.EchoDecay);
        }
Esempio n. 6
0
        /// <summary>
        ///  Instrument initialization
        /// </summary>
        /// <param name="index"></param>
        public void Init(int index)
        {
            mNeedsTheme           = true;
            mbAreRepeatingPattern = false;
            mbAreSettingPattern   = false;
            mCurrentPatternStep   = 0;
            mData              = new InstrumentData();
            InstrumentIndex    = index;
            mPatternstepsTaken = 0;

            mMusicGenerator = MusicGenerator.Instance;
            LoadClipNotes();
            InitRepeatingAndThemeNotes();
            ClearClipNotes();
            InitPatternNotes();
            SetupNoteGenerators();
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
0
        /// loads from json
        public static InstrumentData LoadData(string pathIN, string fileName)
        {
            string configPath = MusicFileConfig.GetConfigDirectory(pathIN) + fileName;
            string data       = "";

            if (File.Exists(configPath))
            {
                data = File.ReadAllText(configPath);
            }
            else
            {
                throw new ArgumentNullException("Instrument configuration does not exist at " + configPath);
            }

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

            saveOUT.mInstrumentType = saveOUT.mInstrumentType.ToLower();
            if (saveOUT.mVersion != MusicGenerator.Version)
            {
                return(UpdateVersion(data, pathIN + fileName, saveOUT));
            }

            return(saveOUT);
        }
Esempio n. 10
0
        /// <summary>
        /// Updates the save version to match the music generator's version
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pathIN"></param>
        /// <param name="saveOUT"></param>
        /// <returns></returns>
        private static InstrumentData UpdateVersion(string data, string pathIN, InstrumentData saveOUT)
        {
            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
                    };
                }
            }
            return(saveOUT);
        }