示例#1
0
        public void PrepareClip(MyMMLClip clip)
        {
            AssetBundle      bundle = null;
            ClipPreparingJob job    = new ClipPreparingJob(this, clip, bundle, false);

            jobListA.AddLast(job.Prepare());
        }
            public sealed override float GetPropertyHeight(SerializedProperty property, GUIContent label)
            {
                MyMMLClip clip = getParent(property) as MyMMLClip;

                if (clip == null)
                {
                    return(0.0f);
                }
                float y = 0;
                float h = EditorGUIUtility.singleLineHeight;
                float s = EditorGUIUtility.standardVerticalSpacing;

                textAreaHeight = CalcTextAreaHeight((clip.textB != null) ? clip.textB : "", 1, 8);
                y += h;                  // textA
                y += h + textAreaHeight; // textB
                y += h;                  // textC
                y += h;                  // ports
                y += h;                  // generateAudioClip
                if (clip.Error.Length > 0)
                {
                    y += h + s * 2 + s;
                }
                y += h; // audioClip;
                return(y);
            }
示例#3
0
 public void Add(MyMMLClip clip)
 {
     if ((syntheStation != null) && isActiveAndEnabled)
     {
         syntheStation.PrepareClip(clip);
     }
     clips.Add(clip);
 }
示例#4
0
            public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                MyMMLClip clip = getParent(property) as MyMMLClip;

                if (clip == null)
                {
                    return;
                }
                SerializedProperty clipProp = getParentProperty(property);
                float y  = position.yMin;
                float h  = EditorGUIUtility.singleLineHeight;
                float s  = EditorGUIUtility.standardVerticalSpacing;
                bool  tx = (clip.textA != null) || ((clip.textB != null) && (clip.textB.Length > 0)) || (clip.textC != null);
                bool  ac = (clip.audioClip != null);

                EditorGUI.BeginDisabledGroup(ac && !tx);
                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textA"));
                y = position.yMax;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.LabelField(position, "Text B");
                y             = position.yMax;
                position.yMin = y;
                position.yMax = y + textAreaHeight;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textB"), GUIContent.none);
                y = position.yMax + s;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textC"));
                y = position.yMax;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("generateAudioClip"));
                y = position.yMax;

                if (clip.Error.Length > 0)
                {
                    position.yMin = y;
                    position.yMax = y + h + s * 2;
                    EditorGUI.HelpBox(EditorGUI.IndentedRect(position), clip.Error, MessageType.Error);
                    y = position.yMax + s;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(tx);
                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("audioClip"));
                y = position.yMax;
                EditorGUI.EndDisabledGroup();
            }
示例#5
0
 public void Stop()
 {
     if (state == PlayState.Stopped)
     {
         return;
     }
     sequencer.Stop(fadeOutTime);
     clip  = null;
     state = PlayState.Stopped;
 }
示例#6
0
 public void Play(MyMMLClip Clip)
 {
     if (sequencer == null)
     {
         return;
     }
     sequencer.Stop(playOutTime);
     clip  = Clip;
     state = PlayState.Prepareing;
 }
示例#7
0
 public ClipPreparingJob(MySyntheStation Station, MyMMLClip Clip, AssetBundle Bundle, bool DontGenerate)
 {
     station      = Station;
     clip         = Clip;
     bundle       = Bundle;
     mmlText      = clip.Text;
     clip.Dirty   = false;
     clip.Unit    = null;
     dontGenerate = DontGenerate;
 }
示例#8
0
        public void PrepareClipBlocked(MyMMLClip clip)
        {
            AssetBundle      bundle = null;
            ClipPreparingJob job    = new ClipPreparingJob(this, clip, bundle, true);
            var i = job.Prepare();

            while (i.MoveNext())
            {
                ;
            }
        }
示例#9
0
        public MyMMLClip Play(int port, int channel, float tempoScale, float volume, params string[] mml)
        {
            if (sequencer == null)
            {
                return(null);
            }
            sequencer.Stop(playOutTime);
            if ((port < 0) || (port >= MyMMLSequence.MaxNumPorts))
            {
                return(null);
            }
            if ((channel < 0) || (channel >= MySynthesizer.NumChannels))
            {
                return(null);
            }
            if ((mml.Length == 0) || (mml.Length >= MyMMLSequence.MaxNumTracks))
            {
                return(null);
            }
            clip            = new MyMMLClip();
            clip.Name       = "Impromptu";
            clip.TempoScale = tempoScale;
            clip.Volume     = volume;
            var sb = MyFountain <System.Text.StringBuilder> .Get(() => new System.Text.StringBuilder());

            sb.Length = 0;
            for (int i = 0; i < mml.Length; i++)
            {
                if (mml[i] == null)
                {
                    continue;
                }
                sb.Append("$t" + i.ToString("d2") + "=" + port.ToString() + ":" + channel.ToString() + "\n");
            }
            for (int i = 0; i < mml.Length; i++)
            {
                if (mml[i] == null)
                {
                    continue;
                }
                sb.Append("t" + i.ToString("d2") + "=" + mml[i] + "\n");
            }
            clip.TextB = sb.ToString();
            sb.Length  = 0;
            MyFountain <System.Text.StringBuilder> .Put(sb);

            state = PlayState.Prepareing;
            return(clip);
        }
示例#10
0
 void OnDisable()
 {
     //Debug.Log("OnDisable:" + Application.isPlaying);
     if (sequencer == null)
     {
         return;
     }
     if (sequencer.Playing)
     {
         sequencer.Stop(0.0f);
     }
     if (syntheStation != null)
     {
         syntheStation.RemoveSequencer(sequencer);
     }
     clip      = null;
     sequencer = null;
     state     = PlayState.Stopped;
 }
示例#11
0
 private void play(MyMMLClip clip)
 {
     if (sequencer == null)
     {
         sequencer = new MyMMLSequencer(syntheStation.TickFrequency);
         syntheStation.AddSequencer(sequencer);
     }
     else
     {
         sequencer.Stop(0.0f);
     }
     for (int j = 0; j < syntheStation.Synthesizers.Count; j++)
     {
         sequencer.SetSynthesizer(j, syntheStation.Synthesizers[j], clip.VoiceMask);
     }
     sequencer.VolumeScale = clip.Volume;
     sequencer.TempoScale  = clip.TempoScale;
     sequencer.KeyShift    = clip.Key;
     sequencer.Play(clip.Unit.Sequence, clip.Unit.ToneMap, 0.0f, false);
 }
示例#12
0
 private void OnDisable()
 {
     //Debug.Log("OnDisable:" + Application.isPlaying);
     if (sequencer == null)
     {
         return;
     }
     if (sequencer.Playing)
     {
         sequencer.Stop(0.0f);
     }
     if (syntheStation != null)
     {
         syntheStation.RemoveSequencer(sequencer);
     }
     sequencer.AppDataEvent     -= appDataEvent;
     sequencer.PlayingEvent     -= playingEvent;
     sequencer.NextSectionEvent -= nextSectionEvent;
     clip          = null;
     sequencer     = null;
     state         = PlayState.Stopped;
     syntheStation = null;
 }
示例#13
0
            public sealed override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                MyMMLClip clip = getParent(property) as MyMMLClip;

                if (clip == null)
                {
                    return;
                }
                SerializedProperty clipProp = getParentProperty(property);
                float y  = position.yMin;
                float h  = EditorGUIUtility.singleLineHeight;
                float s  = EditorGUIUtility.standardVerticalSpacing;
                bool  tx = (clip.textA != null) || ((clip.textB != null) && (clip.textB.Length > 0)) || (clip.textC != null);
                bool  ac = (clip.audioClip != null);

                EditorGUI.BeginDisabledGroup(ac && !tx);
                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textA"));
                y = position.yMax;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.LabelField(position, "Text B");
                y             = position.yMax;
                position.yMin = y;
                position.yMax = y + textAreaHeight;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textB"), GUIContent.none);
                y = position.yMax + s;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("textC"));
                y = position.yMax;

                position.yMin = y;
                position.yMax = y + h;
                var ports = clipProp.FindPropertyRelative("ports");

                EditorGUI.LabelField(position, "Ports");
                var indent = EditorGUI.indentLevel;

                EditorGUI.indentLevel = 0;
                if (ports.arraySize == 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        ports.InsertArrayElementAtIndex(i);
                        var p = ports.GetArrayElementAtIndex(i);
                        p.intValue = i;
                    }
                }
                var w = (position.width - EditorGUIUtility.labelWidth) / ports.arraySize;
                var r = new Rect(position.x + EditorGUIUtility.labelWidth, position.y, w - 2, position.height);

                for (int i = 0; i < ports.arraySize; i++)
                {
                    var elm = ports.GetArrayElementAtIndex(i);
                    elm.enumValueIndex = (int)(SyntheTypes)EditorGUI.EnumPopup(r, (SyntheTypes)elm.enumValueIndex);
                    r.x += w;
                }
                EditorGUI.indentLevel = indent;
                y = position.yMax;

                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("generateAudioClip"));
                y = position.yMax;

                if (clip.Error.Length > 0)
                {
                    position.yMin = y;
                    position.yMax = y + h + s * 2;
                    EditorGUI.HelpBox(EditorGUI.IndentedRect(position), clip.Error, MessageType.Error);
                    y = position.yMax + s;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(tx);
                position.yMin = y;
                position.yMax = y + h;
                EditorGUI.PropertyField(position, clipProp.FindPropertyRelative("audioClip"));
                y = position.yMax;
                EditorGUI.EndDisabledGroup();
            }
示例#14
0
 public IndexedClip(int index, MyMMLClip clip)
 {
     Index = index;
     Clip  = clip;
 }
示例#15
0
            static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
            {
                //Debug.Log(Event.current.type + ":" + EditorUtility.InstanceIDToObject(instanceID).name);
                //bool firstEvent = false;
                EventType eventType = Event.current.type;

                if (eventType == EventType.Used)
                {
                    //eventType = previousEventType;
                }
                else
                {
                    if (eventType != previousEventType)
                    {
                        //firstEvent = true;
                    }
                    previousEventType = eventType;
                }

                if (eventType == EventType.Repaint)
                {
                    if (style == null)
                    {
                        Texture2D tex = new Texture2D(4, 4);
                        Color     col = new Color(0.3f, 0.5f, 1.0f, 0.3f);
                        for (int y = 0; y < tex.height; y++)
                        {
                            for (int x = 0; x < tex.width; x++)
                            {
                                tex.SetPixel(x, y, col);
                            }
                        }
                        tex.Apply();
                        style      = new GUIStyle();
                        style.name = "dropTarget";
                        style.normal.background = tex;
                    }
                    if (dragging && (targetDirection != null) && (targetInstanceID == instanceID))
                    {
                        //targetRect = new Rect(0.0f, 0.0f, 64.0f, 64.0f);
                        //GUI.depth = 1;
                        GUI.Box(targetRect, GUIContent.none, style);
                    }
                }

                // ドラッグ中の処理
                if (eventType == EventType.DragUpdated)
                {
                    dragging   = true;
                    acceptable = false;
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        if (IsAcceptable(obj))
                        {
                            acceptable = true;
                        }
#if true
                        else
                        {
                            // 他の型がまじってたら処理しない。
                            acceptable = false;
                            break;
                        }
#endif
                    }
                    targetDirection = null;
                    if (acceptable)
                    {
                        targetDirection = CheckMousePosition(selectionRect);
                        if (targetDirection != null)
                        {
                            // drag受け入れ可の場合カーソル形状を変更。
                            DragAndDrop.visualMode      = DragAndDropVisualMode.Link;
                            DragAndDrop.activeControlID = instanceID;
                            //Event.current.Use();
                            targetInstanceID = instanceID;
                            targetRect       = selectionRect;
                            if (targetDirection < 0)
                            {
                                float y = targetRect.yMin;
                                targetRect.yMin = y - border;
                                targetRect.yMax = y + border;
                            }
                            else if (targetDirection > 0)
                            {
                                float y = targetRect.yMax;
                                targetRect.yMin = y - border;
                                targetRect.yMax = y + border;
                            }
                        }
                    }
                }

                // ドラッグ停止
                if (eventType == EventType.DragExited)
                {
                    dragging = false;
                }

                // ドロップ処理
                if (eventType == EventType.DragPerform)
                {
                    dragging = false;
                    if (targetDirection == null)
                    {
                        return;
                    }
                    if (instanceID != targetInstanceID)
                    {
                        return;
                    }
                    //Debug.Log(EditorUtility.InstanceIDToObject(instanceID).name);
                    var targetObj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
                    if (targetObj == null)
                    {
                        return;
                    }
                    DragAndDrop.AcceptDrag();
#if true
                    //Debug.Log("CheckObjectPosition:" + on);
                    Undo.RegisterFullObjectHierarchyUndo(targetObj, "");
                    MyMMLBox box = null;
                    if (targetDirection == 0)
                    {
                        box = targetObj.GetComponent <MyMMLBox>();
                    }
                    else
                    {
                        var parent = targetObj.transform.parent;
                        var index  = targetObj.transform.GetSiblingIndex() + ((targetDirection < 0) ? 0 : 1);
                        targetObj = CreateNewGameObject(parent);
                        Undo.RegisterCreatedObjectUndo(targetObj, "Create gameObject:" + targetObj.name);
                        //Undo.RegisterFullObjectHierarchyUndo(parent);
                        targetObj.transform.SetSiblingIndex(index);
                    }
                    if (box == null)
                    {
                        box = Undo.AddComponent <MyMMLBox>(targetObj);
                    }
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        TextAsset textAsset = obj as TextAsset;
                        if (textAsset && (obj.name.EndsWith(".mml")))
                        {
                            //string path = AssetDatabase.GetAssetPath(obj);
                            //Debug.Log("path:" + path);
                            MyMMLClip clip = new MyMMLClip();
                            clip.TextC = textAsset;
                            clip.Name  = obj.name.Substring(0, obj.name.LastIndexOf('.'));
                            box.Add(clip);
                        }
                    }
#endif
                }
            }
示例#16
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--;
                }
            }