/// <summary> /// Set the reference command. /// </summary> /// <param name="c">The command to have its reference set.</param> public void SetReferenceCommand(SequenceCommand c) { switch (c.CommandType) { case SequenceCommands.Random: case SequenceCommands.TimeRandom: SetReferenceCommand((c.Parameter as RandomParameter).Command); break; case SequenceCommands.If: SetReferenceCommand(c.Parameter as SequenceCommand); break; case SequenceCommands.Variable: case SequenceCommands.TimeVariable: SetReferenceCommand((c.Parameter as VariableParameter).Command); break; case SequenceCommands.Time: SetReferenceCommand((c.Parameter as TimeParameter).Command); break; case SequenceCommands.Jump: case SequenceCommands.Call: (c.Parameter as UInt24Parameter).ReferenceCommand = Commands[(c.Parameter as UInt24Parameter).Index(Commands)]; break; case SequenceCommands.OpenTrack: (c.Parameter as OpenTrackParameter).ReferenceCommand = Commands[(c.Parameter as OpenTrackParameter).Index(Commands)]; break; } }
/// <summary> /// Set the index for a command from an offset. /// </summary> /// <param name="c">The command.</param> /// <param name="label">The label.</param> public int SetCommandLabel(SequenceCommand c, string label) { switch (c.CommandType) { case SequenceCommands.Random: case SequenceCommands.TimeRandom: SetCommandLabel((c.Parameter as RandomParameter).Command, label); break; case SequenceCommands.If: SetCommandLabel(c.Parameter as SequenceCommand, label); break; case SequenceCommands.Variable: case SequenceCommands.TimeVariable: SetCommandLabel((c.Parameter as VariableParameter).Command, label); break; case SequenceCommands.Time: SetCommandLabel((c.Parameter as TimeParameter).Command, label); break; case SequenceCommands.Jump: case SequenceCommands.Call: (c.Parameter as UInt24Parameter).Label = label; break; case SequenceCommands.OpenTrack: (c.Parameter as OpenTrackParameter).Label = label; break; } return(-1); }
/// <summary> /// Set the offset for a command from an index. /// </summary> /// <param name="c">The command.</param> /// <param name="offsetMap">The offset map.</param> public uint SetIndexOffset(SequenceCommand c, Dictionary <int, uint> offsetMap) { switch (c.CommandType) { case SequenceCommands.Random: case SequenceCommands.TimeRandom: return(SetIndexOffset((c.Parameter as RandomParameter).Command, offsetMap)); case SequenceCommands.If: return(SetIndexOffset(c.Parameter as SequenceCommand, offsetMap)); case SequenceCommands.Variable: case SequenceCommands.TimeVariable: return(SetIndexOffset((c.Parameter as VariableParameter).Command, offsetMap)); case SequenceCommands.Time: return(SetIndexOffset((c.Parameter as TimeParameter).Command, offsetMap)); case SequenceCommands.Jump: case SequenceCommands.Call: (c.Parameter as UInt24Parameter).Offset = offsetMap[(c.Parameter as UInt24Parameter).m_Index]; return((c.Parameter as UInt24Parameter).Offset); case SequenceCommands.OpenTrack: (c.Parameter as OpenTrackParameter).Offset = offsetMap[(c.Parameter as OpenTrackParameter).m_Index]; return((c.Parameter as OpenTrackParameter).Offset); } return(0xFFFFFFFF); }
public SequenceCommand Sequence() { var command = new SequenceCommand(); m_CommandList.Add(command); return(command); }
private void FinalizeRecording() { string sequenceComment = $"Web Sequence Recorded {DateTime.Now}"; var commentCommand = new AddCodeCommentCommand { v_Comment = sequenceComment }; var closeBrowserCommand = new SeleniumCloseBrowserCommand { v_InstanceName = _browserInstanceName }; var sequenceCommand = new SequenceCommand { ScriptActions = _sequenceCommandList, v_Comment = sequenceComment }; CallBackForm.AddCommandToListView(commentCommand); if (_browserEngineType != "None") { CallBackForm.AddCommandToListView(_createBrowserCommand); } CallBackForm.AddCommandToListView(sequenceCommand); if (_browserEngineType != "None") { CallBackForm.AddCommandToListView(closeBrowserCommand); } }
/// <summary> /// Sequence changed text. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SEQ_ChangedText(object sender, EventArgs e) { //Remove comment area. string s = sequenceEditor.Lines[sequenceEditor.CurrentLine].Text; if (s.Contains(";")) { s = s.Split(';')[0]; } //Remove spaces. s = s.Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", ""); var com = prevCom; try { com = SequenceData.CommandFromString(s, 0, new List <int>(), new Dictionary <string, int>(), new Dictionary <int, string>()); } catch { } if (com != prevCom) { if (prevCom != null) { if (com == null) { UpdateLineNumbers(0, sequenceEditor.Lines.Count); prevCom = com; } else { if (com.Identifier != prevCom.Identifier) { UpdateLineNumbers(0, sequenceEditor.Lines.Count); prevCom = com; } } } else { if (com != null) { UpdateLineNumbers(0, sequenceEditor.Lines.Count); prevCom = com; } } } }
private void FinalizeRecording() { string sequenceComment = $"Advanced UI Sequence Recorded {DateTime.Now}"; var commentCommand = new AddCodeCommentCommand { v_Comment = sequenceComment }; var sequenceCommand = new SequenceCommand { ScriptActions = _sequenceCommandList, v_Comment = sequenceComment }; CallBackForm.AddCommandToListView(commentCommand); CallBackForm.AddCommandToListView(sequenceCommand); }
public void OnEvent(IUnit unit, Vector3 position) { _commandsStorage.TerminateCommand(unit); Vector3[] path; if (!_pathfinder.CalculatePath(unit.Position, position, out path)) { return; } Vector3[] reversePath = new Vector3[path.Length]; Array.Copy(path, reversePath, path.Length); Array.Reverse(reversePath); var unitCmd = new SequenceCommand( new MoveByPath(unit, path, 5), new PunchUnit(unit, Vector3.one, 1.5f), new MoveByPath(unit, reversePath, 5) ); _commandsStorage.ExecuteCommand(unit, unitCmd); }
public void OnEvent(IUnit source, IUnit target) { if (target.HP <= 0) { return; } IUnit rocket = _unitsFactory.CreateUnit <IUnit>("rocket_0"); rocket.Position = new Vector3(source.Position.x, 1.0f, source.Position.z); Vector3 targetPosition = new Vector3(target.Position.x, 1.0f, target.Position.z); target.HP -= source.Attack; var moveRocketCmd = new SequenceCommand( new MoveByPath(rocket, new Vector3[] { rocket.Position, targetPosition }, 3f), new PunchUnit(rocket, Vector3.one, 1f), new UpdateUnitHP(target), new ActionCommand(() => { GameObject.Destroy(rocket.Owner); }) ); if (target.HP <= 0) { moveRocketCmd.Commands.Add(new PunchUnit(target, Vector3.one, 1f)); moveRocketCmd.Commands.Add(new ActionCommand(() => { _gameScene.Units.Remove(target); GameObject.Destroy(target.Owner); })); } _commandsManager.ExecuteCommand(moveRocketCmd); }
/// <summary> /// Create a sequence from text. /// </summary> /// <param name="text">The text.</param> public void FromText(List <string> text) { //Success by default. WritingCommandSuccess = true; //Reset labels. PublicLabels = new Dictionary <string, int>(); OtherLabels = new List <int>(); Dictionary <string, int> privateLabels = new Dictionary <string, int>(); List <int> labelLines = new List <int>(); //Format text. List <string> t = text.ToList(); int comNum = 0; for (int i = t.Count - 1; i >= 0; i--) { t[i] = t[i].Replace("\t", " ").Replace("\r", "").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " "); try { t[i] = t[i].Split(';')[0]; } catch { } if (t[i].Replace(" ", "").Length == 0) { t.RemoveAt(i); continue; } for (int j = 0; j < t[i].Length; j++) { if (t[i][j].Equals(' ')) { t[i] = t[i].Substring(j + 1); j--; } else { break; } } } //Fetch labels. for (int i = 0; i < t.Count; i++) { //If it's a label. if (t[i].EndsWith(":")) { labelLines.Add(i); if (t[i].StartsWith("_")) { privateLabels.Add(t[i].Replace(":", ""), comNum); OtherLabels.Add(comNum); } else { PublicLabels.Add(t[i].Replace(":", ""), comNum); } } else { comNum++; } } //Sort labels. PublicLabels = PublicLabels.OrderBy(obj => new NullTerminatedString(obj.Key)).ToDictionary(obj => obj.Key, obj => obj.Value); //Get commands. Commands = new List <SequenceCommand>(); for (int i = 0; i < t.Count; i++) { if (labelLines.Contains(i)) { continue; } SequenceCommand seq = new SequenceCommand(); try { seq.FromString(t[i], PublicLabels, privateLabels); } catch (Exception e) { WritingCommandSuccess = false; throw new Exception("Command " + i + ": \"" + t[i] + "\" is invalid.", e); } Commands.Add(seq); } //Set reference commands. for (int i = 0; i < Commands.Count; i++) { SequenceCommands trueType = Playback.Player.GetTrueCommandType(Commands[i]); switch (trueType) { case SequenceCommands.Call: case SequenceCommands.Jump: case SequenceCommands.OpenTrack: SetReferenceCommand(Commands[i]); break; } } //Fin. Commands.Add(new SequenceCommand() { CommandType = SequenceCommands.Fin }); WriteCommandData(); }
public MainViewModel() { Filters = new ObservableCollection <IFilter>(); SendSignalCommand = new DelegateCommand <string>(s => { if (string.IsNullOrEmpty(SignalValue)) { callMe.OnNext(new DeviceResult { CommandId = s }); } else { callMe.OnNext(new DeviceResult <string> { CommandId = s, Input = SignalValue }); } } ); _types = Assembly.GetExecutingAssembly().GetTypes(); _additionals[typeof(ConnectCommand)] = c => { CommandBase <bool> command = c as CommandBase <bool>; command.CompleteAction = com => { CommandBase <bool> cast = com as CommandBase <bool>; if (cast.ReturnValue) { FilterManager.RemoveFilter(_notConnectedFilter); } }; currentConnectCommand = command; }; _additionals[typeof(AlertsCommand)] = c => { CommandBase <String> com = c as CommandBase <string>; com.Subscribe( Observer.Create <ICommandResponse <string> >( x => AddMessage(x.Sender.ToString() + " Got result " + x.Value.ToString()), ex => AddMessage(ex.Source + " Got Error: " + ex.Message), () => { })); currentAlertCommand = c; }; _CanExecutes["AlertsCommand"] = new Func <string, bool>(s => CanConnect); CreateCommandCommand = new DelegateCommand <string>(CreateACommand, s => { if (_CanExecutes.ContainsKey(s)) { return(_CanExecutes[s](s)); } return(true); }); ThrowAlertCommand = new DelegateCommand <string>( s => callMe.OnNext(new DeviceResult <string> { Input = s, CommandId = currentAlertCommand.CommandId })); Commands = new ObservableCollection <IProcessedCommand>(); Messages = new ObservableCollection <Message>(); FilterManager = new FilterManager(); FilterManager.ItemsAdded.Subscribe(f => Filters.Add(f)); FilterManager.ItemsRemoved.Subscribe(f => Filters.Remove(f)); FilterManager.AddFilter(_notConnectedFilter); commandFactory = new CommandFactory(FilterManager); commandFactory.OnCreateCommand = new Action <CommandBase>(c => Commands.Add(c)); CommandProcessor = new CommandProcessor(callMe, FilterManager); CommandProcessor.RegisterForCompletedCommands( Observer.Create <CommandBase>(c => AddMessage(c.ToString() + " is Completed"))); SendConnectCommand = new DelegateCommand <bool?>(b => callMe.OnNext(new DeviceResult <bool> { Input = b.Value, CommandId = currentConnectCommand.CommandId })); callMe.OnNext(new ProcessorInput()); ReleaseBlockedCommand = new DelegateCommand <string>(s => CommandProcessor.RerunBlockedCommand((CommandBase) Commands.First(c => c.CommandId == s))); CancelCommandCommand = new DelegateCommand <string>(s => CommandProcessor.CancelCommand((CommandBase) Commands.First(c => c.CommandId == s))); CreateSequnceCommand = new DelegateCommand(() => { SequenceCommand c1 = new SequenceCommand(this, "AAA"); SequenceCommand c2 = new SequenceCommand(this, "BBB"); SequenceCommand c3 = new SequenceCommand(this, "CCC"); SequenceCommand c4 = new SequenceCommand(this, "DDD"); Commands.Add(c1); Commands.Add(c2); Commands.Add(c3); Commands.Add(c4); subscriptions.AddRange( CommandProcessor.PublishOrderedCommands( new[] { c1, c2, c3, c4 }, new[] { MyObserver, MyObserver, MyObserver, MyObserver })); }); }
public static void ExecuteExtendedCommand(SequenceCommand c, Track t, SequencePlayer p) { //Switch the extended command type. switch ((ExtendedCommandType)c.Identifier) { //Set var. case ExtendedCommandType.SetVar: SetVar((c as SetVarCommand).Value, (c as SetVarCommand).Variable, t, p); break; //Add var. case ExtendedCommandType.AddVar: SetVar((short)(GetVar((c as AddVarCommand).Variable, t, p) + (c as AddVarCommand).Value), (c as AddVarCommand).Variable, t, p); break; //Sub var. case ExtendedCommandType.SubtractVar: SetVar((short)(GetVar((c as SubtractVarCommand).Variable, t, p) - (c as SubtractVarCommand).Value), (c as SubtractVarCommand).Variable, t, p); break; //Multiply var. case ExtendedCommandType.MultiplyVar: SetVar((short)(GetVar((c as MultiplyVarCommand).Variable, t, p) * (c as MultiplyVarCommand).Value), (c as MultiplyVarCommand).Variable, t, p); break; //Divide var. case ExtendedCommandType.DivideVar: SetVar((short)(GetVar((c as DivideVarCommand).Variable, t, p) / (c as DivideVarCommand).Value), (c as DivideVarCommand).Variable, t, p); break; //Shift var. case ExtendedCommandType.ShiftVar: if ((c as ShiftVarCommand).Value > 0) { SetVar((short)(GetVar((c as ShiftVarCommand).Variable, t, p) << (c as ShiftVarCommand).Value), (c as ShiftVarCommand).Variable, t, p); } else { SetVar((short)(GetVar((c as ShiftVarCommand).Variable, t, p) >> Math.Abs((c as ShiftVarCommand).Value)), (c as ShiftVarCommand).Variable, t, p); } break; //Random var. case ExtendedCommandType.RandomVar: if ((c as RandomVarCommand).Value >= 0) { SetVar((short)random.Next(0, (c as RandomVarCommand).Value), (c as RandomVarCommand).Variable, t, p); } else { SetVar((short)random.Next((c as RandomVarCommand).Value, 0), (c as RandomVarCommand).Variable, t, p); } break; //And var. case ExtendedCommandType.AndVar: SetVar((short)(GetVar((c as AndVarCommand).Variable, t, p) & (c as AndVarCommand).Value), (c as AndVarCommand).Variable, t, p); break; //Or var. case ExtendedCommandType.OrVar: SetVar((short)(GetVar((c as OrVarCommand).Variable, t, p) | (c as OrVarCommand).Value), (c as OrVarCommand).Variable, t, p); break; //Xor var. case ExtendedCommandType.XorVar: SetVar((short)(GetVar((c as XorVarCommand).Variable, t, p) ^ (c as XorVarCommand).Value), (c as XorVarCommand).Variable, t, p); break; //Not var. case ExtendedCommandType.NotVar: SetVar((short)~(GetVar((c as NotVarCommand).Variable, t, p) & (c as NotVarCommand).Value), (c as NotVarCommand).Variable, t, p); break; //Mod var. case ExtendedCommandType.ModVar: SetVar((short)(GetVar((c as ModVarCommand).Variable, t, p) % (c as ModVarCommand).Value), (c as ModVarCommand).Variable, t, p); break; //Compare equal. case ExtendedCommandType.CompareEqual: t.ConditionFlag = GetVar((c as CompareEqualCommand).Variable, t, p) == (c as CompareEqualCommand).Value; break; //Compare greater than or equal to. case ExtendedCommandType.CompareGreaterThanOrEqualTo: t.ConditionFlag = GetVar((c as CompareGreaterThanOrEqualToCommand).Variable, t, p) >= (c as CompareGreaterThanOrEqualToCommand).Value; break; //Compare greater than. case ExtendedCommandType.CompareGreaterThan: t.ConditionFlag = GetVar((c as CompareGreaterThanCommand).Variable, t, p) > (c as CompareGreaterThanCommand).Value; break; //Compare less than or equal to. case ExtendedCommandType.CompareLessThanOrEqualTo: t.ConditionFlag = GetVar((c as CompareLessThanOrEqualToCommand).Variable, t, p) <= (c as CompareLessThanOrEqualToCommand).Value; break; //Compare less than. case ExtendedCommandType.CompareLessThan: t.ConditionFlag = GetVar((c as CompareLessThanCommand).Variable, t, p) < (c as CompareLessThanCommand).Value; break; //Compare not equal. case ExtendedCommandType.CompareNotEqual: t.ConditionFlag = GetVar((c as CompareNotEqualCommand).Variable, t, p) != (c as CompareNotEqualCommand).Value; break; //TODO: MOD STUFF!!! } }
private void lstScriptActions_DoubleClick(object sender, EventArgs e) { if (_selectedTabScriptActions.SelectedItems.Count != 1) { return; } //bring up edit mode to edit the action ListViewItem selectedCommandItem = _selectedTabScriptActions.SelectedItems[0]; //set selected command from the listview item tag object which was assigned to the command var currentCommand = (ScriptCommand)selectedCommandItem.Tag; //check if editing a sequence if (currentCommand is SequenceCommand) { if (_editMode) { MessageBox.Show("Embedding Sequence Commands within Sequence Commands not yet supported."); return; } //get sequence events SequenceCommand sequence = (SequenceCommand)currentCommand; frmScriptBuilder newBuilder = new frmScriptBuilder(); newBuilder.ScriptProject = ScriptProject; newBuilder.ScriptProjectPath = ScriptProjectPath; //add variables/elements newBuilder._scriptVariables = _scriptVariables; newBuilder._scriptElements = _scriptElements; TabPage newtabPage = new TabPage("Sequence"); newtabPage.Name = "Sequence"; newtabPage.ToolTipText = "Sequence"; newBuilder.uiScriptTabControl.TabPages.Add(newtabPage); newtabPage.Controls.Add(newBuilder._selectedTabScriptActions); newBuilder.uiScriptTabControl.SelectedTab = newtabPage; //append to new builder foreach (var cmd in sequence.ScriptActions) { newBuilder._selectedTabScriptActions.Items.Add(CreateScriptCommandListViewItem(cmd)); } //apply editor style format newBuilder.ApplyEditorFormat(sequence.v_Comment); newBuilder._parentBuilder = this; //if data has been changed if (newBuilder.ShowDialog() == DialogResult.OK) { CreateUndoSnapshot(); //create updated list List <ScriptCommand> updatedList = new List <ScriptCommand>(); //update to list for (int i = 0; i < newBuilder._selectedTabScriptActions.Items.Count; i++) { var command = (ScriptCommand)newBuilder._selectedTabScriptActions.Items[i].Tag; updatedList.Add(command); } //apply new list to existing sequence sequence.ScriptActions = updatedList; sequence.v_Comment = newBuilder.Text; //update label selectedCommandItem.Text = sequence.GetDisplayValue(); //update variables/elements _scriptVariables = newBuilder._scriptVariables; _scriptElements = newBuilder._scriptElements; } } else { //create new command editor form frmCommandEditor editCommand = new frmCommandEditor(_automationCommands, GetConfiguredCommands()); //creation mode edit locks form to current command editCommand.CreationModeInstance = CreationMode.Edit; //editCommand.defaultStartupCommand = currentCommand.SelectionName; editCommand.EditingCommand = currentCommand; //create clone of current command so databinding does not affect if changes are not saved editCommand.OriginalCommand = Common.Clone(currentCommand); //set variables editCommand.ScriptVariables = _scriptVariables; //set elements editCommand.ScriptElements = _scriptElements; editCommand.ProjectPath = ScriptProjectPath; if (currentCommand.CommandName == "SeleniumElementActionCommand") { editCommand.HTMLElementRecorderURL = HTMLElementRecorderURL; } //show edit command form and save changes on OK result if (editCommand.ShowDialog() == DialogResult.OK) { CreateUndoSnapshot(); selectedCommandItem.Tag = editCommand.SelectedCommand; selectedCommandItem.Text = editCommand.SelectedCommand.GetDisplayValue(); //+ "(" + cmdDetails.SelectedVariables() + ")"; selectedCommandItem.SubItems.Add(editCommand.SelectedCommand.GetDisplayValue()); } if (editCommand.SelectedCommand.CommandName == "SeleniumElementActionCommand") { CreateUndoSnapshot(); _scriptElements = editCommand.ScriptElements; HTMLElementRecorderURL = editCommand.HTMLElementRecorderURL; } } }
/// <summary> /// From text. /// </summary> /// <param name="text">The text to parse.</param> /// <param name="a">Sound archive.</param> public void FromText(List <string> text, SoundArchive a) { //Success by default. WritingCommandSuccess = true; //Get platform. var p = Platform(); //Reset labels. PublicLabels = new Dictionary <string, int>(); OtherLabels = new List <int>(); Dictionary <string, int> privateLabels = new Dictionary <string, int>(); List <int> labelLines = new List <int>(); //Format text. List <string> t = text.ToList(); int comNum = 0; for (int i = t.Count - 1; i >= 0; i--) { t[i] = t[i].Replace("\t", "").Replace("\r", ""); try { t[i] = t[i].Split(';')[0]; } catch { } if (t[i].Replace(" ", "").Length == 0) { t.RemoveAt(i); continue; } for (int j = 0; j < t[i].Length; j++) { if (t[i][j].Equals(' ')) { t[i] = t[i].Substring(j + 1); j--; } else { break; } } } //Sequence id to label name. Dictionary <int, string> seqId2Label = new Dictionary <int, string>(); //Get sequences. Sequences = new List <SequenceArchiveSequence>(); int currSeqId = 0; for (int i = t.IndexOf("@SEQ_TABLE") + 1; i < t.IndexOf("@SEQ_DATA"); i++) { //New sequence. SequenceArchiveSequence s = new SequenceArchiveSequence(); //Get sequence data. string[] seqData = t[i].Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Split(','); //Get sequence. string label = seqData[0].Split(':')[1]; string seqNameData = seqData[0].Split(':')[0]; if (seqNameData.Contains("=")) { currSeqId = int.Parse(seqNameData.Split('=')[1]); s.Name = seqNameData.Split('=')[0]; } else { s.Name = seqNameData; } s.Index = currSeqId; seqId2Label.Add(currSeqId++, label); s.LabelName = label; //Bank. string bnk = seqData[1]; if (ushort.TryParse(bnk, out _)) { s.ReadingBankId = ushort.Parse(bnk); if (a != null) { s.Bank = a.Banks.Where(x => x.Index == s.ReadingBankId).FirstOrDefault(); } } else if (a != null) { var bnkReal = a.Banks.Where(x => x.Name.Equals(bnk)).FirstOrDefault(); if (bnkReal == null) { throw new Exception("Bank " + bnk + " does not exist!"); } s.ReadingBankId = (ushort)bnkReal.Index; s.Bank = bnkReal; } else { throw new Exception("Can't use a name when there is no sound archive open!"); } //Data. s.Volume = byte.Parse(seqData[2]); s.ChannelPriority = byte.Parse(seqData[3]); s.PlayerPriority = byte.Parse(seqData[4]); //Player string ply = seqData[5]; if (ushort.TryParse(ply, out _)) { s.ReadingPlayerId = byte.Parse(ply); if (a != null) { s.Player = a.Players.Where(x => x.Index == s.ReadingPlayerId).FirstOrDefault(); } } else if (a != null) { var plyReal = a.Players.Where(x => x.Name.Equals(ply)).FirstOrDefault(); if (plyReal == null) { throw new Exception("Player " + ply + " does not exist!"); } s.ReadingPlayerId = (byte)plyReal.Index; s.Player = plyReal; } else { throw new Exception("Can't use a name when there is no sound archive open!"); } //Add sequence. Sequences.Add(s); } //Fetch labels. int strt = t.IndexOf("@SEQ_DATA") + 1; for (int i = strt; i < t.Count; i++) { //If it's a label. if (t[i].EndsWith(":")) { labelLines.Add(i); string lbl = t[i].Replace(":", ""); if (!seqId2Label.ContainsValue(lbl)) { privateLabels.Add(lbl, comNum); OtherLabels.Add(comNum); } else { PublicLabels.Add(lbl, comNum); } } else { comNum++; } } //Get commands. Commands = new List <SequenceCommand>(); for (int i = t.IndexOf("@SEQ_DATA") + 1; i < t.Count; i++) { if (labelLines.Contains(i)) { continue; } SequenceCommand seq = new SequenceCommand(); try { seq.FromString(t[i], PublicLabels, privateLabels); } catch { WritingCommandSuccess = false; throw new Exception("Command " + i + ": \"" + t[i] + "\" is invalid."); } Commands.Add(seq); } //Fin. Commands.Add(new SequenceCommand() { CommandType = SequenceCommands.Fin }); //Backup labels. var bakLabels = PublicLabels; PublicLabels = new Dictionary <string, int>(); foreach (var seq in Sequences) { PublicLabels.Add(seq.Name, bakLabels[seq.LabelName]); } }
/// <summary> /// Read command data into the commands list. /// </summary> /// <param name="globalMode">If to make private labels global.</param> public void ReadCommandData(bool globalMode = false) { //New reader. using (MemoryStream src = new MemoryStream(RawData)) { using (FileReader r = new FileReader(src)) { //Command index. int commandInd = 0; //Platform. var p = Platform(); //Offsets to command index. Dictionary <uint, int> offsetMap = new Dictionary <uint, int>(); //Commands. Commands = new List <SequenceCommand>(); //Labels. PublicLabels = new Dictionary <string, int>(); OtherLabels = new List <int>(); //Read until end. while (r.Position < RawData.Length) { //Add command index. offsetMap.Add((uint)r.Position, commandInd); //MIDI2SSEQ fix because it doesn't understand that jumps use UInt24, not UInt32. if (r.Position < RawData.Length - 1 && Commands.Count > 0 && Commands.Last().CommandType == SequenceCommands.Jump) { long bak = r.Position; if (r.ReadByte() == 0) { continue; } else { r.Position = bak; } } //Read the command. SequenceCommand c = new SequenceCommand(); c.Read(r, p); Commands.Add(c); commandInd++; } //Public labels. for (int i = 0; i < Labels.Count; i++) { PublicLabels.Add(Labels.Keys.ElementAt(i), offsetMap[Labels.Values.ElementAt(i)]); } //Get labels. for (int i = 0; i < Commands.Count; i++) { //Command index. int commandIndex = 0; //Switch the type. SequenceCommands trueType = Playback.Player.GetTrueCommandType(Commands[i]); switch (trueType) { //It has an offset. case SequenceCommands.Call: case SequenceCommands.Jump: case SequenceCommands.OpenTrack: commandIndex = SetOffsetIndex(Commands[i], offsetMap); break; } //Label. string label = ""; //Possible type. if (trueType == SequenceCommands.Call || trueType == SequenceCommands.Jump || trueType == SequenceCommands.OpenTrack) { //Get label. uint offset = offsetMap.FirstOrDefault(x => x.Value == commandIndex).Key; if (Labels.ContainsValue(offset)) { label = Labels.FirstOrDefault(x => x.Value == offset).Key; } else { label = (globalMode ? "C" : "_c") + "ommand_" + commandIndex; OtherLabels.Add(commandIndex); } } //Set label. switch (trueType) { //Set the label. case SequenceCommands.Call: case SequenceCommands.Jump: case SequenceCommands.OpenTrack: SetCommandLabel(Commands[i], label); break; } } //Set reference commands. for (int i = 0; i < Commands.Count; i++) { SequenceCommands trueType = Playback.Player.GetTrueCommandType(Commands[i]); switch (trueType) { case SequenceCommands.Call: case SequenceCommands.Jump: case SequenceCommands.OpenTrack: SetReferenceCommand(Commands[i]); break; } } } } }
private void FinalizeRecording() { string sequenceComment = $"UI Sequence Recorded {DateTime.Now}"; _scriptCommandList = GlobalHook.GeneratedCommands; var outputList = new List <ScriptCommand>(); if (chkGroupIntoSequence.Checked) { var newSequence = new SequenceCommand(); foreach (ScriptCommand cmd in _scriptCommandList) { newSequence.ScriptActions.Add(cmd); } if (newSequence.ScriptActions.Count > 0) { outputList.Add(newSequence); } } else if (chkGroupMovesIntoSequences.Checked) { var newSequence = new SequenceCommand(); newSequence.v_Comment = sequenceComment; foreach (ScriptCommand cmd in _scriptCommandList) { if (cmd is SendMouseMoveCommand) { var sendMouseCmd = (SendMouseMoveCommand)cmd; if (sendMouseCmd.v_MouseClick != "None") { outputList.Add(newSequence); newSequence = new SequenceCommand(); newSequence.v_Comment = sequenceComment; outputList.Add(cmd); } else { newSequence.ScriptActions.Add(cmd); } } else if (cmd is SendKeystrokesCommand) { outputList.Add(newSequence); newSequence = new SequenceCommand(); newSequence.v_Comment = sequenceComment; outputList.Add(cmd); } else { newSequence.ScriptActions.Add(cmd); } } if (newSequence.ScriptActions.Count > 0) { outputList.Add(newSequence); } } else { outputList = _scriptCommandList; } var commentCommand = new AddCodeCommentCommand { v_Comment = sequenceComment }; outputList.Insert(0, commentCommand); foreach (var cmd in outputList) { CallBackForm.AddCommandToListView(cmd); } Close(); }
public static void ExecuteCommand(SequenceCommand c, Track t, SequencePlayer p) { //Note command. if (c.Identifier >= 0 && c.Identifier <= 127) { //Play note. } //Switch the command type. switch ((CommandType)c.Identifier) { //Wait the provided amount of ticks. case CommandType.Wait: Thread.Sleep(TickTime.Ticks2Milliseconds((c as WaitCommand).Length)); break; //Program change. case CommandType.ProgramChange: t.InstrumentNumber = (int)(c as ProgramChangeCommand).Program; break; //Open track. case CommandType.OpenTrack: OpenTrackCommand openTrackCommand = (c as OpenTrackCommand); p.TracksOpen[openTrackCommand.TrackNumber] = true; p.Tracks[openTrackCommand.TrackNumber] = new Track(p.Tracks[0]); p.Tracks[openTrackCommand.TrackNumber].Offset = (int)openTrackCommand.Offset.Value; break; //Jump. case CommandType.Jump: t.Offset = (int)(c as JumpCommand).Offset.Value; break; //Call. case CommandType.Call: t.ReturnToOffsets.Push(t.Offset + 1); t.Offset = (int)(c as CallCommand).Offset.Value; break; //Time base. case CommandType.TimeBase: t.TimeBase = (c as TimeBaseCommand).QuarterNoteLength; break; //Hold. case CommandType.Hold: t.Hold = (c as HoldCommand).Hold; break; //Monophonic. case CommandType.Monophonic: t.Monophonic = (c as MonophonicCommand).Monophonic; break; //Velocity range. case CommandType.VelocityRange: t.VelocityRange = (c as VelocityRangeCommand).VelocityRange; break; //Biquad type. case CommandType.BiquadType: t.BiquadType = (c as BiquadTypeCommand).BiquadType; break; //Biquad value. case CommandType.BiquadValue: t.BiquadValue = (c as BiquadValueCommand).BiquadValue; break; //Bank select. case CommandType.BankSelect: t.BankNumber = (c as BankSelectCommand).BankNumber; break; //TODO! //Sweep pitch. //Mod period. //Extended command. case CommandType.Extended: ExecuteExtendedCommand((c as ExtendedCommand).SequenceCommand, t, p); break; //Envelope reset. TODO! //Loop end. TODO! //Return from a call. case CommandType.Return: t.Offset = t.ReturnToOffsets.Pop(); break; //Allocate track does nothing. //Fin. Close the track. case CommandType.Fin: int trackIndexToClose = Array.IndexOf(p.Tracks, t); p.TracksOpen[trackIndexToClose] = false; break; //Prefix commands are to do later. } //Increment the command number, if not moving. if ((c as OpenTrackCommand != null) || (c as JumpCommand != null) || (c as CallCommand != null)) { t.Offset++; } }