예제 #1
0
        private void DrawNotes(Rect rect, InstancedPattern pattern)
        {
            var  original = Current.uniquePatterns[pattern.pattern];
            byte highest  = (byte)(original.Highest + 2);
            byte lowest   = (byte)(original.Lowest - 2);

            //Debug.Log(highest + ", " + lowest);

            if (Event.current.type == EventType.Repaint)
            {
                GUI.BeginClip(rect);
                //GL.PushMatrix();
                GL.Clear(true, false, Color.black * 1f);
                glMaterial.SetPass(0);

                GL.Begin(GL.LINES);
                GL.Color(Color.white * 1f);

                //draw note lines
                for (int i = 0; i < Current.instruments.Count; i++)
                {
                    foreach (var note in original.notes[i].notes)
                    {
                        float remap = Remap(note.note, lowest, highest, rect.height, 0);
                        GL.Vertex3(note.start, remap, 0);
                        GL.Vertex3(note.end, remap, 0);
                    }
                }

                GL.End();
                GUI.EndClip();
            }
        }
예제 #2
0
 public InstancedPattern(InstancedPattern original)
 {
     name    = original.name;
     time    = original.time;
     order   = original.order;
     pattern = original.pattern;
 }
예제 #3
0
파일: Player.cs 프로젝트: popcron/synthy
            public Note(string instrument, Synthy.Note note, InstancedPattern instancedPattern)
            {
                this.instrument = instrument;
                this.note       = note;

                start = note.start + instancedPattern.time;
                end   = note.end + instancedPattern.time;
            }
예제 #4
0
        private void Add(Vector2Int position, Pattern pattern)
        {
            InstancedPattern instancedPattern = new InstancedPattern(pattern, Current)
            {
                time  = position.x - LeftOffset,
                order = (byte)(position.y / (float)TrackHeight)
            };

            Current.patterns.Add(instancedPattern);
        }
예제 #5
0
        public static void Initialize(InstancedPattern instancedPattern, Track track)
        {
            EditorSequencerPianoRoll window = GetWindow <EditorSequencerPianoRoll>("Piano roll");

            var pattern = track.uniquePatterns[instancedPattern.pattern];

            Current           = pattern;
            window.instrument = 0;

            //focus on first note
            window.Focus();
        }
예제 #6
0
        private void OnGUI()
        {
            Repaint();

            Toolbar();
            Drag();
            Grid();
            Mouse();

            //draw the tracks
            int tracks = Mathf.CeilToInt(Screen.width / MaxTracks);

            for (int i = 0; i < tracks; i++)
            {
                Rect position = new Rect(0, TopOffset + i * TrackHeight, LeftOffset, TrackHeight);
                if (i < MaxTracks)
                {
                    GUI.Box(position, "Track " + (i + 1), EditorStyles.helpBox);
                }
                else
                {
                    GUI.Box(position, "", EditorStyles.helpBox);
                }
            }

            //draw the patterns
            bool deselect = true;

            foreach (var pattern in Current.patterns)
            {
                Rect rect     = new Rect(LeftOffset + pattern.time, TopOffset + pattern.order * TrackHeight, pattern.GetLength(Current), TrackHeight);
                bool contains = rect.Contains(Event.current.mousePosition);
                if (contains)
                {
                    deselect = false;
                }

                if (MouseDown && contains && dragOffset == null)
                {
                    //start dragging the pattern
                    var pos = new Vector2(pattern.time + LeftOffset, TopOffset + pattern.order * TrackHeight);
                    dragOffset      = GetPatternPosition(Event.current.mousePosition - pos - Vector2.down * TopOffset);
                    patternDragging = pattern;
                    dragStart       = Event.current.mousePosition;
                    dragDistance    = 0f;
                    //Debug.Log("Started dragging " + pattern.Name);
                }
                else if (MouseDown && dragOffset != null)
                {
                    if (pattern == patternDragging)
                    {
                        //snap the position of the pattern to the mouse
                        pattern.time = GetPatternPosition().x - LeftOffset - (int)dragOffset.Value.x;
                        pattern.time = pattern.time < 0 ? 0 : pattern.time;

                        float my = Event.current.mousePosition.y < TopOffset ? TopOffset : Event.current.mousePosition.y;
                        int   patternPositionY = GetPatternPosition(new Vector2(Event.current.mousePosition.x, my)).y;
                        patternPositionY = patternPositionY < 0 ? 0 : patternPositionY;

                        pattern.order = (byte)(((uint)patternPositionY - (uint)dragOffset.Value.y) / (float)TrackHeight);
                        pattern.order = pattern.order > MaxTracks - 1 ? (byte)(MaxTracks - 1) : pattern.order;
                        dragDistance  = Vector2.Distance(dragStart, Event.current.mousePosition);
                    }
                }
                else if (!MouseDown && dragOffset != null)
                {
                    //stop dragging
                    //Debug.Log("Stopped dragging");
                    patternDragging = null;
                    dragOffset      = null;
                }

                //display the pattern box
                if (DrawBox(rect, pattern.name, 0.5f))
                {
                    if (EditorApplication.timeSinceStartup > nextPianoRollOpen)
                    {
                        //Debug.Log(Event.current.button);
                        //only register a click if the drag distance was small enough
                        if (dragDistance < 1f)
                        {
                            //left click to edit
                            //right click to delete
                            if (Event.current.button == 0)
                            {
                                //double click to open piano roll
                                if (lastClick != null && EditorApplication.timeSinceStartup - lastClick < 0.25)
                                {
                                    EditorSequencerPianoRoll.Initialize(pattern, Current);
                                    lastClick = null;
                                }
                                else
                                {
                                    //if double click failed
                                    //simply select it on the browser
                                    if (pattern.pattern != EditorSequencerBrowser.Selected)
                                    {
                                        EditorSequencerBrowser.Selected = pattern.pattern;

                                        //new selected pattern is different, reset the double click timer
                                        lastClick = null;
                                    }
                                    else
                                    {
                                        lastClick = EditorApplication.timeSinceStartup;
                                    }
                                }
                            }
                            else if (Event.current.button == 1)
                            {
                                Current.patterns.Remove(pattern);
                                return;
                            }
                        }
                    }
                }

                //display the pattern notes
                DrawNotes(rect, pattern);
            }

            //didnt click on any patterns in the playlist
            //so place a pattern here if one is selected
            if (deselect && EditorSequencerBrowser.Selected != null)
            {
                if (Event.current.button == 0)
                {
                    if (Event.current.type == EventType.MouseDown)
                    {
                        nextPianoRollOpen = EditorApplication.timeSinceStartup + 0.5;
                        var mouse   = GetPatternPosition();
                        var pattern = Current.uniquePatterns[EditorSequencerBrowser.Selected.Value];
                        Add(mouse, pattern);
                    }
                }
            }
        }