コード例 #1
0
ファイル: RenderEngine.cs プロジェクト: SeleDreams/OpenUtau
        public Tuple <MasterAdapter, List <Fader>, CancellationTokenSource, Task> RenderProject(int startTick)
        {
            var source = new CancellationTokenSource();
            var items  = new List <RenderItem>();
            var faders = new List <Fader>();

            foreach (var track in project.tracks)
            {
                var trackItems = PrepareTrack(track, project, startTick).ToArray();
                var sources    = trackItems.Select(item => {
                    var waveSource  = new WaveSource(item.PosMs, item.DurMs, item.Envelope, item.SkipOver);
                    item.OnComplete = data => waveSource.SetWaveData(data);
                    return(waveSource);
                }).ToList();
                sources.AddRange(project.parts
                                 .Where(part => part is UWavePart && part.trackNo == track.TrackNo)
                                 .Select(part => part as UWavePart)
                                 .Select(part => {
                    var waveSource = new WaveSource(
                        project.TickToMillisecond(part.position),
                        project.TickToMillisecond(part.Duration),
                        null,
                        part.skipMs);
                    if (part.Samples != null)
                    {
                        waveSource.SetSamples(part.Samples);
                    }
                    return(waveSource);
                }));
                var trackMix = new WaveMix(sources);
                items.AddRange(trackItems);
                var fader = new Fader(trackMix);
                fader.Scale = PlaybackManager.DecibelToVolume(track.Volume);
                faders.Add(fader);
            }
            items = items.OrderBy(item => item.PosMs).ToList();
            int threads  = Util.Preferences.Default.PrerenderThreads;
            var progress = new Progress(items.Count);
            var task     = Task.Run(() => {
                var progress = new Progress(items.Count);
                Parallel.ForEach(source: items, parallelOptions: new ParallelOptions()
                {
                    MaxDegreeOfParallelism = threads
                }, body: item => {
                    if (source.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    item.progress = progress;
                    Resample(item);
                });
                ReleaseSourceTemp();
                progress.Clear();
            });
            var master = new MasterAdapter(new WaveMix(faders));

            master.SetPosition((int)(project.TickToMillisecond(startTick) * 44100 / 1000));
            return(Tuple.Create(master, faders, source, task));
        }
コード例 #2
0
ファイル: RenderEngine.cs プロジェクト: SeleDreams/OpenUtau
        public List <WaveMix> RenderTracks()
        {
            List <WaveMix> result = new List <WaveMix>();

            foreach (var track in project.tracks)
            {
                var items    = PrepareTrack(track, project, 0);
                var progress = new Progress(items.Count());
                var mix      = new WaveMix(items.Select(item => {
                    var waveSource  = new WaveSource(item.PosMs, item.DurMs, item.Envelope, item.SkipOver);
                    item.progress   = progress;
                    item.OnComplete = data => waveSource.SetWaveData(data);
                    Resample(item);
                    return(waveSource);
                }));
                progress.Clear();
                result.Add(mix);
            }
            return(result);
        }