Exemple #1
0
            public override void OnInspectorGUI()
            {
#if false
                if (null == FindObjectOfType <MySyntheStation>())
                {
                    EditorGUILayout.HelpBox("MyMMLBox requires MySyntheStation", MessageType.Warning);
                }
#endif
                {
                    var curSyntheStation = FindObjectOfType <MySyntheStation>();
                    if (curSyntheStation != syntheStation)
                    {
                        syntheStation = curSyntheStation;
                        if (sequencer != null)
                        {
                            sequencer.Stop(0.0f);
                            syntheStation.RemoveSequencer(sequencer);
                            sequencer = null;
                        }
                    }
                }
                serializedObject.Update();
                EditorGUILayout.PropertyField(serializedObject.FindProperty("player"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("audioSource"));
                editorGUILayout_Clips(serializedObject.FindProperty("clips"));
                serializedObject.ApplyModifiedProperties();
            }
Exemple #2
0
 void onDisable()
 {
     if (sequencer != null)
     {
         sequencer.Stop(0.0f);
         syntheStation.RemoveSequencer(sequencer);
         sequencer = null;
     }
     syntheStation = null;
 }
Exemple #3
0
            private void editorGUILayout_Clips(SerializedProperty property)
            {
                MyMMLBox box    = property.serializedObject.targetObject as MyMMLBox;
                bool     expand = EditorGUILayout.Foldout(property.isExpanded, "Clips");

                property.isExpanded = expand;
                if (property.isExpanded)
                {
                    Repaint();
                    //
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < property.arraySize; i++)
                    {
                        SerializedProperty prop1 = property.GetArrayElementAtIndex(i);
                        MyMMLClip          clip  = getInstance(prop1) as MyMMLClip;
                        EditorGUI.BeginChangeCheck();
                        SerializedProperty nameProp = prop1.FindPropertyRelative("name");
                        string             name     = (nameProp == null) ? prop1.name : nameProp.stringValue;
                        if ((name == null) || (name.Length < 1))
                        {
                            name = "New Clip";
                        }
                        GUIContent elmLabel = new GUIContent(char.ToUpper(name[0]) + name.Substring(1));
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(prop1, elmLabel, false);
                        if ((syntheStation == null) || (syntheStation.LivingDead) || (Application.isPlaying))
                        {
                            bool old = GUI.enabled;
                            GUI.enabled = false;
                            GUILayout.Button("Play");
                            GUI.enabled = old;
                        }
                        else
                        {
                            if ((sequencer != null) && (sequencer.Playing) && (clip.Unit != null) && (sequencer.Sequence == clip.Unit.Sequence))
                            {
                                if (GUILayout.Button("Stop"))
                                {
                                    sequencer.Stop(0.0f);
                                    return;
                                }
                                sequencer.VolumeScale = clip.Volume;
                                sequencer.TempoScale  = clip.Tempo;
                                sequencer.KeyShift    = clip.Key;
                            }
                            else
                            {
                                if (GUILayout.Button("Play"))
                                {
                                    if (!clip.Valid)
                                    {
                                        syntheStation.PrepareClipBlocked(clip);
                                        if (!clip.Valid)
                                        {
                                            return;
                                        }
                                    }
                                    if (sequencer == null)
                                    {
                                        sequencer = new Synthesizer.MMLSequencer.MyMMLSequencer(syntheStation.TickFrequency);
                                        syntheStation.AddSequencer(sequencer);
                                    }
                                    else
                                    {
                                        sequencer.Stop(0.0f);
                                    }
                                    for (int j = 0; j < clip.Unit.Synthesizers.Count; j++)
                                    {
                                        sequencer.SetSynthesizer(j, clip.Unit.Synthesizers[j], clip.Unit.ToneSet, clip.Unit.ToneMap, 0xffffffffU);
                                    }
                                    sequencer.VolumeScale = clip.Volume;
                                    sequencer.TempoScale  = clip.Tempo;
                                    sequencer.KeyShift    = clip.Key;
                                    sequencer.Play(clip.Unit.Sequence, 0.0f, false);
                                    return;
                                }
                            }
                        }
                        EditorGUILayout.Space();
                        if (GUILayout.Button("Del"))
                        {
                            //Debug.Log("Delete");
                            prop1.isExpanded = false;
                            prop1.DeleteCommand();
                            return;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                        editorGUILayout_PropertyChildren(prop1);
                        if (EditorGUI.EndChangeCheck())
                        {
                            clip.Dirty = true;
                            //clip.Flush();
                        }
                    }
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    if (GUILayout.Button("Add New Clip"))
                    {
                        //Debug.Log("Add New Clip");
                        Undo.RecordObject(box, "Add New Clip");
                        box.Add(new MyMMLClip());
                        return;
                    }
                    EditorGUILayout.Space();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel--;
                }
            }