Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            Color prev_color = GUI.backgroundColor;

            GUILayout.Space(5f);
            HelmSequencer helmSequencer         = target as HelmSequencer;
            Rect          sequencerPositionRect = GUILayoutUtility.GetRect(minWidth, positionHeight, GUILayout.ExpandWidth(true));
            Rect          rect           = GUILayoutUtility.GetRect(minWidth, sequencerHeight, GUILayout.ExpandWidth(true));
            Rect          velocitiesRect = GUILayoutUtility.GetRect(minWidth, velocitiesHeight, GUILayout.ExpandWidth(true));

            if (sequencer.DoSequencerEvents(rect, helmSequencer, allNotes))
            {
                Repaint();
            }
            if (velocities.DoVelocityEvents(velocitiesRect, helmSequencer, allNotes))
            {
                Repaint();
            }

            sequencerPosition.DrawSequencerPosition(sequencerPositionRect, helmSequencer);
            velocities.DrawSequencerVelocities(velocitiesRect, helmSequencer, allNotes);

            if (rect.height == sequencerHeight)
            {
                sequencer.DrawSequencer(rect, helmSequencer, allNotes);
            }
            GUILayout.Space(5f);
            GUI.backgroundColor = prev_color;

            if (GUILayout.Button(new GUIContent("Clear Sequencer", "Remove all notes from the sequencer.")))
            {
                Undo.RecordObject(helmSequencer, "Clear Sequencer");
                helmSequencer.Clear();
            }

            if (GUILayout.Button(new GUIContent("Load MIDI File [BETA]", "Load a MIDI sequence into this sequencer.")))
            {
                string path = EditorUtility.OpenFilePanel("Load MIDI Sequence", "", "mid");
                if (path.Length != 0)
                {
                    Undo.RecordObject(helmSequencer, "Load MIDI File");
                    helmSequencer.ReadMidiFile(new FileStream(path, FileMode.Open, FileAccess.Read));
                }
            }

            EditorGUILayout.IntSlider(channel, 0, Utils.kMaxChannels - 1);
            EditorGUILayout.IntSlider(length, 1, Sequencer.kMaxLength);
            EditorGUILayout.PropertyField(division);
            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 2
0
        public void DrawSequencer(Rect rect, Sequencer sequencer, float zoomPercent, SerializedProperty allNotes)
        {
            float divisionLength = sequencer.GetDivisionLength();

            numRows       = maxKey - minKey + 1;
            numCols       = Mathf.RoundToInt(sequencer.length / divisionLength);
            numSixteenths = Mathf.RoundToInt(sequencer.length);

            float zoomLog  = Mathf.Log(maxColZoomWidth / minColWidth);
            float zoomSize = minColWidth * Mathf.Exp(zoomLog * zoomPercent);
            float minWidth = Mathf.Max(zoomSize, minColWidth);

            colWidth       = Mathf.Max(minWidth * divisionLength, (rect.width - keyboardWidth - rightPadding) / numCols);
            sixteenthWidth = Mathf.Max(minWidth, (rect.width - keyboardWidth - rightPadding) / numSixteenths);

            float noteAreaHeight = rect.height - bottomPadding - velocitySectionHeight;

            rowHeight = Mathf.Clamp(noteAreaHeight / numRows, minRowHeight, maxRowHeight);
            float scrollableWidth  = numCols * colWidth + keyboardWidth + 1;
            float scrollableHeight = numRows * rowHeight + velocitySectionHeight;

            Rect scrollableArea = new Rect(0, 0, scrollableWidth, scrollableHeight);

            if (sequencer.autoScroll && sequencer.isActiveAndEnabled &&
                EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                float playPosition = keyboardWidth + colWidth * sequencer.currentIndex;
                scrollPosition = sequencer.scrollPosition;
                if (playPosition < scrollPosition.x - keyboardWidth ||
                    playPosition + colWidth >= scrollPosition.x - keyboardWidth + rect.width)
                {
                    scrollPosition.x = playPosition - keyboardWidth;
                }
                sequencer.scrollPosition = scrollPosition;
            }
            sequencer.scrollPosition = GUI.BeginScrollView(rect, sequencer.scrollPosition, scrollableArea, true, true);
            scrollPosition           = sequencer.scrollPosition;

            DrawNoteRows(rect);
            DrawBarHighlights(rect);
            DrawNoteDivisionLines(rect);
            DrawActiveNotes(sequencer, divisionLength, rect);
            DrawPressedNotes(divisionLength);
            DrawPositionOverlay(sequencer, rect);

            velocities.DrawSequencerVelocities(GetVelocityRect(rect), sequencer,
                                               GetMinVisibleTime(), GetMaxVisibleTime(rect.width));

            GUI.EndScrollView();
        }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            Color prev_color = GUI.backgroundColor;

            GUILayout.Space(5f);
            SampleSequencer sampleSequencer = target as SampleSequencer;
            Sampler         sampler         = sampleSequencer.GetComponent <Sampler>();

            if (sampler)
            {
                sequencer.minKey = sampler.GetMinKey();
                sequencer.maxKey = sampler.GetMaxKey();
            }
            else
            {
                sequencer.minKey = 0;
                sequencer.maxKey = Utils.kMidiSize - 1;
            }

            Rect  sequencerPositionRect = GUILayoutUtility.GetRect(minWidth, positionHeight, GUILayout.ExpandWidth(true));
            float seqHeight             = Mathf.Min(sequencerHeight, sequencer.GetMaxHeight());
            Rect  rect           = GUILayoutUtility.GetRect(minWidth, seqHeight, GUILayout.ExpandWidth(true));
            Rect  velocitiesRect = GUILayoutUtility.GetRect(minWidth, velocitiesHeight, GUILayout.ExpandWidth(true));

            if (sequencer.DoSequencerEvents(rect, sampleSequencer, allNotes))
            {
                Repaint();
            }
            if (velocities.DoVelocityEvents(velocitiesRect, sampleSequencer, allNotes))
            {
                Repaint();
            }

            sequencerPosition.DrawSequencerPosition(sequencerPositionRect, sampleSequencer);
            velocities.DrawSequencerVelocities(velocitiesRect, sampleSequencer, allNotes);

            if (rect.height == seqHeight)
            {
                sequencer.DrawSequencer(rect, sampleSequencer, allNotes);
            }
            GUILayout.Space(5f);
            GUI.backgroundColor = prev_color;

            if (GUILayout.Button(new GUIContent("Clear Sequencer", "Remove all notes from the sequencer.")))
            {
                Undo.RecordObject(sampleSequencer, "Clear Sequencer");

                for (int i = 0; i < allNotes.arraySize; ++i)
                {
                    SerializedProperty noteRow = allNotes.GetArrayElementAtIndex(i);
                    SerializedProperty notes   = noteRow.FindPropertyRelative("notes");
                    notes.ClearArray();
                }
                sampleSequencer.Clear();
            }

            if (GUILayout.Button(new GUIContent("Load MIDI File [BETA]", "Load a MIDI sequence into this sequencer.")))
            {
                string path = EditorUtility.OpenFilePanel("Load MIDI Sequence", "", "mid");
                if (path.Length != 0)
                {
                    Undo.RecordObject(sampleSequencer, "Load MIDI File");
                    sampleSequencer.ReadMidiFile(new FileStream(path, FileMode.Open, FileAccess.Read));
                }
            }

            EditorGUILayout.IntSlider(length, 1, Sequencer.kMaxLength);
            EditorGUILayout.PropertyField(division);
            serializedObject.ApplyModifiedProperties();
        }