/// <summary> /// マウスダウン処理の最終決定 /// </summary> protected virtual void finalMouseDownPart4Size() { var e = _clickPos; if (_selectedParts.Count > 0) { var tarPane = ClickPane; var parts = ClickParts; // Parts.GetPartsAt(e.Pos, true, out tarPane); if (parts != null) { var isP = false; switch (parts.IsOn(e.Pos, tarPane)) { case PartsBase.PointType.OnLeft: _pos.SetDevelop(_developmentMode = PartsPositionManager.DevelopType.SizeLeft); isP = true; break; case PartsBase.PointType.OnRight: _pos.SetDevelop(_developmentMode = PartsPositionManager.DevelopType.SizeRight); isP = true; break; case PartsBase.PointType.OnTop: _pos.SetDevelop(_developmentMode = PartsPositionManager.DevelopType.SizeTop); isP = true; break; case PartsBase.PointType.OnBottom: _pos.SetDevelop(_developmentMode = PartsPositionManager.DevelopType.SizeBottom); isP = true; break; } if (isP) { _mouseDownOriginal = e.Pos; _pos.Initialize(_selectedParts); Token.Add(TokenGeneral.TokenMouseDownNormalize, this); } } } }
public override void OnInitInstance() { base.OnInitInstance(); Hot.Setting = LoadSetting(); Token.Add(TokenSettingsLoaded, this); }
private void Jump(int offsetSx = 0) { Box.BackColor = BgColor; var line = Box.Text; try { var cpos = Hot.TimelineParts.GetCdPos(TarPane, TarPane.GetPaneRect().LT); var tartime = Hot.FirstSpeech + TimeSpan.FromSeconds(cpos.X); var tardate = new DateTime(tartime.Year, tartime.Month, tartime.Day); var cs = line.Split(':').Select(a => a.Trim()).Where(a => !string.IsNullOrEmpty(a)).ToArray(); // Set new time text DateTime settime; switch (cs.Length) { case 1: settime = GetTime(cs[0], tartime); break; case 2: settime = GetTime(cs[0], cs[1], tartime); break; case 3: settime = GetTime(cs[0], cs[1], cs[2], tartime); break; default: settime = default; break; } // Scroll if (settime != default) { Box.Text = lastTimeText = settime.ToString(TimeUtil.FormatHMS); Box.SelectAll(); var spos = Hot.TimelineParts.GetScRect(TarPane, CodeRect.FromLTWH((int)(settime - Hot.FirstSpeech).TotalSeconds, 0, 0, 0)); Pane.Scroll = ScreenPos.FromInt(Pane.Scroll.X - spos.LT.X + offsetSx, Pane.Scroll.Y); Token.Add(FeatureAutoScroll.TokenAutoScrollOFF, this); Pane.Invalidate(null); GetRoot().FlushFeatureTriggers(); } } catch { Box.BackColor = Color.DarkRed; } }
public TokenImpl(ReteNode node, Token <T> parent, Element <T> element) { _node = node; _parent = parent; _element = element; _children = Enumerable.Empty <Token <T> >(); parent.Add(this); if (element != null) { element.AddToken(this); } }
private void Btn_Click(object sender, EventArgs e) { Hot.IsPlaying = !Hot.IsPlaying; Btn.Checked = Hot.IsPlaying; if (Hot.IsPlaying) { LOG.WriteLine(LLV.INF, $"START at {DateTime.Now.ToString(TimeUtil.FormatYMDHMSms)}"); Token.Add(TokenStart, this); } else { LOG.WriteLine(LLV.INF, $"Requested to STOP at {DateTime.Now.ToString(TimeUtil.FormatYMDHMSms)}"); GetRoot().SetUrgentToken(TokenStop, TokenStop, null); } }
public override void Start(NamedId who) { base.Start(who); var fd = new FontDialog(); // 初期化 foreach (PartsCollectionBase.PartsEntry pe in _selectedParts) { if (pe.Parts is PartsTextBase fp) { fd.Font = fp.LastFont; fd.Color = fp.FontColor; break; } } fd.MinSize = 4; fd.MaxSize = 300; fd.ShowEffects = false; fd.ShowHelp = false; fd.ShowColor = true; fd.FontMustExist = true; fd.AllowVerticalFonts = false; // 選択 if (fd.ShowDialog() == DialogResult.OK) { foreach (PartsCollectionBase.PartsEntry pe in _selectedParts) { if (pe.Parts is PartsTextBase fp) { fp.FontName = fd.Font.Name; fp.FontSize = fd.Font.SizeInPoints; fp.FontColor = fd.Color; fp.IsItalic = fd.Font.Italic; fp.IsBold = fd.Font.Bold; fp.LastFont = fd.Font; Parts.Invalidate(fp, pe.Pane); Link.Equalization(fp); Data.SetModified(); Token.Add(NamedId.FromName("TokenFontChanged"), this); } } } }
/// <summary> /// マウスダウン処理の最終決定 /// </summary> protected virtual void _finalMouseDownPart() { var e = _clickPos; if (_selectedParts.Count > 0) { var tarPane = ClickPane; var parts = ClickParts; // Parts.GetPartsAt(e.Pos, true, out tarPane); if (parts != null) { if (parts.IsOn(e.Pos, tarPane) == PartsBase.PointType.Inside) { _pos.SetDevelop(_developmentMode = PartsPositionManager.DevelopType.Move); _mouseDownOriginal = e.Pos; _pos.Initialize(_selectedParts); Token.Add(TokenGeneral.TokenMouseDownNormalize, this); } } } }
public override void Start(NamedId who) { base.Start(who); Enabled = false; // Considering Re-entering by FlushToken in timer trigger. var fo = new FormPreferences { Setting = Hot.Setting, IsPlaying = Hot.IsPlaying, }; if (fo.ShowDialog(Pane.Control) == DialogResult.OK) { Hot.Setting = fo.Setting; SaveSetting(Hot.Setting); Token.Add(TokenSettingsLoaded, this); } Enabled = true; }
private void OnCancel(object sender, SpeechRecognitionEventArgs e) { if (_talkID == null) { return; } LOG.NoJumpNext(); LOG.WriteLine(LLV.DEV, $"{DateTime.Now.ToString(TimeUtil.FormatYMDHMSms)} {GetType().Name}({GetTargetRecognizeLanguage()}).OnCancel : {e.Result.Text}"); Hot.SpeechEventQueue.Enqueue(new SpeechEvent { RowID = ID.Value, Action = SpeechEvent.Actions.Canceled, TimeGenerated = DateTime.Now, SessionID = _talkID, Text = e.Result.Text, }); _talkID = null; Token.Add(TokenSpeechEventQueued, this); GetRoot().FlushFeatureTriggers(); }
/// <summary> /// コントロールイベント取得 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void target_Raise(object sender, EventArgs e) { var pi = sender.GetType().GetProperty("Tag"); var tag = (string)pi.GetValue(sender, null); string token; var id = tag.ToUpper().IndexOf("TOKEN:"); if (id >= 0) { token = tag.Substring(id + 6); if (token.IndexOf(';') >= 0) { token = token.Substring(0, token.IndexOf(';')); } } else { token = tag; } Token.Add(NamedId.FromName(token), this); GetRoot().FlushFeatureTriggers(); }
private void OnRecognizing(object sender, SpeechRecognitionEventArgs e) { LOG.NoJumpNext(); LOG.WriteLine(LLV.DEV, $"{DateTime.Now.ToString(TimeUtil.FormatYMDHMSms)} {GetType().Name}({GetTargetRecognizeLanguage()}).OnRecognizing : {e.Result.Text}"); if (_talkID == null) { _talkID = Guid.NewGuid().ToString(); Hot.SpeechEventQueue.Enqueue(new SpeechEvent { RowID = ID.Value, Action = SpeechEvent.Actions.Start, TimeGenerated = DateTime.Now, SessionID = _talkID, }); Hot.SpeechEventQueue.Enqueue(new SpeechEvent { RowID = ID.Value, Action = SpeechEvent.Actions.SetColor, TimeGenerated = DateTime.Now, SessionID = _talkID, Text = GetBarColor().ToArgb().ToString(), }); } Hot.SpeechEventQueue.Enqueue(new SpeechEvent { RowID = ID.Value, Action = SpeechEvent.Actions.Recognizing, TimeGenerated = DateTime.Now, SessionID = _talkID, Text = e.Result.Text, }); Token.Add(TokenSpeechEventQueued, this); GetRoot().FlushFeatureTriggers(); }
/// <summary> /// パラメータを取得し、フィーチャーやトークン発行などを行う /// </summary> private void resetSwitch() { var ss = GetParamString().Split(new char[] { ',' }); var fis = GetRoot().GetChildFeatureInstance(); var tokenLidName = string.Empty; foreach (var s in ss) { var s2 = s.Trim(); if (s2.StartsWith("[")) // チェックボックス関連は関係ない { continue; } // トークン、シェアを設定する var com = s2.Split(new char[] { '=' }); if (com.Length == 2) { if (com[0].Trim().Equals("Command", StringComparison.CurrentCultureIgnoreCase)) { switch (com[1].Trim().ToUpper()) { case "REDRAW": Pane.Invalidate(null); break; case "KEEPOFF": ThreadSafe.SetChecked(_checkBox, false); _isOn = false; break; } } if (com[0].Trim().Equals("Token", StringComparison.CurrentCultureIgnoreCase)) { tokenLidName = com[1].Trim(); } if (com[0].Trim().Equals("ShareBool", StringComparison.CurrentCultureIgnoreCase)) { var b = (DataSharingManager.Boolean)Share.Get(com[1].Trim(), typeof(DataSharingManager.Boolean)); b.value = _isOn; } } else { // フィーチャーのEnabledを設定する foreach (FeatureBase fi in fis) { if (s2.StartsWith("@")) { if (fi.Name == s2.Substring(1)) { fi.Enabled = _isOn; } } else { if (fi.GetType().Name == s2) { fi.Enabled = _isOn; } } } } } // トークンを投げる(フィーチャーのEnableを設定した後) if (_isNoToken == false) { if (string.IsNullOrEmpty(tokenLidName) == false) { Token.Add(NamedId.FromName(tokenLidName), this); } } else { _isNoToken = false; } }
/// <summary> /// フィーチャー初期化 /// </summary> public override void OnInitInstance() { base.OnInitInstance(); Token.Add(MultiTokenTriggerID[0], null); LOG.LogClearRequested += new EventHandler <EventArgs>(LOG_LogClearRequested); }
private async Task <bool> MakeAudioConfigAsync(SpeechHandler handler) { Debug.Assert(handler.Device != null); // NAudio Setting var wavein = CreateCaptureInstance(handler.Device); var waveoutFormat = new WaveFormat(16000, 16, 1); wavein.StartRecording(); // Azure Cognitive Service Setting var audioformat = AudioStreamFormat.GetWaveFormatPCM((uint)waveoutFormat.SampleRate, (byte)waveoutFormat.BitsPerSample, (byte)waveoutFormat.Channels); handler.AudioInputStream = AudioInputStream.CreatePushStream(audioformat); handler.AudioConfig = AudioConfig.FromStreamInput(handler.AudioInputStream); // Silence Generate DateTime preEvent = DateTime.Now; var silenceData = new byte[waveoutFormat.BlockAlign]; // Appliation Preparation Hot.SetWavFormat(DisplayName, waveoutFormat); // for file saving // NAudio Voice event wavein.DataAvailable += (s, e) => { if (e.BytesRecorded > 0) { var now = DateTime.Now; using (var ms = new MemoryStream()) { var memoryWriter = new WaveFileWriter(ms, waveoutFormat); ms.SetLength(0); // Delete file header. var samples = Resample(wavein.WaveFormat, e.Buffer, e.BytesRecorded, waveoutFormat); foreach (var sample in samples) { memoryWriter.WriteSample(sample); } Hot.AddWavToAllQueue(DisplayName, ms.GetBuffer(), (int)ms.Length, now); // for file saving handler.AudioInputStream.Write(ms.GetBuffer(), (int)ms.Length); // for Azure Cognitive Speech to Text } try { Token.Add(TokenWavDataQueued, this); // TODO: Need Confirm it must be fixed with Tono.Gui.WinForm 1.1.2 - System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' // It must be not fixed yet. so I added try-catch. } catch { // No Action because the above token is a QoS 0 message. But it's necessary to disappear exception messages that's why catch them here. } preEvent = DateTime.Now; } else { if (_talkID != null) { var spms = (double)waveoutFormat.SampleRate / 1000; // samples per ms var n = (int)(spms * (DateTime.Now - preEvent).TotalMilliseconds); for (var i = n; i >= 0; i--) { handler.AudioInputStream.Write(silenceData, silenceData.Length); // send silence to azure to get realtime event (othewise, azure will wait untile next event timing even if there is no event long time) } } preEvent = DateTime.Now; } }; handler.StopRequested += (s, e) => { wavein.StopRecording(); // Stop NAudio recording }; return(await Task.FromResult(true)); }
public override void ParseParameter(string param) { base.ParseParameter(param); var rnd = new Random(DateTime.Now.Ticks.GetHashCode()); var lines = param.Split(',').Select(a => a.Trim()).Where(a => !string.IsNullOrWhiteSpace(a)).ToList(); var ms = 1200; var sessionid = 1; var col = Color.DarkRed; var queue = new Queue <(int ms, SpeechEvent ev)>(); Id fid = default; if (lines.FirstOrDefault() is string c1) { if (c1.ToLower().StartsWith("id=")) { try { var val = int.Parse(StrUtil.Mid(c1, 3)); fid = Id.From(val); } catch { } lines.RemoveAt(0); } } if (fid == default) { if (GetRoot().FindChildFeatures(typeof(FeatureAudioLoopback2)).FirstOrDefault() is FeatureAudioLoopback2 f) { fid = f.ID; } else { fid = ID; } } Hot.AddRowID(fid.Value, fid.Value * 10, 42); // Device Dummy Hot.AddRowID(0x8000 | fid.Value, fid.Value * 10 + 1, 4); // Blank Space foreach (var line in lines) { if (line.StartsWith("+")) { try { var val = int.Parse(StrUtil.Mid(line, 1)); ms += val; } catch { } continue; } if (line.StartsWith("#")) { try { var argb = Convert.ToInt32(StrUtil.Mid(line, 1), 16); col = Color.FromArgb(argb); if (col.A == 0) { col = Color.FromArgb(255, col.R, col.G, col.B); } } catch { } continue; } queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Start, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", })); queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.SetColor, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = col.ToArgb().ToString(), })); ms += (int)(rnd.NextDouble() * 1000 + 200); var len = 1; var buildstr = ""; for (var i = 0; i < line.Length; i += len) { len = (int)(rnd.NextDouble() * 5 + 1); buildstr += StrUtil.Mid(line, i, len) ?? ""; if (!string.IsNullOrWhiteSpace(buildstr)) { queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Recognizing, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = buildstr, })); ms += (int)(rnd.NextDouble() * 300 + 100); } } ms += 500; queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Recognized, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = buildstr, })); sessionid++; ms += 1000; } while (queue.Count > 0) { var item = queue.Dequeue(); Timer.AddTrigger(item.ms, () => { item.ev.TimeGenerated = DateTime.Now; Hot.SpeechEventQueue.Enqueue(item.ev); Token.Add(TokenSpeechEventQueued, this); if (Pane.Control.InvokeRequired) { Pane.Control.Invoke(new InvokeMethod(() => { GetRoot().FlushFeatureTriggers(); })); } else { GetRoot().FlushFeatureTriggers(); } }); } }