private void InitBass() { BassHelper.InitializeBass(); // Ask for device to use List <Tuple <string, int> > bassDevices = BassHelper.GetBassDevices(); int?selectedIndex = null; do { Console.Clear(); Console.WriteLine("Select device:"); for (int i = 0; i < bassDevices.Count && i < 10; i++) { Console.WriteLine($" {i}. {bassDevices[i].Item1}"); } char input = Console.ReadKey().KeyChar; int tmp; if (int.TryParse(input.ToString(), out tmp) && tmp < bassDevices.Count) { selectedIndex = tmp; } } while (!selectedIndex.HasValue); Console.WriteLine(); _soundDataProcessor = new SoundDataProcessor(bassDevices[selectedIndex.Value].Item2) { VolumeScalar = VOLUME_SCALAR }; }
public void Dispose() { Stop(); CloseFile(); if (BassHelper.IsInitialized) { BassHelper.Free(); } }
private void InitialiseSampleMixer() { // create mixer channel _sampleMixerChannel = BassHelper.IntialiseMixerChannel(); // add to list of active mixers _activeMixers.Add(_sampleMixerChannel, _sampleMixerChannel); Bass.BASS_ChannelSetSync(_sampleMixerChannel, BASSSync.BASS_SYNC_STALL, 0L, _mixerStall, IntPtr.Zero); Bass.BASS_ChannelPlay(_sampleMixerChannel, false); }
private Track GetClosestTrack(Track currentTrack, Direction direction) { if (currentTrack == null) { return(null); } var track = this.Library.GetTracks().OrderBy(t => BassHelper.AbsoluteBPMPercentChange(currentTrack.EndBPM, t.StartBPM)).FirstOrDefault(); if (track != null) { return(track); } throw new NotImplementedException(); }
private void Init() { if (!BassHelper.IsInitialized) { try { //BassHelper.Registration("xxx", "xxx");// register BassHelper.Initialize(); //Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM, (int)(_volume * 10000)); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Current.Shutdown(); } } }
public void AddTrack(string filename) { if (!File.Exists(filename)) { return; } if (Path.GetExtension(filename).ToLower() == "m3u") { foreach (var file in BassHelper.GetFilesInPlaylist(filename)) { AddTrack(file); } } else if (Path.GetExtension(filename).ToLower() == "mp3") { AddTrack(_bassPlayer.LoadTrack(filename)); } }
private Track GetRandomWorkingTrack() { var excludeTracks = new List <Track>(); excludeTracks.Add(this.CurrentTrack); excludeTracks.AddRange(_history); var preferredTracks = this.MixLibrary.GetPreferredTracks(this.CurrentTrack); var forbiddenTracks = this.MixLibrary.GetForbiddenTracks(this.CurrentTrack); excludeTracks.AddRange(forbiddenTracks); excludeTracks.AddRange(preferredTracks); Track randomTrack = null; if (this.WorkingTrack != null && this.CurrentTrack != this.WorkingTrack && this.CurrentTrack != null) { randomTrack = this.WorkingTrack; } else if (this.WorkingTrack != null) { var currentTrack = this.CurrentTrack; if (currentTrack == null) { currentTrack = this.WorkingTrack; } randomTrack = BassHelper.GetTracksInBPMRange(currentTrack.EndBPM, 5M, this.Library.GetTracks()) .Union(BassHelper.GetTracksInEndBPMRange(currentTrack.StartBPM, 5M, this.Library.GetTracks())) .Distinct() .Except(excludeTracks) .OrderBy(t => BassHelper.AbsoluteBPMPercentChange(currentTrack.EndBPM, t.StartBPM)) .FirstOrDefault(); } if (randomTrack == null) { randomTrack = this.WorkingTrack; } return(randomTrack); }
/// <summary> /// Gets all preferred tracks for the specified track /// </summary> /// <param name="track">The track.</param> /// <returns>A list of tracks in the library the specified track should prefer to mix with</returns> public List <Track> GetMixableTracks(Track track, int mixLevel) { var tracks = new List <Track>(); if (track == null) { return(tracks); } if (mixLevel == 1) { var excludeTracks = new List <Track>(); excludeTracks.Add(track); excludeTracks.AddRange(GetMixableTracks(track, 0)); excludeTracks.AddRange(GetMixableTracks(track, 2)); excludeTracks.AddRange(GetMixableTracks(track, 3)); excludeTracks.AddRange(GetMixableTracks(track, 4)); excludeTracks.AddRange(GetMixableTracks(track, 5)); var tracksInRange = BassHelper.GetTracksInBPMRange(track.EndBPM, 5M, _library.GetTracks()); return(tracksInRange .Distinct() .Except(excludeTracks) .ToList()); } else { foreach (var toTrack in GetMixTracks(track).GetToTracks(mixLevel)) { var mixableTrack = _library.GetTracks() .Where(t => t.Description == toTrack.TrackDescription) .FirstOrDefault(); if (mixableTrack != null) { tracks.Add(mixableTrack); } } } return(tracks); }
/// <summary> /// Loads the sample audio data. /// </summary> /// <param name="sample">The sample to load.</param> /// <returns>The loaded sample</returns> private Sample LoadSampleAudioData(Sample sample) { // abort if audio data already loaded if (sample.Channel != int.MinValue) { return(sample); } Debug.Print("Loading sample Audio Data " + sample.Description); sample.AudioData = File.ReadAllBytes(sample.Filename); sample.AudioDataHandle = GCHandle.Alloc(sample.AudioData, GCHandleType.Pinned); sample.Channel = Bass.BASS_StreamCreateFile(sample.AudioDataPointer, 0, sample.AudioData.Length, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); if (sample.Channel == 0) { var errorCode = Bass.BASS_ErrorGetCode(); throw new Exception("Cannot load sample " + sample.Filename + ". Error code: " + errorCode.ToString()); } sample.Channel = BassFx.BASS_FX_ReverseCreate(sample.Channel, 1, BASSFlag.BASS_STREAM_DECODE); if (sample.Channel == 0) { throw new Exception("Cannot load sample " + sample.Filename); } Bass.BASS_ChannelSetAttribute(sample.Channel, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_FORWARD); sample.Channel = BassFx.BASS_FX_TempoCreate(sample.Channel, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE); if (sample.Channel == 0) { throw new Exception("Cannot load sample " + sample.Filename); } sample.Length = Bass.BASS_ChannelGetLength(sample.Channel); sample.DefaultSampleRate = BassHelper.GetSampleRate(sample.Channel); return(sample); }
/// <summary> /// Gets the mix level for mixing track 1 into track 1 /// </summary> /// <param name="track1">The track 1.</param> /// <param name="track2">The track 2.</param> /// <returns>A mix level from 0 to 5</returns> public int GetMixLevel(Track track1, Track track2) { if (track1 == null || track2 == null) { return(0); } var mixTracks = GetMixTracks(track1); var mixTrack = mixTracks.GetToTracks() .Where(mt => mt.TrackDescription == track2.Description) .FirstOrDefault(); if (mixTrack != null) { return(mixTrack.MixLevel); } if (BassHelper.AbsoluteBPMPercentChange(track1.EndBPM, track2.StartBPM) > 5M) { return(0); } return(1); }
public void Save(string filename) { BassHelper.SaveAsPlaylist(filename, this.GetTracks()); }