public static void RTTick(object sender, EventArgs e) { try { MainWindow.KMCDialogs.MIDIImport.InitialDirectory = Properties.Settings.Default.LastMIDIFolder; if (!MainWindow.KMCStatus.IsKMCBusy) { RTF.KMCIdle(); } else { if (!MainWindow.KMCStatus.IsKMCNowExporting) { RTF.KMCMemoryAllocation(); } else { RTF.KMCBusy(); } } System.Threading.Thread.Sleep(1); } catch (Exception ex) { BasicFunctions.WriteToConsole(ex); } }
// Code by Mac Gravell, edited by Keppy // https://stackoverflow.com/a/929418 static IEnumerable <String> GetFiles(String Target) { Queue <string> AnalyzeQueue = new Queue <string>(); // Add target of queue to the queue AnalyzeQueue.Enqueue(Target); // Do this while the queue list still contains items while (AnalyzeQueue.Count > 0) { // Dequeue the item that is going to be analyzed Target = AnalyzeQueue.Dequeue(); try { // Add each subdir to the queue if (CheckStop) { break; } foreach (string subDir in Directory.GetDirectories(Target)) { if (CheckStop) { break; } AnalyzeQueue.Enqueue(subDir); } } catch (Exception ex) { BasicFunctions.WriteToConsole(ex); } string[] Files = null; try { // Add files from the directory of the queued item Files = Directory.GetFiles(Target); } catch (Exception ex) { BasicFunctions.WriteToConsole(ex); } // If the function detected items, return them to the calling foreach loop if (Files != null) { for (int i = 0; i < Files.Length; i++) { if (CheckStop) { break; } yield return(Files[i]); } } // If the queued item is actually a direct path to the file, return it to the foreach loop if (File.Exists(Target)) { yield return(Target); } } }
public static void PBRWork(object sender, DoWorkEventArgs e) { try { try { BasicFunctions.PlayConversionStart(); // First of all, initialize BASS itself BASSControl.BASSInitSystem(true); BASSControl.InitializeDummyVSTs(); foreach (String str in MainWindow.KMCGlobals.MIDIs) { // Initialize RT stuff Double[] CustomFramerates; BasicFunctions.ReturnCustomFramerate(out CustomFramerates); MainWindow.FPSSimulator.NextDouble(); // Initialize BASS stream BASSControl.BASSStreamSystemRT(str, true); BASSControl.BASSLoadSoundFonts(str); BASSControl.BASSInitVSTiIfNeeded(true); BASSControl.InitializeVSTsForStream(); BASSControl.BASSEffectSettings(); BASSControl.BASSVolumeSlideInit(); // Get length of the stream Int64 pos = 0, es = 0; // Notes stuff MainWindow.KMCStatus.PlayedNotes = 0; if (!MainWindow.KMCGlobals.DoNotCountNotes) { try { MainWindow.KMCGlobals._mySync = new SYNCPROC(BASSControl.NoteSyncProc); Bass.BASS_ChannelSetSync(MainWindow.KMCGlobals._recHandle, BASSSync.BASS_SYNC_MIDI_EVENT, (Int64)BASSMIDIEvent.MIDI_EVENT_NOTE, MainWindow.KMCGlobals._mySync, IntPtr.Zero); MainWindow.KMCStatus.TotalNotesOrg = 0; MainWindow.KMCStatus.TotalNotes = MainWindow.KMCStatus.TotalNotesOrg; } catch (Exception ex) { BasicFunctions.WriteToConsole(ex); MainWindow.KMCGlobals.DoNotCountNotes = true; } } // KMC is now busy MainWindow.KMCStatus.IsKMCNowExporting = true; BassWasapi.BASS_WASAPI_Start(); while (CheckStreamStatus() != BASSActive.BASS_ACTIVE_STOPPED) { if (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER) { BASSControl.BASSPlayBackEngineRT(CustomFramerates, ref pos, ref es); } else { break; } TimerFuncs.MicroSleep(-1); } BASSControl.ReleaseResources( (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER), (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ); if (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) { break; } } MainWindow.KMCStatus.RenderingMode = false; MainWindow.KMCStatus.IsKMCBusy = false; MainWindow.KMCStatus.IsKMCNowExporting = false; MainWindow.KMCGlobals.VSTSkipSettings = false; String Msg = (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ? "PlaybackAborted" : "PlaybackCompleted"; BASSControl.BASSCloseStream(Languages.Parse(Msg), Languages.Parse(Msg), 0); BasicFunctions.PlayConversionStop(); } catch (Exception exception) { BasicFunctions.WriteToConsole(exception); BASSControl.ReleaseResources(false, true); } } catch (Exception exception2) { BASSControl.BASSCloseStreamException(exception2); } }
public static void CPRWork(object sender, DoWorkEventArgs e) { try { try { BasicFunctions.PlayConversionStart(); // First of all, initialize BASS itself BASSControl.BASSInitSystem(false); BASSControl.InitializeDummyVSTs(); foreach (String str in MainWindow.KMCGlobals.MIDIs) { // Initialize RT stuff Double[] CustomFramerates; BasicFunctions.ReturnCustomFramerate(out CustomFramerates); MainWindow.FPSSimulator.NextDouble(); // Initialize BASS stream BASSControl.BASSStreamSystemRT(str, false); BASSControl.BASSLoadSoundFonts(str); BASSControl.BASSInitVSTiIfNeeded(false); BASSControl.InitializeVSTsForStream(); BASSControl.BASSEffectSettings(); BASSControl.BASSVolumeSlideInit(); BASSControl.BASSEncoderInit(MainWindow.KMCGlobals.CurrentEncoder, str); // Get length of the stream Int64 pos = 0, es = 0; // KMC is now busy MainWindow.KMCStatus.IsKMCNowExporting = true; for (pos = 0, es = 0; ;) { if (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER) { if (!BASSControl.BASSEncodingEngineRT(CustomFramerates, ref pos, ref es)) { break; } } else { break; } } BASSControl.ReleaseResources( (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER), (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ); if (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) { break; } } MainWindow.KMCStatus.RenderingMode = false; MainWindow.KMCStatus.IsKMCBusy = false; MainWindow.KMCStatus.IsKMCNowExporting = false; MainWindow.KMCGlobals.VSTSkipSettings = false; String Msg = (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ? "ConversionAborted" : "ConversionCompleted"; BASSControl.BASSCloseStream(Languages.Parse(Msg), Languages.Parse(Msg), 0); if (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) { if (MainWindow.KMCGlobals.AutoShutDownEnabled == true) { Process.Start(new ProcessStartInfo("shutdown", "/s /t 0") { CreateNoWindow = true, UseShellExecute = false }); } if (MainWindow.KMCGlobals.AutoClearMIDIListEnabled) { MainWindow.Delegate.Invoke((MethodInvoker) delegate { MainWindow.Delegate.MIDIList.Items.Clear(); }); } } BasicFunctions.PlayConversionStop(); } catch (Exception exception) { BasicFunctions.WriteToConsole(exception); BASSControl.ReleaseResources(false, true); } } catch (Exception exception2) { BASSControl.BASSCloseStreamException(exception2); } }