-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMBQuickPlayOverlayDll.cs
More file actions
187 lines (160 loc) · 7.19 KB
/
MBQuickPlayOverlayDll.cs
File metadata and controls
187 lines (160 loc) · 7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Interop;
using MusicBeePlugin.Views;
using MusicBeePlugin.ViewModels;
using System.Linq;
using System.Collections.ObjectModel;
using MusicBeePlugin.Models;
namespace MusicBeePlugin
{
public partial class Plugin
{
private MusicBeeApiInterface mbApiInterface;
private PluginInfo about = new PluginInfo();
private SearchWindowViewModel swViewModel = new SearchWindowViewModel();
public PluginInfo Initialise(IntPtr apiInterfacePtr)
{
mbApiInterface = new MusicBeeApiInterface();
mbApiInterface.Initialise(apiInterfacePtr);
about.PluginInfoVersion = PluginInfoVersion;
about.Name = "QuickPlay Overlay";
about.Description = "Bind to a global hotkey to quickly search for and play tracks in your NowPlayingList without having to open the MusicBee UI.";
about.Author = "Mikkel Jarlund";
about.TargetApplication = ""; // current only applies to artwork, lyrics or instant messenger name that appears in the provider drop down selector or target Instant Messenger
about.Type = PluginType.General;
about.VersionMajor = 1; // your plugin version
about.VersionMinor = 1;
about.Revision = 1;
about.MinInterfaceVersion = MinInterfaceVersion;
about.MinApiRevision = MinApiRevision;
about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
about.ConfigurationPanelHeight = 0; // height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function
createMenuItem();
return about;
}
private void InitialisePlugin()
{
swViewModel.NowPlayingList = GetNowPlayingList();
swViewModel.PlaySelectedSong = new RelayCommand(x =>
{
PlayNow(swViewModel.SelectedSong);
}, x => swViewModel.SelectedSong != null);
}
private void createMenuItem()
{
mbApiInterface.MB_AddMenuItem("mnuTools/QuickPlay Overlay", "QuickPlay Overlay", openSearchWindow);
}
private void openSearchWindow(object sender, EventArgs args)
{
SearchWindow window = new SearchWindow();
window.DataContext = swViewModel;
WindowInteropHelper helper = new WindowInteropHelper(window);
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();
window.Activate();
window.PreviewKeyUp += windowPreviewKeyUp;
window.Deactivated += windowDeactivated;
window.Closing += windowClosing;
}
private void windowPreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
switch (e.Key)
{
case System.Windows.Input.Key.Escape:
case System.Windows.Input.Key.Enter:
(sender as SearchWindow).Close();
break;
}
}
private void windowDeactivated(object sender, EventArgs e)
{
(sender as SearchWindow).Close();
}
private void windowClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
var window = sender as SearchWindow;
window.Deactivated -= windowDeactivated;
window.PreviewKeyUp -= windowPreviewKeyUp;
}
public bool Configure(IntPtr panelHandle)
{
// save any persistent settings in a sub-folder of this path
string dataPath = mbApiInterface.Setting_GetPersistentStoragePath();
// panelHandle will only be set if you set about.ConfigurationPanelHeight to a non-zero value
// keep in mind the panel width is scaled according to the font the user has selected
// if about.ConfigurationPanelHeight is set to 0, you can display your own popup window
if (panelHandle != IntPtr.Zero)
{
Panel configPanel = (Panel)Panel.FromHandle(panelHandle);
Label prompt = new Label();
prompt.AutoSize = true;
prompt.Location = new Point(0, 0);
prompt.Text = "prompt:";
TextBox textBox = new TextBox();
textBox.Bounds = new Rectangle(60, 0, 100, textBox.Height);
configPanel.Controls.AddRange(new Control[] { prompt, textBox });
}
return false;
}
// called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen.
// its up to you to figure out whether anything has changed and needs updating
public void SaveSettings()
{
}
// MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
public void Close(PluginCloseReason reason)
{
}
// uninstall this plugin - clean up any persisted files
public void Uninstall()
{
}
// receive event notifications from MusicBee
// you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
public void ReceiveNotification(string sourceFileUrl, NotificationType type)
{
// perform some action depending on the notification type
switch (type)
{
case NotificationType.PluginStartup:
// perform startup initialisation
InitialisePlugin();
break;
case NotificationType.NowPlayingListChanged:
case NotificationType.FileDeleted:
case NotificationType.RatingChanged:
case NotificationType.TagsChanged:
swViewModel.NowPlayingList = GetNowPlayingList();
break;
}
}
private ObservableCollection<Song> GetNowPlayingList()
{
ObservableCollection<Song> instance = new ObservableCollection<Song>();
string[] fileUrls = new string[0];
mbApiInterface.NowPlayingList_QueryFilesEx(null, ref fileUrls);
foreach (var url in fileUrls)
{
Song song = new Song
{
Url = url
};
song.Name =
mbApiInterface.Library_GetFileTag(url, MetaDataType.TrackTitle) +
" - " +
mbApiInterface.Library_GetFileTag(url, MetaDataType.AlbumArtist) +
(mbApiInterface.Library_GetFileTag(url, MetaDataType.RatingLove) == "L" ? " ♥" : "");
instance.Add(song);
}
return new ObservableCollection<Song>(instance.OrderBy(x => x.Name));
}
private void PlayNow(Song target)
{
NowPlayingList_FileActionDelegate FileAction = mbApiInterface.NowPlayingList_PlayNow;
FileAction(target.Url);
}
}
}