Ejemplo n.º 1
0
        public MixingWaveProvider32 Overlay(ISampleProvider music, ISampleProvider watermark, double watermarkOffset)
        {
            if (music == null || watermark == null)
            {
                throw new ArgumentNullException("Не удалось наложить водяной знак. Трек или водяной знак были пустыми");
            }

            // Инициализация энкодера(чтобы получать на выходе любой формат)
            NAudio.MediaFoundation.MediaFoundationApi.Startup();

            var sampleProvider = new OffsetSampleProvider(watermark.ToWaveProvider().ToSampleProvider()); //Деление на sample

            sampleProvider.DelayBy = TimeSpan.FromSeconds(watermarkOffset);                               //Добавление задержки

            var watermarkWaveProvider = sampleProvider.ToWaveProvider();                                  //Перевод в wave водяного знака
            var musicWaveProvider     = music.ToWaveProvider();                                           //Перевод в wave музыки

            // Слияние трека и водяного знака
            var result = new MixingWaveProvider32(new[] { musicWaveProvider, watermarkWaveProvider });

            result.ToSampleProvider().ToWaveProvider16();

            return(result);
        }
Ejemplo n.º 2
0
 private void SaveSong(Song songToSave, bool skipValidation = false)
 {
     try {
         Cursor.Current = Cursors.WaitCursor;
         bool reload = false;
         if (!skipValidation)
         {
             ValidateSong();
         }
         //might need to generate the lead in time here and add the lead in time to every note...
         if (!songToSave.LeadInTimeGenerated)
         {
             audioFile.Position = 0; //reset position else we'll just offset everything to where it left playing
             var offset = new OffsetSampleProvider(audioFile.ToSampleProvider());
             if (songToSave.LastLeadInTime != -1)
             {
                 var lastLeadInMS = songToSave.LastLeadInTime * 1000;
                 //need to remove the delay then readdd.
                 offset.SkipOver = TimeSpan.FromSeconds(songToSave.LastLeadInTime);
                 //audioFile.Position = CurrentSong.LastLeadInTime * 1000; //this skips the file forward by the amount of time in the last delay.
                 foreach (var beat in songToSave.EasyBeats)
                 {
                     beat.HitTime -= lastLeadInMS;
                 }
                 foreach (var beat in songToSave.AdvancedBeats)
                 {
                     beat.HitTime -= lastLeadInMS;
                 }
                 foreach (var beat in songToSave.ExpertBeats)
                 {
                     beat.HitTime -= lastLeadInMS;
                 }
                 if (songToSave.PreviewStart > lastLeadInMS)
                 {
                     songToSave.PreviewStart -= lastLeadInMS;
                 }
                 if (songToSave.PreviewEnd > lastLeadInMS)
                 {
                     songToSave.PreviewEnd -= lastLeadInMS;
                 }
             }
             offset.DelayBy = TimeSpan.FromSeconds(songToSave.LeadInTime);
             var tempFileName = Path.Combine(SongFolder, Path.GetFileNameWithoutExtension(songToSave.FileName) + "extend" + Path.GetExtension(songToSave.FileName));
             WaveFileWriter.CreateWaveFile(tempFileName, offset.ToWaveProvider());
             File.Delete(Path.Combine(SongFolder, songToSave.FileName));
             File.Move(tempFileName, Path.Combine(SongFolder, songToSave.FileName));
             var leadInMS = songToSave.LeadInTime * 1000;
             foreach (var beat in songToSave.EasyBeats)
             {
                 beat.HitTime += leadInMS;
             }
             foreach (var beat in songToSave.AdvancedBeats)
             {
                 beat.HitTime += leadInMS;
             }
             foreach (var beat in songToSave.ExpertBeats)
             {
                 beat.HitTime += leadInMS;
             }
             if (songToSave.PreviewStart > 0)
             {
                 songToSave.PreviewStart += leadInMS;
             }
             if (songToSave.PreviewEnd > 0)
             {
                 songToSave.PreviewEnd += leadInMS;
             }
             songToSave.LeadInTimeGenerated = true;
             reload = true; //need to reload to account for the new offset.
         }
         if (!String.IsNullOrWhiteSpace(songToSave.ImageData))
         {
             File.WriteAllBytes(Path.Combine(SongFolder, songToSave.ImageFileName), Convert.FromBase64String(songToSave.ImageData));
             songToSave.ImageData = String.Empty;
         }
         var json = JsonConvert.SerializeObject(songToSave);
         File.WriteAllText(Path.Combine(SongFolder, $"{Path.GetFileNameWithoutExtension(SongFile)}.js"), json);
         File.Delete(SongFile);
         ZipFile.CreateFromDirectory(SongFolder, SongFile);
         if (reload)
         {
             LoadSong(SongFile);
         }
     } catch (SaveValidationException e) {
         MessageBox.Show("Your song has not been saved due to an error: " + e.Message, "Save validation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     } finally {
         Cursor.Current = Cursors.Default;
     }
 }