/// <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); } }
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); }