Esempio n. 1
0
        void PCMReaderCallback(float[] buffer)
        {
            float time = (float)playPos / (Sample * speed);

            int current = playPos;

            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = 0.0f;
            }

            foreach (var n in musicalNotesList)
            {
                if (n.StartTime + n.KeepTime < time)
                {
                    continue;
                }

                if (n.Note < 0)
                {
                    continue;
                }

                SoundClip clip = new SoundClip(Timbre, Sample, MusicalNote.NoteHz[n.Note], MusicalNote.NoteHz[n.Note], 0, (n.KeepTime - 0.05f) * speed);

                int start = (int)(n.StartTime * (Sample * speed));

                float[] buf = clip.Data;
                int     ns  = start - playPos;
                for (int i = 0; i < buf.Length; i++)
                {
                    if (i + ns >= buffer.Length)
                    {
                        break;
                    }

                    if (i + ns >= 0)
                    {
                        current         = Mathf.Max(current, playPos + i + ns);
                        buffer[i + ns] += buf[i];
                    }
                }
            }

            playPos += buffer.Length;
        }
Esempio n. 2
0
        //public void MoveNote(MusicalNote note, float targetTime, int targetHz)
        //{
        //    note.StartTime = targetTime;
        //    note.Hz = targetHz;
        //}

        //public void ChangeNoteLeaps(MusicalNote note, LeapsTypes leaps, int leapsHz)
        //{
        //    note.LeapsType = leaps;
        //    note.LeapsHz = leapsHz;
        //}

        //public void ChangeNotePower(MusicalNote note, float power)
        //{
        //    note.Power = power;
        //}

        //public void ChangeNoteLength(MusicalNote note, float keepTime)
        //{
        //    note.KeepTime = keepTime;
        //}

        public float[] ExportData(float speed)
        {
            Sort();

            int len = (int)(Length * Sample * speed);

            float[] data = new float[len];

            foreach (var n in musicalNotesList)
            {
                if (n.Note < 0)
                {
                    continue;
                }

                SoundClip clip = new SoundClip(Timbre, Sample, MusicalNote.NoteHz[n.Note], MusicalNote.NoteHz[n.Note], 0, (n.KeepTime - 0.05f) * speed);

                int start = (int)(n.StartTime * Sample * speed);

                if (start >= len)
                {
                    break;
                }

                float[] buf = clip.Data;
                for (int i = 0; i < buf.Length; i++)
                {
                    if (start + i < len)
                    {
                        data[start + i] += buf[i];
                    }
                }
            }

            return(data);
        }
Esempio n. 3
0
        void CtrlNote()
        {
            if (Event.current.type == EventType.KeyUp)
            {
                if (Event.current.keyCode == KeyCode.Delete)
                {
                    currentPart.RemoveSelected();
                    currentPart.CleanSelected();
                }
            }

            if (music.IsPlaying)
            {
                selectStart.x = selectStart.y = -1;
                selectEnd     = selectStart;
                return;
            }

            if (selectStart.x >= 0 && selectStart.y >= 0 && selectStart.y < MusicalNote.Notes.Length)
            {
                if (currentPart.Selected.Length == 0)
                {
                    if (Event.current.type == EventType.MouseUp)
                    {
                        if (Event.current.shift)
                        {
                            if (Event.current.button == 0)
                            {
                                currentPart.Select(selectStart.y, selectEnd.y, selectStart.x * sizeA, selectEnd.x * sizeA);
                            }
                        }
                        else if (Event.current.control)
                        {
                            if (Event.current.button == 0)
                            {
                                playTime = selectStart.x * sizeA;
                            }
                        }
                        else
                        {
                            if (Event.current.button == 0)
                            {
                                if (testClip)
                                {
                                    DestroyImmediate(testClip);
                                    testClip = null;
                                }

                                if (testSource && testSource.gameObject)
                                {
                                    DestroyImmediate(testSource.gameObject);
                                }

                                currentPart.AddNote(selectStart.y, selectStart.x * sizeA, (selectEnd.x - selectStart.x + 1) * sizeA);

                                SoundClip soundClip = new SoundClip(currentPart.Timbre, 4000, MusicalNote.NoteHz[selectStart.y], MusicalNote.NoteHz[selectStart.y], 0, 0.5f, true);
                                testClip = AudioClip.Create("test", soundClip.Data.Length, 1, 4000, false);
                                testClip.SetData(soundClip.Data, 0);

                                GameObject test = new GameObject();
                                test.name       = "audio clip on shot";
                                testSource      = test.AddComponent <AudioSource>();
                                testSource.clip = testClip;
                                testSource.Play();
                            }
                            else if (Event.current.button == 1)
                            {
                                currentPart.Select(selectStart.y, selectStart.x * sizeA);
                                currentPart.RemoveSelected();
                                currentPart.CleanSelected();
                            }

                            music.UpdateParts();
                        }


                        selectStart.x = selectStart.y = -1;
                        selectEnd     = selectStart;
                    }
                }
                else
                {
                    if (Event.current.type == EventType.MouseUp)
                    {
                        if (selectEnd == selectStart)
                        {
                            currentPart.CleanSelected();
                        }
                        else
                        {
                            currentPart.MoveSelected(selectStart.x * sizeA, selectStart.y, selectEnd.x * sizeA, selectEnd.y);
                            selectStart.x = selectStart.y = -1;
                            selectEnd     = selectStart;

                            music.UpdateParts();
                        }
                    }
                }
            }
        }