Пример #1
0
        private void buttonPlayToDisk_Click(object sender, EventArgs e)
        {
            if (!Validate())
            {
                return;
            }

            // TODO: reuse code with device playback
            List <TrackObjectRec> included = new List <TrackObjectRec>();

            foreach (Source.TrackInclusionRec inclusion in source.IncludedTracks)
            {
                if (inclusion.Included)
                {
                    included.Add(inclusion.Track);
                }
            }
#if true // prevents "Add New Data Source..." from working
            SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .Do(
                mainWindow.DisplayName,
                OutputSelectableFileDestinationHandler.OutputSelectableFileGetDestination,
                OutputSelectableFileDestinationHandler.CreateOutputSelectableFileDestinationHandler,
                new OutputSelectableFileArguments(),
                SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerMainLoop,
                new SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments>(
                    mainWindow,
                    document,
                    included,
                    included[0],
                    0,
                    source.SamplingRate,
                    source.EnvelopeUpdateRate,
                    source.NumChannels,
                    (LargeBCDType)source.DefaultBeatsPerMinute,
                    source.OverallVolumeScalingFactor,
                    (LargeBCDType)source.ScanningGap,
                    source.OutputNumBits,
                    source.ClipWarning,
                    source.Oversampling,
                    source.ShowSummary,
                    source.Deterministic,
                    source.Seed,
                    null /*automationSettings*/),
                SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerCompletion,
                mainWindow,
                source.NumChannels,
                source.OutputNumBits,
                source.SamplingRate,
                source.Oversampling,
                true /*showProgressWindow*/,
                true /*modal*/);
#endif
        }
Пример #2
0
        public static OutputGeneric <T, SynthesizerGeneratorParams <T, W>, W> Do(
            string baseName,
            GetDestinationMethod <T> getDestination,
            CreateDestinationHandlerMethod <T, W> createDestinationHandler,
            W destinationHandlerArguments,
            GeneratorMainLoopMethod <T, SynthesizerGeneratorParams <T, W>, W> generatorMainLoop,
            SynthesizerGeneratorParams <T, W> generatorParams,
            GeneratorCompletionMethod <SynthesizerGeneratorParams <T, W> > generatorCompletion,
            IMainWindowServices mainWindow,
            NumChannelsType channels,
            NumBitsType bits,
            int samplingRate,
            int oversamplingFactor,
            bool showProgressWindow,
            bool modal)
        {
            // prerequisites

            /* force an auto-save since play may take a long time */
            MainWindow.DoAutosaveGlobally();

            /* make sure all objects are up to date */
            if (!mainWindow.MakeUpToDate())
            {
                /* couldn't compile score elements */
                return(null);
            }

            return(OutputGeneric <T, SynthesizerGeneratorParams <T, W>, W> .Do(
                       baseName,
                       getDestination,
                       createDestinationHandler,
                       destinationHandlerArguments,
                       generatorMainLoop,
                       generatorParams,
                       generatorCompletion,
                       channels,
                       bits,
                       samplingRate,
                       oversamplingFactor,
                       showProgressWindow,
                       modal));
        }
Пример #3
0
 public static void SynthesizerMainLoop <U>(
     SynthesizerGeneratorParams <T, W> generatorParams,
     Synthesizer.DataOutCallbackMethod <OutputGeneric <T, U, W> > dataCallback,
     OutputGeneric <T, U, W> dataCallbackState,
     Synthesizer.StopTask stopper)
 {
     try
     {
         generatorParams.result = Synthesizer.DoSynthesizer(
             generatorParams.document,
             dataCallback,
             dataCallbackState,
             generatorParams.listOfTracks,
             generatorParams.keyTrack,
             generatorParams.frameToStartAt,
             generatorParams.samplingRate * generatorParams.oversamplingFactor,
             generatorParams.oversamplingFactor,
             generatorParams.envelopeRate,
             generatorParams.defaultBeatsPerMinute,
             generatorParams.overallVolumeScalingReciprocal,
             generatorParams.scanningGap,
             stopper,
             generatorParams.showSummary,
             out generatorParams.errorInfo,
             generatorParams.interactionLog,
             generatorParams.deterministic,
             generatorParams.randomSeed,
             generatorParams.automationSettings);
     }
     catch (Exception exception)
     {
         Program.WriteLog("SynthesizerMainLoop", exception.ToString());
         generatorParams.exception = exception;
         stopper.Stop();
     }
     finally
     {
         generatorParams.completed = true;
     }
 }
Пример #4
0
        public static void SynthesizerCompletion(
            SynthesizerGeneratorParams <T, W> generatorParams,
            ref ClipInfo clipInfo)
        {
            string interactionLogFinal = generatorParams.interactionLog.ToString();

            if (interactionLogFinal.Length != 0)
            {
                IInteractionWindowService interaction = generatorParams.mainWindow.GetInteractionWindow();
                interaction.Append(interactionLogFinal);
            }

            string message = null;

            if (generatorParams.exception != null)
            {
                message = generatorParams.exception.ToString();
            }
            else if (generatorParams.result != Synthesizer.SynthErrorCodes.eSynthDone)
            {
                message = Synthesizer.GetErrorMessage(generatorParams.result, generatorParams.errorInfo);
            }
            if (message != null)
            {
                MessageBox.Show(message, "Synthesis Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

            if ((message == null) && generatorParams.clipWarn && (clipInfo.clippedSampleCount != 0))
            {
                string clippingMessage = String.Format(
                    "{0} out of {1} samples were clipped, with a maximum overextent of {2:0.000000}. Set the inverse volume to be greater than {3:0.000000} to eliminate the clipping.",
                    clipInfo.clippedSampleCount,
                    clipInfo.totalSampleCount,
                    clipInfo.maxClipExtent,
                    clipInfo.maxClipExtent * generatorParams.overallVolumeScalingReciprocal);
                MessageBox.Show(clippingMessage, "Clipping Ocurred", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #5
0
        bool IMenuStripManagerHandler.ExecuteMenuItem(MenuStripManager menuStrip, ToolStripMenuItem menuItem)
        {
            if (menuItem == menuStrip.editNotePropertiesToolStripMenuItem)
            {
                EditNoteProperties();
                return(true);
            }
            else if (menuItem == menuStrip.editTrackPropertiesToolStripMenuItem)
            {
                EditTrackProperties();
                return(true);
            }
            else if (menuItem == menuStrip.selectAllToolStripMenuItem)
            {
                trackViewControl.TrackViewSelectAll();
                return(true);
            }
            else if (menuItem == menuStrip.pasteToolStripMenuItem)
            {
                trackViewControl.TrackViewAttemptPaste();
                return(true);
            }
            else if (menuItem == menuStrip.clearToolStripMenuItem)
            {
                if (trackViewControl.TrackViewIsASingleNoteSelected() || trackViewControl.TrackViewIsASingleCommandSelected())
                {
                    trackViewControl.TrackViewDeleteSingleNoteOrCommand();
                }
                else if (trackViewControl.TrackViewIsARangeSelected())
                {
                    trackViewControl.TrackViewDeleteRangeSelection();
                }
                trackViewControl.TrackViewShowSelection();
                return(true);
            }
            else if (menuItem == menuStrip.cutToolStripMenuItem)
            {
                trackViewControl.TrackViewCutRangeSelection();
                trackViewControl.TrackViewShowSelection();
                return(true);
            }
            else if (menuItem == menuStrip.copyToolStripMenuItem)
            {
                trackViewControl.TrackViewCopyRangeSelection();
                return(true);
            }
            else if (menuItem == menuStrip.undoToolStripMenuItem)
            {
                trackViewControl.UndoHelper.Undo();
                return(true);
            }
            else if (menuItem == menuStrip.redoToolStripMenuItem)
            {
                trackViewControl.UndoHelper.Redo();
                return(true);
            }
            else if ((menuItem == menuStrip.playTrackFromHereToolStripMenuItem) ||
                     (menuItem == menuStrip.playTrackFromHereToDiskToolStripMenuItem))
            {
                IPlayPrefsProvider playPrefsProvider = mainWindow.GetPlayPrefsProvider();

                int StartIndex;
                if (trackViewControl.TrackViewIsARangeSelected())
                {
                    StartIndex = trackViewControl.TrackViewGetRangeStart();
                }
                else if (trackViewControl.TrackViewIsThereInsertionPoint())
                {
                    StartIndex = trackViewControl.TrackViewGetInsertionPointIndex();
                }
                else if (trackViewControl.TrackViewIsASingleNoteSelected() ||
                         trackViewControl.TrackViewIsASingleCommandSelected())
                {
                    StartIndex = trackViewControl.TrackViewGetSingleNoteSelectionFrameNumber();
                }
                else
                {
                    StartIndex = 0; /* default to the beginning for other selections */
                }

                List <TrackObjectRec> TrackList = new List <TrackObjectRec>();
                TrackList.Add(trackObject);

                if (menuItem == menuStrip.playTrackFromHereToolStripMenuItem)
                {
#if true // prevents "Add New Data Source..." from working
                    SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .Do(
                        mainWindow.DisplayName,
                        OutputDeviceEnumerator.OutputDeviceGetDestination,
                        OutputDeviceEnumerator.CreateOutputDeviceDestinationHandler,
                        new OutputDeviceArguments(playPrefsProvider.BufferDuration),
                        SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .SynthesizerMainLoop,
                        new SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments>(
                            mainWindow,
                            mainWindow.Document,
                            TrackList,
                            trackObject,
                            StartIndex,
                            playPrefsProvider.SamplingRate,
                            playPrefsProvider.EnvelopeUpdateRate,
                            playPrefsProvider.NumChannels,
                            (LargeBCDType)playPrefsProvider.DefaultBeatsPerMinute,
                            playPrefsProvider.OverallVolumeScalingFactor,
                            (LargeBCDType)playPrefsProvider.ScanningGap,
                            playPrefsProvider.OutputNumBits,
                            false /*clipWarning*/,
                            playPrefsProvider.Oversampling,
                            playPrefsProvider.ShowSummary,
                            playPrefsProvider.Deterministic,
                            playPrefsProvider.Seed,
                            null /*automationSettings*/),
                        SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .SynthesizerCompletion,
                        mainWindow,
                        playPrefsProvider.NumChannels,
                        playPrefsProvider.OutputNumBits,
                        playPrefsProvider.SamplingRate,
                        playPrefsProvider.Oversampling,
                        true /*showProgressWindow*/,
                        true /*modal*/);
#endif
                }
                else
                {
#if true // prevents "Add New Data Source..." from working
                    SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .Do(
                        mainWindow.DisplayName,
                        OutputSelectableFileDestinationHandler.OutputSelectableFileGetDestination,
                        OutputSelectableFileDestinationHandler.CreateOutputSelectableFileDestinationHandler,
                        new OutputSelectableFileArguments(),
                        SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerMainLoop,
                        new SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments>(
                            mainWindow,
                            mainWindow.Document,
                            TrackList,
                            trackObject,
                            StartIndex,
                            playPrefsProvider.SamplingRate,
                            playPrefsProvider.EnvelopeUpdateRate,
                            playPrefsProvider.NumChannels,
                            (LargeBCDType)playPrefsProvider.DefaultBeatsPerMinute,
                            playPrefsProvider.OverallVolumeScalingFactor,
                            (LargeBCDType)playPrefsProvider.ScanningGap,
                            playPrefsProvider.OutputNumBits,
                            false /*clipWarning*/,
                            playPrefsProvider.Oversampling,
                            playPrefsProvider.ShowSummary,
                            playPrefsProvider.Deterministic,
                            playPrefsProvider.Seed,
                            null /*automationSettings*/),
                        SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerCompletion,
                        mainWindow,
                        playPrefsProvider.NumChannels,
                        playPrefsProvider.OutputNumBits,
                        playPrefsProvider.SamplingRate,
                        playPrefsProvider.Oversampling,
                        true /*showProgressWindow*/,
                        true /*modal*/);
#endif
                }
                return(true);
            }
            else if ((menuItem == menuStrip.playAllFromHereToolStripMenuItem) ||
                     (menuItem == menuStrip.playAllFromHereToDiskToolStripMenuItem))
            {
                IPlayPrefsProvider playPrefsProvider = mainWindow.GetPlayPrefsProvider();

                int StartIndex;
                if (trackViewControl.TrackViewIsARangeSelected())
                {
                    StartIndex = trackViewControl.TrackViewGetRangeStart();
                }
                else if (trackViewControl.TrackViewIsThereInsertionPoint())
                {
                    StartIndex = trackViewControl.TrackViewGetInsertionPointIndex();
                }
                else if (trackViewControl.TrackViewIsASingleNoteSelected() ||
                         trackViewControl.TrackViewIsASingleCommandSelected())
                {
                    StartIndex = trackViewControl.TrackViewGetSingleNoteSelectionFrameNumber();
                }
                else
                {
                    StartIndex = 0; /* default to the beginning for other selections */
                }

                List <TrackObjectRec> TrackList = new List <TrackObjectRec>();
                TrackList.Add(trackObject); // we must include the current track
                foreach (TrackObjectRec track in playPrefsProvider.IncludedTracks)
                {
                    if (track != trackObject)
                    {
                        TrackList.Add(track);
                    }
                }

                if (menuItem == menuStrip.playAllFromHereToolStripMenuItem)
                {
#if true // prevents "Add New Data Source..." from working
                    SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .Do(
                        mainWindow.DisplayName,
                        OutputDeviceEnumerator.OutputDeviceGetDestination,
                        OutputDeviceEnumerator.CreateOutputDeviceDestinationHandler,
                        new OutputDeviceArguments(playPrefsProvider.BufferDuration),
                        SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .SynthesizerMainLoop,
                        new SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments>(
                            mainWindow,
                            mainWindow.Document,
                            TrackList,
                            trackObject,
                            StartIndex,
                            playPrefsProvider.SamplingRate,
                            playPrefsProvider.EnvelopeUpdateRate,
                            playPrefsProvider.NumChannels,
                            (LargeBCDType)playPrefsProvider.DefaultBeatsPerMinute,
                            playPrefsProvider.OverallVolumeScalingFactor,
                            (LargeBCDType)playPrefsProvider.ScanningGap,
                            playPrefsProvider.OutputNumBits,
                            false /*clipWarning*/,
                            playPrefsProvider.Oversampling,
                            playPrefsProvider.ShowSummary,
                            playPrefsProvider.Deterministic,
                            playPrefsProvider.Seed,
                            null /*automationSettings*/),
                        SynthesizerGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .SynthesizerCompletion,
                        mainWindow,
                        playPrefsProvider.NumChannels,
                        playPrefsProvider.OutputNumBits,
                        playPrefsProvider.SamplingRate,
                        playPrefsProvider.Oversampling,
                        true /*showProgressWindow*/,
                        true /*modal*/);
#endif
                }
                else
                {
#if true // prevents "Add New Data Source..." from working
                    SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .Do(
                        mainWindow.DisplayName,
                        OutputSelectableFileDestinationHandler.OutputSelectableFileGetDestination,
                        OutputSelectableFileDestinationHandler.CreateOutputSelectableFileDestinationHandler,
                        new OutputSelectableFileArguments(),
                        SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerMainLoop,
                        new SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments>(
                            mainWindow,
                            mainWindow.Document,
                            TrackList,
                            trackObject,
                            StartIndex,
                            playPrefsProvider.SamplingRate,
                            playPrefsProvider.EnvelopeUpdateRate,
                            playPrefsProvider.NumChannels,
                            (LargeBCDType)playPrefsProvider.DefaultBeatsPerMinute,
                            playPrefsProvider.OverallVolumeScalingFactor,
                            (LargeBCDType)playPrefsProvider.ScanningGap,
                            playPrefsProvider.OutputNumBits,
                            false /*clipWarning*/,
                            playPrefsProvider.Oversampling,
                            playPrefsProvider.ShowSummary,
                            playPrefsProvider.Deterministic,
                            playPrefsProvider.Seed,
                            null /*automationSettings*/),
                        SynthesizerGeneratorParams <OutputSelectableFileDestination, OutputSelectableFileArguments> .SynthesizerCompletion,
                        mainWindow,
                        playPrefsProvider.NumChannels,
                        playPrefsProvider.OutputNumBits,
                        playPrefsProvider.SamplingRate,
                        playPrefsProvider.Oversampling,
                        true /*showProgressWindow*/,
                        true /*modal*/);
#endif
                }
                return(true);
            }
            else if (menuItem == menuStrip.showSelectionToolStripMenuItem)
            {
                trackViewControl.TrackViewShowSelection();
                return(true);
            }
            else if (menuItem == menuStrip.transposeToolStripMenuItem)
            {
                double Transpose = 0;
                CmdDlgOneParam.CommandDialogOneParam("Transpose half-steps:", null, ref Transpose);
                if (Transpose != 0)
                {
                    trackViewControl.TrackViewTransposeSelection((int)Transpose);
                }
                return(true);
            }
            else if (menuItem == menuStrip.goToLineToolStripMenuItem)
            {
                double NewMeasure = 0;
                CmdDlgOneParam.CommandDialogOneParam("Go To Measure:", null, ref NewMeasure);
                if (NewMeasure != 0)
                {
                    trackViewControl.TrackViewShowMeasure((int)NewMeasure);
                }
                return(true);
            }
            else if (menuItem == menuStrip.doubleDurationToolStripMenuItem)
            {
                trackViewControl.TrackViewAdjustDuration(2, 1);
                return(true);
            }
            else if (menuItem == menuStrip.halveDurationToolStripMenuItem)
            {
                trackViewControl.TrackViewAdjustDuration(1, 2);
                return(true);
            }

            return(false);
        }