public bool DoSequencerEvents(Rect rect, Sequencer sequencer, SerializedProperty allNotes) { Event evt = Event.current; if (!evt.isMouse) { return(false); } Vector2 sequencerPosition = GetSequencerPosition(rect, evt.mousePosition, sequencer.length); float time = sequencerPosition.x; if (evt.type == EventType.MouseUp && mouseActive) { if (mode == Mode.kChangingVelocity) { velocities.DoVelocityEvents(GetVelocityRectGlobal(rect), sequencer, allNotes); mouseActive = false; } else { MouseUp(time, sequencer, allNotes); } return(true); } int note = (int)sequencerPosition.y; Rect ignoreScrollRect = new Rect(rect); ignoreScrollRect.width -= rightPadding; ignoreScrollRect.height -= bottomPadding; if (evt.type == EventType.MouseDown && ignoreScrollRect.Contains(evt.mousePosition)) { ignoreScrollRect.height -= velocitySectionHeight; if (ignoreScrollRect.Contains(evt.mousePosition)) { if (note > maxKey || note < minKey) { return(false); } MouseDown(note, time, sequencer, allNotes); } else { mode = Mode.kChangingVelocity; mouseActive = true; velocities.DoVelocityEvents(GetVelocityRectGlobal(rect), sequencer, allNotes); } } else if (evt.type == EventType.MouseDrag && mouseActive) { if (mode == Mode.kChangingVelocity) { return(velocities.DoVelocityEvents(GetVelocityRectGlobal(rect), sequencer, allNotes)); } return(MouseDrag(note, time, sequencer, allNotes)); } return(true); }
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(); }
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(); }