Beispiel #1
0
 private void Update()
 {
     if (state == PlayState.Stopped)
     {
         return;
     }
     if (sequencer.Playing)
     {
         sequencer.KeyShift    = clip.Key + keyShift;
         sequencer.VolumeScale = clip.Volume * volume;
         sequencer.TempoScale  = clip.TempoScale * tempoScale;
     }
     if (state == PlayState.Playing)
     {
         if (!sequencer.Playing)
         {
             Stop();
         }
         return;
     }
     if (state != PlayState.Prepareing)
     {
         return;
     }
     if (sequencer.Playing)
     {
         return;
     }
     if (syntheStation == null)
     {
         return;
     }
     if (clip.Dirty)
     {
         syntheStation.PrepareClip(clip);
     }
     if (!clip.Prepared)
     {
         return;
     }
     if (!clip.Ready)
     {
         Stop();
         return;
     }
     for (int i = 0; i < clip.Ports.Length; i++)
     {
         var s = (int)clip.Ports[i];
         if ((s >= 0) && (s <= syntheStation.Synthesizers.Count))
         {
             sequencer.SetSynthesizer(i, syntheStation.Synthesizers[s], clip.VoiceMask);
         }
     }
     sequencer.KeyShift    = clip.Key + keyShift;
     sequencer.VolumeScale = clip.Volume * volume;
     sequencer.TempoScale  = clip.TempoScale * tempoScale;
     sequencer.Play(clip.Unit.Sequence, clip.Unit.ToneMap, fadeInTime, clip.Loop);
     state = PlayState.Playing;
 }
 private void OnEnable()
 {
     syntheStation = FindObjectOfType <MySyntheStation>();
     if (syntheStation == null)
     {
         return;
     }
     foreach (var clip in clips)
     {
         syntheStation.PrepareClip(clip);
     }
 }
Beispiel #3
0
 void Update()
 {
     if (state == PlayState.Stopped)
     {
         return;
     }
     if (sequencer.Playing)
     {
         sequencer.KeyShift    = clip.Key + keyShift;
         sequencer.VolumeScale = clip.Volume * volume;
         sequencer.TempoScale  = clip.Tempo * tempo;
     }
     if (state == PlayState.Playing)
     {
         if (!sequencer.Playing)
         {
             Stop();
         }
         return;
     }
     if (state != PlayState.Prepareing)
     {
         return;
     }
     if (sequencer.Playing)
     {
         return;
     }
     if (clip.Dirty)
     {
         syntheStation.PrepareClip(clip);
     }
     if (!clip.Prepared)
     {
         return;
     }
     if (!clip.Valid)
     {
         Stop();
         return;
     }
     for (int i = 0; i < clip.Unit.Synthesizers.Count; i++)
     {
         sequencer.SetSynthesizer(i, clip.Unit.Synthesizers[i], clip.Unit.ToneSet, clip.Unit.ToneMap, 0xffffffffU);
     }
     sequencer.AppDataEvent = AppDataEvent;
     sequencer.PlayingEvent = PlayingEvent;
     sequencer.KeyShift     = clip.Key + keyShift;
     sequencer.VolumeScale  = clip.Volume * volume;
     sequencer.TempoScale   = clip.Tempo * tempo;
     sequencer.Play(clip.Unit.Sequence, fadeInTime, false);
     state = PlayState.Playing;
 }
            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)
                {
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < property.arraySize; i++)
                    {
                        var prop1 = property.GetArrayElementAtIndex(i);
                        var clip  = prop1.GetTargetFieldValue() as MyMMLClip;
                        EditorGUI.BeginChangeCheck();
                        var nameProp = prop1.FindPropertyRelative("name");
                        var name     = (nameProp == null) ? prop1.name : nameProp.stringValue;
                        if ((name == null) || (name.Length < 1))
                        {
                            name = "New Clip";
                        }
                        var elmLabel = new GUIContent(char.ToUpper(name[0]) + name.Substring(1));
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(prop1, elmLabel, false);
                        if ((syntheStation == null) || (syntheStation.LivingDead) || (Application.isPlaying))
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Button("Play");
                            EditorGUI.EndDisabledGroup();
                        }
                        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.TempoScale;
                                sequencer.KeyShift    = clip.Key;
                            }
                            else
                            {
                                if (GUILayout.Button("Play"))
                                {
                                    if (!clip.Ready)
                                    {
                                        syntheStation.PrepareClip(clip, play, true);
                                    }
                                    else
                                    {
                                        play(clip);
                                    }
                                    return;
                                }
                            }
                        }
                        if (i == 0)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Button("Up");
                            EditorGUI.EndDisabledGroup();
                        }
                        else
                        {
                            if (GUILayout.Button("Up"))
                            {
                                property.MoveArrayElement(i, i - 1);
                                return;
                            }
                        }
                        EditorGUILayout.Space();
                        if (GUILayout.Button("Del"))
                        {
                            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"))
                    {
                        Undo.RecordObject(box, "Add New Clip");
                        box.Add(new MyMMLClip());
                        return;
                    }
                    EditorGUILayout.Space();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel--;
                }
            }