public void Play(PlaybackInfo info) { if (playingThread != null) playingThread.Abort(); playingThread = new System.Threading.Thread(() => player.Play(info)); playingThread.Start(); }
public void Play(PlaybackInfo info) { if (info.Messages.Count == 0) return; currentInfo = info; state = 0; var keys = new int[info.Messages.Keys.Count]; int i = 0; foreach(var k in info.Messages.Keys) { keys[i++] = k; } MaxKeyTime = keys[info.Messages.Keys.Count - 1]; for(i = 0; i < keys.Length - 1; i++) { currentIndex = i; if (state != 0) break; foreach(PlaybackMessage message in info.Messages[keys[i]]) { if (OnMessageSent != null) OnMessageSent(this, keys[i], message); midiOut.Send(message.GenerateMidiMessage().RawData); } int sleep_dur = keys[i + 1] - keys[i]; Thread.Sleep(sleep_dur); } }
void generateSongPlotFull(PlotModel model, PlaybackInfo info) { var songpoints = (model.Series[0] as ScatterSeries).ItemsSource as List<ScatterPoint>; songpoints.Clear(); model.InvalidatePlot(true); var keys = new int[info.Messages.Keys.Count]; int i = 0; foreach (var k in info.Messages.Keys) { keys[i++] = k; } for (i = 0; i < keys.Length - 1; i++) { foreach (PlaybackMessage message in info.Messages[keys[i]]) { if (message.Message == PlaybackMessage.PlaybackMessageType.Start) { double duration = Math.Log(message.Duration + 1, 2) * 2; songpoints.Add(new ScatterPoint(keys[i], message.Pitch % 12, duration, message.Pitch / 12)); } } } if (model.Axes.Count > 2) { model.Axes[2].IsAxisVisible = false; model.Axes[2].Maximum = 14; model.Axes[2].Minimum = -2; } model.InvalidatePlot(true); }
public static PlaybackInfo operator +(PlaybackInfo info1, PlaybackInfo info2) { PlaybackInfo info = new PlaybackInfo(); foreach (int k in info1.Messages.Keys) info.Add(k, info1.Messages[k]); foreach (int k in info2.Messages.Keys) info.Add(k, info2.Messages[k]); return info; }
public PlaybackInfo GeneratePlaybackInfo(int time = 0) { PlaybackInfo info = new PlaybackInfo(); info.Add(time, new PlaybackMessage(Instrument, Channel)); foreach (var s in sequences) { info += s.GeneratePlaybackInfo(Channel, time); time += (int)(1000 * Note.ToRealDuration(s.Duration)); } return info; }
public PlaybackInfo GeneratePlaybackInfo() { PlaybackInfo info = new PlaybackInfo(); foreach (Track t in Tracks) info += t.GeneratePlaybackInfo(0); return info; }
public PlaybackInfo GeneratePlaybackInfo(byte channel, int time = 0) { PlaybackInfo info = new PlaybackInfo(); foreach (Note n in sequence) { if (n.Pitch < 0 || n.Velocity == 0) { time += (int)(1000 * Note.ToRealDuration(n.Duration)); continue; } var tag = Tuple.Create(channel,n); PlaybackMessage m = new PlaybackMessage(PlaybackMessage.PlaybackMessageType.Start, channel, (byte)n.Velocity, (byte)n.Pitch, n.Duration); m.Tag = tag; // Experimenta info.Add(time, m); time += (int)(1000 * Note.ToRealDuration(n.Duration)); m = new PlaybackMessage(PlaybackMessage.PlaybackMessageType.Stop, channel, (byte)n.Velocity, (byte)n.Pitch); //m.Tag = tag; // Experimental info.Add(time, m); time += 1; } return info; }