public static void Play(Playlists PlayItem) { if (Bass.BASS_GetInfo() == null) { Bass.BASS_Init(-1, hz, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); } Bass.BASS_StreamFree(_stream); Bass.BASS_ChannelStop(_stream); _stream = Bass.BASS_StreamCreateFile(PlayItem.Path, 0, 0, BASSFlag.BASS_DEFAULT); now = PlayList.IndexOf(PlayItem); Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, slrVolume / 100f); EqualizerSettings.SetFX(_stream); ggg.Dispatcher.Invoke(() => { ggg.lblAudioName.Content = PlayItem.Name; ggg.SyncSlider(); ggg.lblMusicDuration.Content = new TimeSpan(0, 0, (int)Bass.BASS_ChannelBytes2Seconds(BassMet._stream, Bass.BASS_ChannelGetLength(BassMet._stream))); ggg.btnResumePause.Content = "Pause"; }); Bass.BASS_ChannelPlay(_stream, true); timer.Start(); }
public Equalizer() { InitializeComponent(); Slider[] sliders = { slrFX0, slrFX1, slrFX2, slrFX3, slrFX4, slrFX5, slrFX6, slrFX7, slrFX8, slrFX9 }; Label[] labels = { lblFX0, lblFX1, lblFX2, lblFX3, lblFX4, lblFX5, lblFX6, lblFX7, lblFX8, lblFX9 }; IniReader IR = new IniReader(EqualizerSettings.SettingsPath); IniWriter IW = new IniWriter(EqualizerSettings.SettingsPath); cmbEqualizerProfile.ItemsSource = PresetCollection; foreach (var i in IR.GetParams().Skip(1)) { PresetCollection.Add(i); } cmbEqualizerProfile.SelectedItem = IR.GetValuebyParam("Current"); for (int i = 0; i < sliders.Length; i++) { sliders[i].Value = EqualizerSettings.FXGain[i]; labels[i].Content = EqualizerSettings.FXGain[i]; } cmbEqualizerProfile.SelectionChanged += (e, a) => { EqualizerSettings.LoadPreset(cmbEqualizerProfile.SelectedItem.ToString()); IW.WriteParam("Current", cmbEqualizerProfile.SelectedItem.ToString()); for (int i = 0; i < sliders.Length; i++) { sliders[i].Value = EqualizerSettings.FXGain[i]; labels[i].Content = EqualizerSettings.FXGain[i]; } }; btnEqualizerProfileAdd.Click += (e, a) => { if (txtbNewProfileName.Text.Replace(" ", "") != "" && IR.GetParams().Skip(1).Any(x => x != txtbNewProfileName.Text)) { IW.WriteParam(txtbNewProfileName.Text, EqualizerSettings.FXGain.Select(x => x.ToString()).ToArray()); PresetCollection.Add(txtbNewProfileName.Text); cmbEqualizerProfile.SelectedItem = txtbNewProfileName.Text; } txtbNewProfileName.Text = ""; }; btnEqualizerProfileDlt.Click += (e, a) => { if (cmbEqualizerProfile.Text != "Standart") { string s = cmbEqualizerProfile.Text; cmbEqualizerProfile.SelectedItem = "Standart"; PresetCollection.Remove(s); IW.DeleteParam(s); } }; this.Closed += (e, a) => { EqualizerSettings.LoadPreset(IR.GetValuebyParam("Current")); }; btnEqualizerSave.Click += (e, a) => { if (cmbEqualizerProfile.Text != "Standart") { IW.WriteParam(cmbEqualizerProfile.SelectedItem.ToString(), EqualizerSettings.FXGain.Select(x => x.ToString()).ToArray()); } }; slrFX0.MouseRightButtonDown += (s, e) => { slrFX0.Value = 0; lblFX0.Content = 0; EqualizerSettings.FXGain[0] = 0f; EqualizerSettings.ChangeFXParam(0); }; slrFX1.MouseRightButtonDown += (s, e) => { slrFX1.Value = 0; lblFX1.Content = 0; EqualizerSettings.FXGain[1] = 0f; EqualizerSettings.ChangeFXParam(1); }; slrFX2.MouseRightButtonDown += (s, e) => { slrFX2.Value = 0; lblFX2.Content = 0; EqualizerSettings.FXGain[2] = 0f; EqualizerSettings.ChangeFXParam(2); }; slrFX3.MouseRightButtonDown += (s, e) => { slrFX3.Value = 0; lblFX3.Content = 0; EqualizerSettings.FXGain[3] = 0f; EqualizerSettings.ChangeFXParam(3); }; slrFX4.MouseRightButtonDown += (s, e) => { slrFX4.Value = 0; lblFX4.Content = 0; EqualizerSettings.FXGain[4] = 0f; EqualizerSettings.ChangeFXParam(4); }; slrFX5.MouseRightButtonDown += (s, e) => { slrFX5.Value = 0; lblFX5.Content = 0; EqualizerSettings.FXGain[5] = 0f; EqualizerSettings.ChangeFXParam(5); }; slrFX6.MouseRightButtonDown += (s, e) => { slrFX6.Value = 0; lblFX6.Content = 0; EqualizerSettings.FXGain[6] = 0f; EqualizerSettings.ChangeFXParam(6); }; slrFX7.MouseRightButtonDown += (s, e) => { slrFX7.Value = 0; lblFX7.Content = 0; EqualizerSettings.FXGain[7] = 0f; EqualizerSettings.ChangeFXParam(7); }; slrFX8.MouseRightButtonDown += (s, e) => { slrFX8.Value = 0; lblFX8.Content = 0; EqualizerSettings.FXGain[8] = 0f; EqualizerSettings.ChangeFXParam(8); }; slrFX9.MouseRightButtonDown += (s, e) => { slrFX9.Value = 0; lblFX9.Content = 0; EqualizerSettings.FXGain[9] = 0f; EqualizerSettings.ChangeFXParam(9); }; slrFX0.ValueChanged += (s, e) => { EqualizerSettings.FXGain[0] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(0); lblFX0.Content = Math.Round(e.NewValue, 1); }; slrFX1.ValueChanged += (s, e) => { EqualizerSettings.FXGain[1] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(1); lblFX1.Content = Math.Round(e.NewValue, 1); }; slrFX2.ValueChanged += (s, e) => { EqualizerSettings.FXGain[2] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(2); lblFX2.Content = Math.Round(e.NewValue, 1); }; slrFX3.ValueChanged += (s, e) => { EqualizerSettings.FXGain[3] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(3); lblFX3.Content = Math.Round(e.NewValue, 1); }; slrFX4.ValueChanged += (s, e) => { EqualizerSettings.FXGain[4] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(4); lblFX4.Content = Math.Round(e.NewValue, 1); }; slrFX5.ValueChanged += (s, e) => { EqualizerSettings.FXGain[5] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(5); lblFX5.Content = Math.Round(e.NewValue, 1); }; slrFX6.ValueChanged += (s, e) => { EqualizerSettings.FXGain[6] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(6); lblFX6.Content = Math.Round(e.NewValue, 1); }; slrFX7.ValueChanged += (s, e) => { EqualizerSettings.FXGain[7] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(7); lblFX7.Content = Math.Round(e.NewValue, 1); }; slrFX8.ValueChanged += (s, e) => { EqualizerSettings.FXGain[8] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(8); lblFX8.Content = Math.Round(e.NewValue, 1); }; slrFX9.ValueChanged += (s, e) => { EqualizerSettings.FXGain[9] = (float)Math.Round(e.NewValue, 1); EqualizerSettings.ChangeFXParam(9); lblFX9.Content = Math.Round(e.NewValue, 1); }; }
public MainWindow() { InitializeComponent(); lvPlaylist.ItemsSource = BassMet.PlayList; Dispatcher.InvokeAsync(() => { Timer timer = new Timer(new TimerCallback(CollectGarbage), null, 0, 5000); }); Dispatcher.InvokeAsync(() => { if (File.Exists(EqualizerSettings.SettingsPath)) { try { IniReader IR = new IniReader(EqualizerSettings.SettingsPath); if (IR.GetValuebyParam(IR.GetValuebyParam("Current"), true) == null) { IniWriter IW = new IniWriter(EqualizerSettings.SettingsPath); IW.WriteParam("Current", "Standart"); IW.WriteParam("Standart", EqualizerSettings.FXGain.Select(x => x.ToString()).ToArray()); } else { EqualizerSettings.LoadPreset(IR.GetValuebyParam("Current")); } } catch { IniWriter IW = new IniWriter(EqualizerSettings.SettingsPath); IW.WriteParam("Current", "Standart"); IW.WriteParam("Standart", EqualizerSettings.FXGain.Select(x => x.ToString()).ToArray()); } } else { IniWriter IW = new IniWriter(EqualizerSettings.SettingsPath); IW.WriteParam("Current", "Standart"); IW.WriteParam("Standart", EqualizerSettings.FXGain.Select(x => x.ToString()).ToArray()); } }); #region Global Hooks IKeyboardMouseEvents KeyHook = Hook.GlobalEvents(); KeyHook.KeyDown += (s, e) => { switch (e.KeyCode) { case WindowsHook.Keys.MediaNextTrack: BassMet.PlayNext(); break; case WindowsHook.Keys.MediaPlayPause: if (Bass.BASS_ChannelIsActive(BassMet._stream) == BASSActive.BASS_ACTIVE_PAUSED) { BassMet.Resume(); } else { BassMet.Pause(); } break; case WindowsHook.Keys.MediaPreviousTrack: BassMet.PlayPrev(); break; case WindowsHook.Keys.MediaStop: BassMet.Stop(); break; } }; #endregion BassMet.ggg = this; var addons = Bass.BASS_PluginLoadDirectory(Environment.CurrentDirectory); #region Buttons logic btnShaffle.Click += (e, a) => { int j = 0; for (int i = BassMet.PlayList.Count - 1; i >= 1; i--) { j = random.Next(i); var buf = BassMet.PlayList[j]; BassMet.PlayList[j] = BassMet.PlayList[i]; BassMet.PlayList[i] = buf; if (BassMet.now == i) { BassMet.now = j; } if (BassMet.now == j) { BassMet.now = i; } } //UpdateList(); }; btnStop.Click += (e, a) => { BassMet.Stop(); }; btnResumePause.Click += (e, a) => { if (Bass.BASS_ChannelIsActive(BassMet._stream) == BASSActive.BASS_ACTIVE_PAUSED) { BassMet.Resume(); btnResumePause.Content = "Pause"; } else { BassMet.Pause(); btnResumePause.Content = "Resume"; } }; btnNext.Click += (e, a) => { if (BassMet.PlayList.Count > 0) { BassMet.PlayNext(); } }; btnPrev.Click += (e, a) => { if (BassMet.PlayList.Count > 0) { BassMet.PlayPrev(); } }; btnLoop.Click += (e, a) => { btnLoop.BorderBrush = btnLoop.BorderBrush == Brushes.Red ? Brushes.Blue : Brushes.Red; }; btnMute.Click += (e, a) => { if (slrPlayVolume.Value != 0) { MusicVolumeBuffer = slrPlayVolume.Value; slrPlayVolume.Value = 0; } else { slrPlayVolume.Value = MusicVolumeBuffer; } }; /*btnCloseApp.Click += (e, a) => * { * Application.Current.Shutdown(); * }; * * btnCollapseApp.Click += (e, a) => * { * this.WindowState = WindowState.Minimized; * }; * * btnOpenFullApp.Click += (e, a) => * { * if (this.WindowState == WindowState.Maximized) * this.WindowState = WindowState.Normal; * else * this.WindowState = WindowState.Maximized; * };*/ #endregion #region ListViews logic lvContextUpper.Click += (e, a) => { if (BassMet.PlayList.Count > 1) { List <Playlists> abc = new List <Playlists>(); for (int i = 0; i < lvPlaylist.SelectedItems.Count; i++) { abc.Add((Playlists)lvPlaylist.SelectedItems[i]); //lvPlaylistDoUpper(BassMet.PlayList.IndexOf(BassMet.PlayList.Where(x => x == lvPlaylist.SelectedItems[0]).First())); } for (int i = 0; i < BassMet.PlayList.Count; i++) { foreach (var j in abc) { if (BassMet.PlayList[i] == j) { lvPlaylistDoUpper(i); } } } } //UpdateList(); }; lvContextLower.Click += (e, a) => { if (BassMet.PlayList.Count > 1) { List <Playlists> abc = new List <Playlists>(); for (int i = 0; i < lvPlaylist.SelectedItems.Count; i++) { abc.Add((Playlists)lvPlaylist.SelectedItems[i]); //lvPlaylistDoUpper(BassMet.PlayList.IndexOf(BassMet.PlayList.Where(x => x == lvPlaylist.SelectedItems[0]).First())); } for (int i = 0; i < BassMet.PlayList.Count; i++) { foreach (var j in abc) { if (BassMet.PlayList[i] == j) { lvPlaylistDoLower(i); } } } //lvPlaylistDoLower(lvPlaylist.SelectedIndex); } //UpdateList(); }; lvContextDelete.Click += (e, a) => { try { List <Playlists> abc = new List <Playlists>(); for (int i = 0; i < lvPlaylist.SelectedItems.Count; i++) { abc.Add((Playlists)lvPlaylist.SelectedItems[i]); //lvPlaylistDoUpper(BassMet.PlayList.IndexOf(BassMet.PlayList.Where(x => x == lvPlaylist.SelectedItems[0]).First())); } for (int i = 0; i < BassMet.PlayList.Count; i++) { foreach (var j in abc) { if (BassMet.PlayList[i] == j) { BassMet.PlayList.RemoveAt(i); } } } //BassMet.PlayList.RemoveAt(lvPlaylist.SelectedIndex); UpdateList(); } catch { } }; lvPlaylist.MouseDoubleClick += (e, a) => { if (BassMet.PlayList.Count == 0) { return; } BassMet.Play(BassMet.PlayList[lvPlaylist.SelectedIndex]); }; lvPlaylist.DragEnter += (e, a) => { if (a.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) { a.Effects = System.Windows.DragDropEffects.Copy; } }; lvPlaylist.Drop += (e, a) => { if (a.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) { foreach (string obj in (string[])a.Data.GetData(System.Windows.DataFormats.FileDrop)) { if (Directory.Exists(obj)) { foreach (var file in Directory.GetFiles(obj)) { if (Utils.BASSAddOnIsFileSupported(addons, file)) { BassMet.PlayList.Add(new Playlists { Name = file.Substring(file.LastIndexOfAny(new char[] { '\\', '/' }) + 1), Path = file }); } else { System.Windows.MessageBox.Show("Не удалось загрузить файл '" + file + "'"); } } } else { if (Utils.BASSAddOnIsFileSupported(addons, obj)) { BassMet.PlayList.Add(new Playlists { Name = obj.Substring(obj.LastIndexOfAny(new char[] { '\\', '/' }) + 1), Path = obj }); } else { System.Windows.MessageBox.Show("Не удалось загрузить файл '" + obj + "'"); } } } UpdateList(); } }; #endregion #region Context Main Menu logic MainMenuPLOpen.Click += (e, a) => { ReadPlaylistDialog RPD = new ReadPlaylistDialog(); RPD.ShowInTaskbar = false; RPD.ShowDialog(); UpdateList(); }; MainMenuPLSave.Click += (e, a) => { SavePlaylistDialog SPD = new SavePlaylistDialog(); SPD.ShowInTaskbar = false; SPD.ShowDialog(); }; MainMenuEcvalaizer.Click += (e, a) => { Equalizer ES = new Equalizer(); ES.ShowDialog(); }; /*MainMenuSettings.Click += (e, a) => * { * ApplicationSettings AS = new ApplicationSettings(); * AS.Show(); * };*/ #endregion #region Sliders logic BassMet.slrVolume = (float)slrPlayVolume.Value; slrPlayDuration.ValueChanged += (e, a) => { if (Mouse.LeftButton == MouseButtonState.Pressed && slrPlayDuration.IsMouseOver) { Dispatcher.Invoke(() => Bass.BASS_ChannelSetPosition(BassMet._stream, a.NewValue)); } lblDurationNow.Content = new TimeSpan(0, 0, (int)BassMet.GetAudioPosition()); }; slrPlayVolume.ValueChanged += (e, a) => { BassMet.slrVolume = (float)a.NewValue; Bass.BASS_ChannelSetAttribute(BassMet._stream, BASSAttribute.BASS_ATTRIB_VOL, (float)a.NewValue / 100f); }; #endregion BassMet.timer.Tick += (e, a) => { if (Bass.BASS_ChannelIsActive(BassMet._stream) == BASSActive.BASS_ACTIVE_STOPPED) { Brush b = Brushes.Blue; Dispatcher.Invoke(() => { b = btnLoop.BorderBrush; }); if (b == Brushes.Blue) { BassMet.Replay(); } else { BassMet.PlayNext(); } } if (Bass.BASS_ChannelIsActive(BassMet._stream) == BASSActive.BASS_ACTIVE_PLAYING) { Dispatcher.Invoke(() => { slrPlayDuration.Value = BassMet.GetAudioPosition(); lblMusicDuration.Content = new TimeSpan(0, 0, (int)Bass.BASS_ChannelBytes2Seconds(BassMet._stream, Bass.BASS_ChannelGetLength(BassMet._stream))); }); } }; }