public void QueueSection(string streamKey, string sectionKey) { var audioStream = GetAudioStream(streamKey); if (audioStream == null) { throw new Exception("Cannot find stream " + streamKey); } var audioSection = GetAudioSection(streamKey, sectionKey); if (audioSection == null) { throw new Exception("Cannot find section " + sectionKey + " for stream " + streamKey); } if (!audioSection.HasStartAndEnd) { throw new Exception("Cannot find start and end for section " + sectionKey + " for stream " + streamKey); } var startPosition = audioSection.HasOffset ? audioSection.Offset.Position + 500 : audioSection.Start.Position; AudioStreamHelper.SetPosition(audioStream, startPosition); SetSectionTempo(audioStream, audioSection); }
private static void SetSectionTempo(AudioStream audioStream, AudioSection audioSection) { if (audioSection.TargetBpm != 0) { AudioStreamHelper.SetTempoToMatchBpm(audioStream, audioSection.Bpm, audioSection.TargetBpm); } }
private void LoadSample(string file) { var lengthInSeconds = AudioStreamHelper.GetLength(file); var bpm = BpmHelper.GetBpmFromLoopLength(lengthInSeconds); var sample = new Sample { Filename = file, Description = (Path.GetFileNameWithoutExtension(file) + "").Replace(_folder, "").Replace("\\", ""), IsAtonal = true, IsPrimaryLoop = true, Gain = 0, LoopMode = LoopMode.FullLoop, Length = lengthInSeconds, TrackLength = (decimal)lengthInSeconds, Offset = 0, Start = 0, Key = "", Bpm = bpm, Tags = new List <string>(), TrackArtist = (Path.GetDirectoryName(file) + "").Replace(_folder, "").Replace("\\", ""), TrackTitle = (Path.GetFileNameWithoutExtension(file) + "").Replace(_folder, "").Replace("\\", ""), }; lock (_samples) { _samples.Add(sample); } }
public List <Track> GetDuplicateButDifferentShufflerTracks() { var duplicateButDifferentTracks = new List <Track>(); var duplicateTracksByTitle = Tracks .Where(track => track.IsShufflerTrack) .GroupBy(track => track.Description) .Where(group => group.Count() > 1) .ToList(); foreach (var duplicateTrackByTitle in duplicateTracksByTitle) { var tracks = duplicateTrackByTitle.ToList(); foreach (var track in tracks) { track.FullLength = Convert.ToDecimal(AudioStreamHelper.GetLength(track.Filename)); } var duplicateTracksByLength = tracks .GroupBy(track => track.FullLength) .ToList(); if (duplicateTracksByLength.Count > 1) { duplicateButDifferentTracks.AddRange(duplicateTracksByLength.SelectMany(x => x)); } } return(duplicateButDifferentTracks.OrderBy(x => x.Description).ToList()); }
/// <summary> /// Mutes the track FX. /// </summary> public void StopTrackFxSend() { if (CurrentTrack == null || LastTrackFxTrigger == null || LastTrackFxTriggerTrack == null) { return; } // DebugHelper.WriteLine("Start StopTrackFXSend"); _trackSendMixer.SetVolume(0); // DebugHelper.WriteLine("Calculate TrackFXSend Length"); var position = AudioStreamHelper.GetPosition(LastTrackFxTriggerTrack); var positionSeconds = LastTrackFxTriggerTrack.SamplesToSeconds(position); var length = positionSeconds - LastTrackFxTrigger.Start; if (length <= 0 || position >= LastTrackFxTriggerTrack.FadeOutStart) { length = LastTrackFxTriggerTrack.SamplesToSeconds(LastTrackFxTriggerTrack.FadeOutStart) - LastTrackFxTrigger.Start; } LastTrackFxTrigger.Length = length; // DebugHelper.WriteLine("End StopTrackFXSend"); }
public void StopRecordingManualExtendedMix(bool powerDownAfterFade) { if (CurrentTrack == null) { return; } if (PreviousTrack == null) { return; } if (!IsManualMixMode) { return; } if (PreviousManaulExtendedFadeType == ExtendedFadeType.PowerDown) { return; } CreateLastExtendedMixAttributes(); var attributes = LastExtendedMixAttributes; attributes.FadeEnd = AudioStreamHelper.GetPosition(PreviousTrack); attributes.FadeLength = GetAdjustedPositionSeconds(CurrentTrack); attributes.FadeEndLoop = PreviousTrack.CurrentEndLoop; attributes.FadeEndVolume = Convert.ToSingle(AudioStreamHelper.GetVolume(PreviousTrack) / 100); attributes.PowerDownAfterFade = powerDownAfterFade; if (IsManualMixMode) { RaiseOnEndFadeIn(); } }
/// <summary> /// Draws the current selected position. /// </summary> private void DrawCurrentPosition() { var position = AudioStreamHelper.GetPosition(BassPlayer.RawLoopTrack); BeginInvoke((MethodInvoker) delegate { var oldBitmap = picWaveForm.Image; var bitmap = new Bitmap(picWaveForm.Width, picWaveForm.Height); if (position >= ZoomStart && position <= ZoomEnd) { var positionPercent = (position - ZoomStart) / (double)ZoomLength; var x = Convert.ToInt32(Math.Round(positionPercent * picWaveForm.Width, 0)); using (var pen = new Pen(Color.Gray)) using (var graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.Black); graphics.DrawLine(pen, x, 0, x, picWaveForm.Height - 1); } } bitmap.MakeTransparent(Color.Black); picWaveForm.Image = bitmap; oldBitmap?.Dispose(); }); }
public void Play(string streamKey) { var audioStream = GetAudioStream(streamKey); ApplySyncIfOneExistsForCurrentPosition(audioStream); AudioStreamHelper.Play(audioStream); }
/// <summary> /// Plays the raw loop track at the start of the raw-loop section. /// </summary> public void StopRawLoop() { if (RawLoopTrack == null) { return; } // DebugHelper.WriteLine("Pausing raw-loop"); AudioStreamHelper.Pause(RawLoopTrack); }
public void Pause() { var streamKeys = GetStreamKeys(); foreach (var streamKey in streamKeys) { var audioStream = GetAudioStream(streamKey); AudioStreamHelper.Pause(audioStream); } }
private void ApplySyncIfOneExistsForCurrentPosition(AudioStream audioStream) { var position = AudioStreamHelper.GetPosition(audioStream); var sync = GetAudioSync(audioStream, position); if (sync != null && sync.SyncType != SyncType.AudioStreamEvent) { OnSync(sync.Id, audioStream.ChannelId, int.MinValue, IntPtr.Zero); } }
public void Mute(string streamKey) { var audioStream = GetAudioStream(streamKey); var volume = AudioStreamHelper.GetVolume(audioStream); if (volume != 0) { AudioStreamHelper.SetVolumeSlide(audioStream, 1F, 0F, 0.1D); } }
public SubSeekableAudioStream(ISeekableAudioStream parent, Timestamp start, Timestamp end, bool disposeAfterUse = true) { _parent = parent; _disposeAfterUse = disposeAfterUse; _start = AudioStreamHelper.ConvertTimeToStreamPos(start, Rate, IsStereo); _pos = new Timestamp(0, Rate * (IsStereo ? 2 : 1)); _length = AudioStreamHelper.ConvertTimeToStreamPos(end, Rate, IsStereo) - _start; Debug.Assert(_length.TotalNumberOfFrames % (IsStereo ? 2 : 1) == 0); _parent.Seek(_start); }
private void OnSectionEnd(AudioSection audioSection, AudioStreamSection streamSection) { if (audioSection.LoopIndefinitely || audioSection.HasOffset) { AudioStreamHelper.SetPosition(streamSection.AudioStream, audioSection.Start.Position); ApplySyncIfOneExistsForCurrentPosition(streamSection.AudioStream); } else { PlayNextSection(audioSection, streamSection); } }
public decimal GetManualMixVolume() { if (PreviousTrack == null) { return(100M); } var volume = AudioStreamHelper.GetVolume(PreviousTrack) - (decimal)DefaultFadeOutEndVolume; volume = volume / (decimal)DefaultFadeOutStartVolume; volume = volume * 100; return(100 - volume); }
/// <summary> /// Calculates the length track and saves it in the tag data /// </summary> /// <param name="track">The track.</param> public static void UpdateLength(Track track) { var length = decimal.Round(Convert.ToDecimal(AudioStreamHelper.GetLength(track.Filename)), 3); if (length == decimal.Round(track.FullLength, 3)) { return; } track.Length = length; track.FullLength = length; SaveTrack(track); }
/// <summary> /// Starts playing the raw loop track at the offset of the raw-loop section. /// </summary> public void PlayRawLoop() { if (RawLoopTrack == null) { return; } // DebugHelper.WriteLine("Playing in raw-loop mode"); AudioStreamHelper.Pause(RawLoopTrack); AudioStreamHelper.SetPosition(RawLoopTrack, RawLoopTrack.RawLoopOffset); AudioStreamHelper.Play(RawLoopTrack); }
public AudioStream Load(string streamKey, string filename) { if (!File.Exists(filename)) { throw new Exception("Cannot find file " + filename); } if (GetStreamSection(streamKey) != null) { throw new Exception("AudioStream already exists with streamKey " + streamKey); } var audioStream = new Sample { Filename = filename }; var tags = TagHelper.LoadTags(filename); if (tags != null) { if (tags.Gain.HasValue) { audioStream.Gain = tags.Gain.Value; } if (tags.Bpm.HasValue) { audioStream.Bpm = tags.Bpm.Value; } audioStream.Description = TrackHelper.GuessTrackDescription(filename, tags.Artist, tags.Title); } AudioStreamHelper.LoadAudio(audioStream); audioStream.SyncProc = OnSync; AudioStreamHelper.AddToMixer(audioStream, Output); AudioStreamHelper.SetPosition(audioStream, 0); lock (_streamSections) { _streamSections.Add(new AudioStreamSection { Key = streamKey, AudioStream = audioStream, AudioSections = new List <AudioSection>() }); } return(audioStream); }
/// <summary> /// Gets the current automated track FX. /// </summary> /// <returns>The current automated track FX.</returns> private SampleTrigger GetCurrentSampleTrigger(AutomationAttributes attributes = null) { if (CurrentTrack == null) { return(null); } if (attributes == null) { attributes = AutomationAttributesHelper.GetAutomationAttributes(CurrentTrack.Description); } var position = AudioStreamHelper.GetPosition(CurrentTrack); return(GetCurrentSampleTriggers(attributes) .OrderBy(t => Math.Abs(t.StartSample - position)) .FirstOrDefault()); }
/// <summary> /// Makes the power off noise on a track /// </summary> public void PowerOffCurrentTrack() { StopSamples(); if (CurrentTrack == null) { return; } if (PlayState != PlayState.Playing) { return; } if (!IsTrackInUse(CurrentTrack)) { return; } AudioStreamHelper.PowerDown(CurrentTrack); }
/// <summary> /// Pauses the track. /// </summary> public void PausePreviousTrack() { if (PreviousTrack == null) { return; } if (!IsTrackInUse(PreviousTrack)) { return; } if (!AudioStreamHelper.IsPlaying(PreviousTrack)) { return; } StopRecordingManualExtendedMix(); AudioStreamHelper.SmoothPause(PreviousTrack); }
/// <summary> /// Makes the power off noise on a track /// </summary> public void PowerOffPreviousTrack() { if (PreviousTrack == null) { return; } if (PlayState != PlayState.Playing) { return; } if (!IsTrackInUse(PreviousTrack)) { return; } AudioStreamHelper.PowerDown(PreviousTrack); StopRecordingManualExtendedMix(true); }
public void Unload(string streamKey) { var streamSection = GetStreamSection(streamKey); if (streamSection == null) { return; } AudioStreamHelper.Pause(streamSection.AudioStream); lock (_audioStreamEvents) { _audioStreamEvents.RemoveAll(x => x.StreamKey == streamKey); } lock (streamSection) { foreach (var sync in streamSection.AudioSections.SelectMany(section => section.AudioSyncs)) { RemoveSyncFromStream(streamSection.AudioStream, sync); } } lock (streamSection.AudioStream) { foreach (var sync in streamSection.AudioStream.AudioSyncs) { RemoveSyncFromStream(streamSection.AudioStream, sync); } streamSection.AudioStream.AudioSyncs.Clear(); } AudioStreamHelper.RemoveFromMixer(streamSection.AudioStream, Output); AudioStreamHelper.UnloadAudio(streamSection.AudioStream); streamSection.AudioStream.SyncProc = null; lock (_streamSections) { _streamSections.Remove(streamSection); } }
public bool Seek(Timestamp where) { _pos = AudioStreamHelper.ConvertTimeToStreamPos(where, Rate, IsStereo); if (_pos > _length) { _pos = _length; return(false); } if (_parent.Seek(_pos + _start)) { return(true); } else { _pos = _length; return(false); } }
private void StopRecordingSampleTrigger() { if (CurrentTrack == null || LastSampleTrigger == null || LastSampleTriggerTrack == null) { return; } var position = AudioStreamHelper.GetPosition(LastSampleTriggerTrack); var positionSeconds = LastSampleTriggerTrack.SamplesToSeconds(position); var length = positionSeconds - LastSampleTrigger.Start; if (length <= 0 || position >= LastSampleTriggerTrack.FadeOutStart) { length = LastSampleTriggerTrack.SamplesToSeconds(LastSampleTriggerTrack.FadeOutStart) - LastSampleTrigger.Start; } LastSampleTrigger.Length = length; }
/// <summary> /// Gets the current automated track FX. /// </summary> /// <returns>The current automated track FX.</returns> private TrackFXTrigger GetPrevTrackFxTrigger(AutomationAttributes attributes = null) { if (CurrentTrack == null) { return(null); } if (attributes == null) { attributes = AutomationAttributesHelper.GetAutomationAttributes(CurrentTrack.Description); } var position = AudioStreamHelper.GetPosition(CurrentTrack); return(attributes .TrackFXTriggers .Where(ta => ta.StartSample <= position) .OrderBy(ta => Math.Abs(ta.StartSample - position)) .FirstOrDefault()); }
public void SetManualMixVolume(decimal value) { value = 100M - value; var track = PreviousTrack; if (track == null) { return; } var range = (decimal)DefaultFadeOutStartVolume; var volume = (range * (value / 100)); volume = (decimal)DefaultFadeOutEndVolume + volume; AudioStreamHelper.SetVolume(track, volume); OnManualMixVolumeChanged?.Invoke(CurrentTrack, EventArgs.Empty); }
/// <summary> /// Silences the track FX. /// </summary> public void StartTrackFxSend() { _trackSendMixer.SetVolume(50M); if (CurrentTrack == null) { return; } LastTrackFxTriggerTrack = CurrentTrack; var position = AudioStreamHelper.GetPosition(LastTrackFxTriggerTrack); LastTrackFxTrigger = new TrackFXTrigger { Start = LastTrackFxTriggerTrack.SamplesToSeconds(position), DelayNotes = TrackSendFxDelayNotes }; _trackSendMixer.SetPluginBpm(); }
/// <summary> /// Loads a track for playing as the raw loop track. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> /// <exception cref="System.Exception">Cannot find file + filename</exception> public Track LoadRawLoopTrack(string filename) { if (!File.Exists(filename)) { throw new Exception("Cannot find file " + filename); } if (RawLoopTrack != null) { UnloadRawLoopTrack(); } var track = new Track { Id = _nextTrackId++, Filename = filename }; SetArtistAndTitle(track, "", ""); LoadTagData(track); ExtenedAttributesHelper.LoadExtendedAttributes(track); LoadTrackAudioData(track); // DebugHelper.WriteLine("Loaded raw loop track " + track.Description); // set track sync event track.SyncProc = OnTrackSync; track.CurrentStartLoop = 0; track.CurrentEndLoop = 0; track.RawLoopStart = 0; track.RawLoopEnd = track.Length; // DebugHelper.WriteLine("Loading raw loop track " + track.Description); AudioStreamHelper.AddToMixer(track, _rawLoopMixer); RawLoopTrack = track; SetRawLoopPositions(0, track.Length, 0); return(RawLoopTrack); }
/// <summary> /// Sets the raw loop positions. /// </summary> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="offset">The offset.</param> public void SetRawLoopPositions(long start, long end, long offset) { if (RawLoopTrack == null) { return; } if (start < 0 || end > RawLoopTrack.Length) { return; } if (end <= 0 || end <= start) { return; } var maxEnd = RawLoopTrack.Length - 500; if (end > maxEnd) { end = maxEnd; } if (offset < start || offset > end) { offset = start; } var track = RawLoopTrack; track.RawLoopStart = start; track.RawLoopEnd = end; track.RawLoopOffset = offset; AudioStreamHelper.SetPosition(track, track.RawLoopOffset); ClearTrackSyncPositions(track); // set track syncs SetTrackSync(track, track.Length, SyncType.TrackEnd); SetTrackSync(track, track.RawLoopEnd, SyncType.EndRawLoop); }