void PartInfoLine() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Part")) { currentPart = music.NewPart(); } if (music.GetPartsNum() > 1) { if (GUILayout.Button("Remove Part")) { music.RemovePart(currentPart); currentPart = music.GetPart(0); } } string[] Timbres = new string[] { "PULSE", "TRIANGLE", "SINE", "SQUARE", "SAWTOOTH", "NOISE" }; int newtype = EditorGUILayout.Popup((int)type, Timbres); if (newtype != (int)type) { type = (SoundGenType)newtype; currentPart.Timbre = type; } int n = 0; string[] names = new string[music.GetPartsNum()]; for (int i = 0; i < music.GetPartsNum(); i++) { names[i] = "part " + (i + 1); if (music.GetPart(i) == currentPart) { n = i; } } int sel = GUILayout.Toolbar(n, names); currentPart = music.GetPart(sel); type = currentPart.Timbre; EditorGUILayout.EndHorizontal(); }
public MusicEditor() { music = new Music(); currentPart = music.GetPart(0); }
void ToolsLine() { EditorGUI.DrawRect(new Rect(0, 0, position.width, 60), new Color(0, 0, 0, 1)); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("New")) { music = new Music(); currentPart = music.GetPart(0); noteSpeed = music.Speed; } if (GUILayout.Button("Load")) { string fn = EditorUtility.OpenFilePanel("open file", Application.dataPath, "bytes"); if (!string.IsNullOrEmpty(fn)) { using (FileStream stream = new FileStream(fn, FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); music = new Music(); music.Load(reader); noteSpeed = music.Speed; currentPart = music.GetPart(0); } } } if (music != null) { if (GUILayout.Button("Save")) { string fn = EditorUtility.SaveFilePanel("save file", Application.dataPath, "new music", "bytes"); if (!string.IsNullOrEmpty(fn)) { using (FileStream stream = new FileStream(fn, FileMode.Create)) { BinaryWriter writer = new BinaryWriter(stream); music.Save(writer); } } } } GUILayout.Space(10); string[] girdSize = { "1\\8", "1\\4", "1\\2", "1\\3", "1" }; float[] girds = { 0.125f, 0.25f, 0.5f, 0.33333f, 1.0f }; sizeGird = EditorGUILayout.Popup(sizeGird, girdSize); sizeA = girds[sizeGird]; string newns = GUILayout.TextArea(noteSpeed.ToString()); int spd = int.Parse(newns); noteSpeed = spd; if (spd > 50 && spd < 200) { music.Speed = noteSpeed; } if (GUILayout.Button("Play")) { if (!testObj) { testObj = new GameObject(); testObj.name = "Editor Audio Object"; } music.Play(testObj); music.Time = 0; } if (GUILayout.Button("Pause/Resume")) { if (music.IsPlaying) { playTime = music.Time; music.Stop(); } else { if (!testObj) { testObj = new GameObject(); testObj.name = "Editor Audio Object"; } music.Play(testObj); music.Time = playTime; } } if (GUILayout.Button("Stop")) { music.Stop(); playTime = 0; } EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.KeyUp) { if (Event.current.control) { if (Event.current.keyCode == KeyCode.C) { Copy(); } else if (Event.current.keyCode == KeyCode.X) { Copy(); currentPart.RemoveSelected(); currentPart.CleanSelected(); music.UpdateParts(); } else if (Event.current.keyCode == KeyCode.V) { Paste(); } } } //if(Event.current.type == EventType.MouseDown) //{ // if (music.IsPlaying) // { // music.Stop(); // } //} }