void MakeBlob() { var ms = new MStream(); var writer = new DataWriter(ms); Key.Write(writer); writer.Write(_members.Count); foreach (var map in _members.Values.OrderBy(i => i.Id)) { map.Write(writer); } _blob = ms.ToArray(); }
public MStream GetATextStream() { MStream stream = new MStream(); stream.Column = RNG.Next(horizontal_blocks); stream.Start = RNG.Next(vertical_blocks - 5); stream.Current = stream.Start; stream.CurrentBlockIndex = stream.Current * horizontal_blocks + stream.Column; stream.Max = vertical_blocks - 1; int ti = RNG.Next(StreamTexts.Count + 1); if (ti == StreamTexts.Count) { stream.Text = GetARandomString() + GetRandomLengthWhitespaces(); } else { stream.Text = StreamTexts[ti] + GetRandomLengthWhitespaces(); } return(stream); }
private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath) { try { Status = "prep"; Int32 MT = Properties.Settings.Default.MultiThreadedMode ? Properties.Settings.Default.MultiThreadedLimitV : 1; WaveFormat WF = new WaveFormat(Properties.Settings.Default.Frequency, 32, 2, AudioEncoding.IeeeFloat); // Initialize BASS Debug.PrintToConsole("ok", "Initializing BASS..."); if (!Bass.BASS_Init(0, WF.SampleRate, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)) { throw new Exception("Unable to initialize BASS!"); } LoadSoundFonts(); foreach (MIDI MFile in Program.MIDIList) { MultiStreamMerger MSM = new MultiStreamMerger(WF); if (StopRequested) { Debug.PrintToConsole("ok", "Stop requested. Stopping foreach loop..."); break; } MDV.SetTotalTracks(MFile.Tracks); MDV.ResetCurrentTrack(); // Begin conversion Status = "mconv"; try { CTS = new CancellationTokenSource(); Debug.PrintToConsole("ok", String.Format("Preparing loop... MaxDegreeOfParallelism = {0}", MT)); ParallelFor(0, MFile.Tracks, MT, CTS.Token, T => { if (StopRequested) { Debug.PrintToConsole("ok", "Stop requested. Stopping Parallel.For..."); //LS.Stop(); return; } if (MFile.NoteCount > 0) { TrackThreadStatus Trck = new TrackThreadStatus(T); Trck.Dock = DockStyle.Top; ThreadsPanel.Invoke((MethodInvoker) delegate { Debug.PrintToConsole("ok", "Added TrackThreadStatus control for MIDI."); ThreadsPanel.Controls.Add(Trck); }); ConvertWorker Worker = new ConvertWorker(MFile.GetSingleTrackTimeBased(T), MFile.TimeLength.TotalSeconds); ISampleWriter Writer; WaveWriter SDestination = null; FileStream SFOpen = null; if (Properties.Settings.Default.PerTrackSeparateFiles) { // Check if we need to export each track to a file String Folder = OPath; if (Properties.Settings.Default.PerTrackSeparateFiles) { // We do, create folder Folder += String.Format("\\{0}\\", Path.GetFileNameWithoutExtension(MFile.Name)); if (!Directory.Exists(Folder)) { Directory.CreateDirectory(Folder); } } else { Folder += " "; } // Prepare the filename String SOutputDir = String.Format("{0}Track {1}.{2}", Folder, T, Properties.Settings.Default.Codec); // Check if file already exists if (File.Exists(SOutputDir)) { SOutputDir = String.Format("{0}Track {1} - {2}.{3}", Folder, T, DateTime.Now.ToString("dd-MM-yyyy HHmmsstt"), Properties.Settings.Default.Codec); } Debug.PrintToConsole("ok", String.Format("{0} - Output file: {1}", T, SOutputDir)); SFOpen = File.Open(SOutputDir, FileMode.Create); SDestination = new WaveWriter(SFOpen, WF); Writer = new WaveSampleWriter(SDestination); } else { Writer = MSM.GetWriter(); } Task ConvThread = Task.Run(() => { Worker.Convert(Writer, WF, false, CTS.Token); }); while (!ConvThread.IsCompleted) { if (StopRequested) { break; } Trck.Invoke((MethodInvoker) delegate { Trck.UpdatePB(Convert.ToInt32(Math.Round(Worker.Progress * 100))); }); Thread.Sleep(10); } ConvThread.Wait(); if (SDestination != null) { SDestination.Dispose(); } if (SFOpen != null) { SFOpen.Dispose(); } ThreadsPanel.Invoke((MethodInvoker) delegate { Debug.PrintToConsole("ok", String.Format("{0} - Removed TrackThreadStatus control for MIDI.", T)); ThreadsPanel.Controls.Remove(Trck); }); if (!StopRequested) { MDV.AddTrack(); } } }); } catch (OperationCanceledException) { } finally { CTS.Dispose(); CTS = null; } if (StopRequested) { break; } else { MDV.AddValidMIDI(); } // Time to save the file String OutputDir = String.Format("{0}\\{1}.{2}", OPath, Path.GetFileNameWithoutExtension(MFile.Name), Properties.Settings.Default.Codec); // Check if file already exists if (File.Exists(OutputDir)) { OutputDir = String.Format("{0}\\{1} - {2}.{3}", OPath, Path.GetFileNameWithoutExtension(MFile.Name), DateTime.Now.ToString("dd-MM-yyyy HHmmsstt"), Properties.Settings.Default.Codec); } Debug.PrintToConsole("ok", String.Format("Output file: {0}", OutputDir)); // Reset MSM position MSM.Position = 0; // Prepare wave source IWaveSource MStream; if (Properties.Settings.Default.LoudMax) { Debug.PrintToConsole("ok", "LoudMax enabled."); AntiClipping BAC = new AntiClipping(MSM, 0.1); MStream = BAC.ToWaveSource(32); } else { MStream = MSM.ToWaveSource(32); } FileStream FOpen = File.Open(OutputDir, FileMode.Create); WaveWriter Destination = new WaveWriter(FOpen, WF); Debug.PrintToConsole("ok", "Output file is open."); Int32 FRead = 0; byte[] FBuffer = new byte[1024 * 16]; Status = "aout"; Debug.PrintToConsole("ok", String.Format("Writing data for {0} to disk...", OutputDir)); while ((FRead = MStream.Read(FBuffer, 0, FBuffer.Length)) != 0) { Destination.Write(FBuffer, 0, FRead); } Debug.PrintToConsole("ok", String.Format("Done writing {0}.", OutputDir)); Destination.Dispose(); FOpen.Dispose(); } FreeSoundFonts(); Debug.PrintToConsole("ok", "BASS freed."); Bass.BASS_Free(); } catch (Exception ex) { Status = "crsh"; StError = String.Format("The converter encountered an error during the conversion process.\nError: {0}", ex.Message.ToString()); IsCrash = true; Debug.PrintToConsole("err", String.Format("{0} - {1}", ex.InnerException.ToString(), ex.Message.ToString())); } if (!StopRequested && !IsCrash) { Form.Invoke((MethodInvoker) delegate { ((Form)Form).Close(); }); } }
public void StartTextStream() { //Initial streams Streams.Clear(); int initial_streams = 50; // 5 + RNG.Next(5); for (int i = 0; i < initial_streams; i++) { Streams.Add(GetATextStream()); } System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 50; Border b, pb; TextBlock tb, ptb; timer.Elapsed += (o, e) => { try { this.Dispatcher.Invoke(() => { for (int s = 0; s < Streams.Count; s++) { MStream stream = Streams[s]; if (stream.Current <= stream.Max && stream.CurrentCharIndex < stream.Text.Length) { b = BlocksArray[stream.CurrentBlockIndex]; tb = b.Child as TextBlock; tb.Text = stream.Text[stream.CurrentCharIndex++].ToString(); tb.Foreground = new SolidColorBrush(Color.FromRgb(150, 255, 150)); tb.FontWeight = FontWeights.Bold; if (LogoBlockRanges.Exists(br => stream.CurrentBlockIndex >= br.Start && stream.CurrentBlockIndex < br.End)) { b.Background = GetALogoColor(); } if (stream.PreviousBlockIndex >= 0) { pb = BlocksArray[stream.PreviousBlockIndex]; ptb = pb.Child as TextBlock; ptb.Foreground = GetANormalColor(); ptb.FontWeight = FontWeights.Normal; } stream.Current++; stream.PreviousBlockIndex = stream.CurrentBlockIndex; stream.CurrentBlockIndex += horizontal_blocks; } else { Streams.Remove(stream); MStream ns = GetATextStream(); ns.PreviousBlockIndex = stream.PreviousBlockIndex; Streams.Insert(s, ns); } } }, System.Windows.Threading.DispatcherPriority.Background); } catch { } }; timer.Start(); }