Exemplo n.º 1
0
        public MusicPart NewPart()
        {
            MusicPart part = new MusicPart();

            partsList.Add(part);
            return(part);
        }
Exemplo n.º 2
0
        public void Load(BinaryReader reader)
        {
            string mark = reader.ReadString();

            if (mark != "8BM_")
            {
                Debug.LogError("File is not 8bit sound generator format!");
                return;
            }

            int ver = reader.ReadInt32();

            if (ver != version)
            {
                Debug.LogError("File version not fit!");
                return;
            }

            name  = reader.ReadString();
            speed = reader.ReadSingle();

            int count = reader.ReadInt32();

            partsList.Clear();

            for (int i = 0; i < count; i++)
            {
                MusicPart part = new MusicPart();
                part.Load(reader);

                partsList.Add(part);
            }
        }
Exemplo n.º 3
0
        public MusicPart Clone()
        {
            MusicPart newPart = new MusicPart();

            newPart.sample = sample;
            newPart.name   = name + "(Clone)";
            newPart.Length = Length;
            newPart.Timbre = Timbre;

            foreach (var n in musicalNotesList)
            {
                newPart.musicalNotesList.Add(n.Clone());
            }

            return(newPart);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 public void RemovePart(MusicPart part)
 {
     partsList.Remove(part);
 }
Exemplo n.º 6
0
 public MusicEditor()
 {
     music       = new Music();
     currentPart = music.GetPart(0);
 }
Exemplo n.º 7
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();
            //    }
            //}
        }