public MidiSequencerEvent Process(int frame)
 {
     seqEvt.Events.Clear();
     //stop or loop
     if (sampleTime >= (int)_MidiFile.Tracks[_track].TotalTime)
     {
         if (looping == true)
         {
             OnLoop?.Invoke();
             sampleTime = 0;
             //Clear the current programs for the channels.
             Array.Clear(currentPrograms, 0, currentPrograms.Length);
             //Clear vol, pan, and tune
             ResetControllers();
             //set bpm
             _MidiFile.BeatsPerMinute = _bpm;
             //Let the synth know that the sequencer is ready.
             eventIndex = 0;
         }
         else
         {
             sampleTime = 0;
             playing    = false;
             synth.NoteOffAll(true);
             return(null);
         }
     }
     while (eventIndex < _MidiFile.Tracks[_track].EventCount && _MidiFile.Tracks[_track].MidiEvents[eventIndex].deltaTime < (sampleTime + frame))
     {
         seqEvt.Events.Add(_MidiFile.Tracks[_track].MidiEvents[eventIndex]);
         eventIndex++;
     }
     return(seqEvt);
 }
Example #2
0
 protected override void HandleOnCompleted()
 {
     if (Loop)
     {
         OnLoop.SafeInvoke();
         base.Stop();
         Run();
     }
     else
     {
         base.HandleOnCompleted();
     }
 }
Example #3
0
 public Timer(float duration, int loop, bool instant, OnComplete onComplete, OnLoop onLoop)
 {
     this.duration      = duration;
     this.loop          = loop;
     started            = false;
     ended              = false;
     timeCreated        = Time.realtimeSinceStartup;
     onCompleteDelegate = onComplete;
     onLoopDelegate     = onLoop;
     if (instant)
     {
         Start();
     }
 }
Example #4
0
        private bool NewLoop(ResetMode loopResetMode)
        {
            bool needsToLoop = loopsRemaining > 0;

            if (!needsToLoop || !Loopable)
            {
                return(false);
            }

            --loopsRemaining;

            Reset(kill: false, loopResetMode);

            Start();

            OnLoop?.Invoke();

            return(true);
        }
 protected void InvokeLoop() => OnLoop?.Invoke();
Example #6
0
        public void Get()
        {
            var firstNode = GetClosestNode(actionSet, Nodes, Source);

            Assign();

            current   = actionSet.VarCollection.Assign("Dijkstra: Current", actionSet.IsGlobal, assignExtended);
            distances = actionSet.VarCollection.Assign("Dijkstra: Distances", actionSet.IsGlobal, false);
            unvisited = actionSet.VarCollection.Assign("Dijkstra: Unvisited", actionSet.IsGlobal, false);
            IndexReference connectedSegments = actionSet.VarCollection.Assign("Dijkstra: Connected Segments", actionSet.IsGlobal, assignExtended);
            IndexReference neighborIndex     = actionSet.VarCollection.Assign("Dijkstra: Neighbor Index", actionSet.IsGlobal, assignExtended);
            IndexReference neighborDistance  = actionSet.VarCollection.Assign("Dijkstra: Distance", actionSet.IsGlobal, assignExtended);

            parentArray = GetParentArray();
            if (useAttributes)
            {
                parentAttributeInfo = GetParentAttributeArray();
            }

            // Set the current variable as the first node.
            actionSet.AddAction(current.SetVariable(firstNode));
            SetInitialDistances(actionSet, distances, (Element)current.GetVariable());
            SetInitialUnvisited();

            actionSet.AddAction(Element.Part <A_While>(LoopCondition()));

            // Invoke LoopStart
            OnLoop.Invoke(actionSet);

            // Get neighboring indexes
            actionSet.AddAction(connectedSegments.SetVariable(GetConnectedSegments(
                                                                  (Element)current.GetVariable()
                                                                  )));

            // Loop through neighboring indexes
            ForeachBuilder forBuilder = new ForeachBuilder(actionSet, connectedSegments.GetVariable());

            // Invoke OnConnectLoop
            OnConnectLoop.Invoke(actionSet);

            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    // Get the index from the segment data
                                    neighborIndex.SetVariable(
                                        Element.Part <V_FirstOf>(Element.Part <V_FilteredArray>(
                                                                     BothNodes(forBuilder.IndexValue),
                                                                     new V_Compare(
                                                                         new V_ArrayElement(),
                                                                         Operators.NotEqual,
                                                                         current.GetVariable()
                                                                         )
                                                                     ))
                                        ),

                                    // Get the distance between the current and the neighbor index.
                                    neighborDistance.SetVariable(
                                        Element.Part <V_DistanceBetween>(
                                            Nodes[(Element)neighborIndex.GetVariable()],
                                            Nodes[(Element)current.GetVariable()]
                                            ) + ((Element)distances.GetVariable())[(Element)current.GetVariable()]
                                        )
                                    ));

            // Set the current neighbor's distance if the new distance is less than what it is now.
            actionSet.AddAction(Element.Part <A_If>(Element.Part <V_Or>(
                                                        new V_Compare(
                                                            ((Element)distances.GetVariable())[(Element)neighborIndex.GetVariable()],
                                                            Operators.Equal,
                                                            new V_Number(0)
                                                            ),
                                                        (Element)neighborDistance.GetVariable() < ((Element)distances.GetVariable())[(Element)neighborIndex.GetVariable()]
                                                        )));

            actionSet.AddAction(distances.SetVariable((Element)neighborDistance.GetVariable(), null, (Element)neighborIndex.GetVariable()));
            actionSet.AddAction(parentArray.SetVariable((Element)current.GetVariable() + 1, null, (Element)neighborIndex.GetVariable()));

            if (useAttributes)
            {
                if (!reverseAttributes)
                {
                    actionSet.AddAction(parentAttributeInfo.SetVariable(
                                            value: Element.TernaryConditional(
                                                new V_Compare(
                                                    current.GetVariable(),
                                                    Operators.Equal,
                                                    Node1(forBuilder.IndexValue)
                                                    ),
                                                Node2Attribute(forBuilder.IndexValue),
                                                Node1Attribute(forBuilder.IndexValue)
                                                ),
                                            index: neighborIndex.Get()
                                            ));
                }
                else
                {
                    actionSet.AddAction(parentAttributeInfo.SetVariable(
                                            value: Element.TernaryConditional(
                                                new V_Compare(
                                                    current.GetVariable(),
                                                    Operators.Equal,
                                                    Node1(forBuilder.IndexValue)
                                                    ),
                                                Node1Attribute(forBuilder.IndexValue),
                                                Node2Attribute(forBuilder.IndexValue)
                                                ),
                                            index: neighborIndex.Get()
                                            ));
                }
            }

            // End the if.
            actionSet.AddAction(new A_End());
            // End the for.
            forBuilder.Finish();

            // Remove the current node from the unvisited array.
            actionSet.AddAction(unvisited.ModifyVariable(Operation.RemoveFromArrayByValue, (Element)current.GetVariable()));
            EndLoop();
            actionSet.AddAction(current.SetVariable(LowestUnvisited(Nodes, (Element)distances.GetVariable(), (Element)unvisited.GetVariable())));

            actionSet.AddAction(new A_End());

            GetResult();

            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    current.SetVariable(0),
                                    distances.SetVariable(0),
                                    connectedSegments.SetVariable(0),
                                    neighborIndex.SetVariable(0),
                                    neighborDistance.SetVariable(0),
                                    parentArray.SetVariable(0),
                                    parentAttributeInfo.SetVariable(0)
                                    ));
        }