// return group of actions or null if no match public ActionGroup execute(ClapsSample sample, bool immediate) { ActionGroup groupToExecute = null; int closestTempoDelta = 0; int tempo = (int)PClapper.Properties.Settings.Default.tempo; foreach (ActionGroup g in PClapper.Properties.Actions.Default.actionsSettings.actionGroups) { if ((immediate == g.immediate) && g.pattern.match(sample)) { int tempoDelta = Math.Abs( tempo - g.pattern.tempo(sample) ); if (groupToExecute == null || tempoDelta < closestTempoDelta ) { groupToExecute = g; closestTempoDelta = tempoDelta; } } } if (groupToExecute == null) return null; // Execute group foreach (ActionSetting a in groupToExecute.actions) { if (a.action.IndexOf("Launch") == 0) new OpenFileProgAction("\"" + a.action.Replace("Launch ", "") + "\"", "").Execute(); else if (a.action.IndexOf("Open") == 0) { new OpenFileProgAction(a.action.Replace("Open ", ""), a.parameters).Execute(); } else if (pm.ClapperPlugins[a.action] != null) { ((ClapperPluginInterface.IClapperPlugin)pm.ClapperPlugins[a.action]).Execute(); } else { MessageBox.Show("Error: Cannot find action '" + a.action + "'"); } } return groupToExecute; }
public bool match(ClapsSample sample) { // Count check if (sample.claps.Count != claps.Count) return false; if (sample.claps.Count == 1) return true; // Rythm check if (!PClapper.Properties.Settings.Default.checkRythm) return true; long sampleLength = sample.claps[sample.claps.Count - 1] - sample.claps[0]; int patternLength = claps[claps.Count - 1] - claps[0]; long beatLength = patternLength == 0 ? 0 : sampleLength / patternLength; long margin = (beatLength * (int)PClapper.Properties.Settings.Default.rythmTolerance) / 100; for (int i = 0; i < claps.Count; i++) { long theoreticalClap = sample.claps[0] + (claps[i] - claps[0]) * beatLength; if (Math.Abs(sample.claps[i] - theoreticalClap) > margin) { Debug.WriteLine("Wrong rythm"); return false; } } // Tempo Check if (!PClapper.Properties.Settings.Default.checkTempo) return true; long theoreticalBeatLength = 30 * Properties.Settings.Default.samplingRate / (long)PClapper.Properties.Settings.Default.tempo; margin = (beatLength * (int)PClapper.Properties.Settings.Default.tempoTolerance) / 100; if (Math.Abs(beatLength - theoreticalBeatLength) > margin) { Debug.WriteLine("Wrong tempo"); return false; } return true; }
public void clapActionPerformed(long sampleCount) { sysTray.Icon = PClapper.Properties.Resources.trayIconBlink; iconTimer.Start(); clapsSample.claps.Add(sampleCount); someTimer.Stop(); ActionGroup ag = cam.execute(clapsSample, true); if (maxPause == 0 || (ag != null && !ag.subPattern)) { clapsSample = new ClapsSample(); } else { someTimer.Interval = maxPause; someTimer.Start(); } }
public int tempo(ClapsSample sample) { long sampleLength = sample.claps[sample.claps.Count - 1] - sample.claps[0]; int patternLength = claps[claps.Count - 1] - claps[0]; if (sampleLength == 0) return 0; return (int)(Properties.Settings.Default.samplingRate * 30 * patternLength / sampleLength); }
private void someTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { someTimer.Stop(); cam.execute(clapsSample,false); clapsSample = new ClapsSample(); }