summaryrefslogtreecommitdiffstats
path: root/Src/nu/MediaLibraryInterface.cpp
blob: 2c84baca397516777815043768d43f0153ee0783 (plain) (blame)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#include "MediaLibraryInterface.h"
#include <commctrl.h>
#include "../nu/ns_wc.h"
#include "../winamp/wa_ipc.h"
#include "../Agave/Language/api_language.h"
#define _ML_HEADER_IMPMLEMENT
#include "..\Plugins\General\gen_ml/ml_ipc_0313.h"
#undef _ML_HEADER_IMPMLEMENT
#include "..\Plugins\General\gen_ml/ml_imageloader.h"
#include <shlwapi.h>
#include <strsafe.h>
MediaLibraryInterface mediaLibrary;

void MediaLibraryInterface::AddTreeItem(MLTREEITEM &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_ADD);
}

void MediaLibraryInterface::AddTreeItem(MLTREEITEMW &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_ADDW);
}

int MediaLibraryInterface::AddTreeImage(int resourceId)
{
	return AddTreeImage(resourceId, -1, (BMPFILTERPROC)FILTER_DEFAULT1);
}

int MediaLibraryInterface::AddTreeImage(int resourceId, int imageIndex, BMPFILTERPROC filter)
{
	MLTREEIMAGE img = {instance, resourceId, imageIndex, filter, 0, 0};
	return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM) &img, ML_IPC_TREEIMAGE_ADD);
}

int MediaLibraryInterface::AddTreeImageBmp(int resourceId)
{
	HMLIMGLST       hmlilNavigation = MLNavCtrl_GetImageList(library);
	MLIMAGESOURCE   mlis            = {sizeof(MLIMAGESOURCE),0};

	MLIMAGELISTITEM item            = {0};
	item.cbSize                     = sizeof( MLIMAGELISTITEM );
	item.hmlil                      = hmlilNavigation;
	item.filterUID                  = MLIF_FILTER1_UID;
	item.pmlImgSource               = &mlis;

	mlis.hInst                      = instance;
	mlis.bpp                        = 24;
	mlis.lpszName                   = MAKEINTRESOURCEW(resourceId);
	mlis.type                       = SRC_TYPE_BMP;
	mlis.flags                      = ISF_FORCE_BPP;

	return MLImageList_Add(library, &item);
}

void MediaLibraryInterface::SetTreeItem(MLTREEITEM &item)
{
	MLTREEITEMINFO ii = {0};
	ii.item           = item;
	ii.mask           = MLTI_IMAGE | MLTI_CHILDREN | MLTI_TEXT | MLTI_ID;

	SendMessage(library, WM_ML_IPC, (WPARAM) &ii, ML_IPC_TREEITEM_SETINFO);
}

void MediaLibraryInterface::SetTreeItem(MLTREEITEMW &item)
{
	MLTREEITEMINFOW ii = {0};
	ii.item            = item;
	ii.mask            = MLTI_IMAGE | MLTI_CHILDREN | MLTI_TEXT | MLTI_ID;

	SendMessage(library, WM_ML_IPC, (WPARAM) &ii, ML_IPC_TREEITEM_SETINFOW);
}

void MediaLibraryInterface::InsertTreeItem(MLTREEITEM &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_INSERT);
}

void MediaLibraryInterface::InsertTreeItem(MLTREEITEMW &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_INSERTW);
}

void MediaLibraryInterface::RemoveTreeItem(INT_PTR treeId)
{
	SendMessage(library, WM_ML_IPC, (WPARAM)treeId, ML_IPC_DELTREEITEM);
}

void MediaLibraryInterface::SelectTreeItem(INT_PTR treeId)
{
	SendMessage(library, WM_ML_IPC, (WPARAM)treeId, ML_IPC_SETCURTREEITEM);
}

INT_PTR MediaLibraryInterface::GetSelectedTreeItem(void)
{
	return (INT_PTR)SendMessage(library, WM_ML_IPC, 0, ML_IPC_GETCURTREEITEM);
}

void MediaLibraryInterface::UpdateTreeItem(MLTREEITEMINFO &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_SETINFO);
}

void MediaLibraryInterface::UpdateTreeItem(MLTREEITEMINFOW &newItem)
{
	SendMessage(library, WM_ML_IPC, (WPARAM) &newItem, ML_IPC_TREEITEM_SETINFOW);
}

int MediaLibraryInterface::SkinList(HWND list)
{
	return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM)list, ML_IPC_SKIN_LISTVIEW);
}

void MediaLibraryInterface::UnskinList(int token)
{
	SendMessage(library, WM_ML_IPC, (WPARAM)token, ML_IPC_UNSKIN_LISTVIEW);
}

void MediaLibraryInterface::ListViewShowSort(int token, BOOL show)
{
	LV_SKIN_SHOWSORT lvs = {0};
	lvs.listView         = token;
	lvs.showSort         = show;

	SendMessage(library, WM_ML_IPC, (WPARAM)&lvs, ML_IPC_LISTVIEW_SHOWSORT);
}

void MediaLibraryInterface::ListViewSort(int token, int columnIndex, BOOL ascending)
{
	LV_SKIN_SORT lvs = {0};
	lvs.listView     = token;
	lvs.ascending    = ascending;
	lvs.columnIndex  = columnIndex;

	SendMessage(library, WM_ML_IPC, (WPARAM)&lvs, ML_IPC_LISTVIEW_SORT);
}

void MediaLibraryInterface::ListSkinUpdateView(int listSkin)
{
	SendMessage(library, WM_ML_IPC, listSkin, ML_IPC_LISTVIEW_UPDATE);
}

void *MediaLibraryInterface::GetWADLGFunc(int num)
{
	return (void *)SendMessage(library, WM_ML_IPC, (WPARAM)num, ML_IPC_SKIN_WADLG_GETFUNC);
}

void MediaLibraryInterface::PlayStream(wchar_t *url, bool force)
{
	wchar_t temp[ 2048 ] = { 0 };
	wchar_t *end = 0;
	StringCchCopyExW( temp, 2047, url, &end, 0, 0 );
	if ( end )
	{
		end[ 1 ] = 0; // double null terminate

		mlSendToWinampStruct send;
		send.type    = ML_TYPE_STREAMNAMESW;
		send.enqueue = force ? ( 0 | 2 ) : 0;
		send.data    = (void *)temp;

		SendMessage( library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP );
	}
}

void MediaLibraryInterface::PlayStreams(std::vector<const wchar_t*> &urls, bool force)
{
	size_t totalSize = 0;
	std::vector<const wchar_t*>::iterator itr;
	for (itr = urls.begin();itr != urls.end();itr++)
	{
		totalSize += lstrlenW(*itr) + 1;
	}
	totalSize++;
	wchar_t *sendTo = new wchar_t[totalSize];
	wchar_t *ptr = sendTo;
	for (itr = urls.begin();itr != urls.end();itr++)
	{
		//AutoChar narrow(*itr);
		StringCchCopyExW(ptr, totalSize, *itr, &ptr, &totalSize, 0);

		ptr++;
		if (totalSize)
			totalSize--;
		else
			break;
	}
	ptr[0] = 0;

	mlSendToWinampStruct send;
	send.type = ML_TYPE_STREAMNAMESW;
	send.enqueue = force?(0 | 2):0;
	send.data = sendTo;
	SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
	delete [] sendTo;
}

void MediaLibraryInterface::EnqueueStream(wchar_t *url, bool force)
{
	wchar_t temp[2048] = {0};
	wchar_t *end=0;
	StringCchCopyExW(temp, 2047, url, &end, 0, 0);
	if (end)
	{
		end[1]=0; // double null terminate

		mlSendToWinampStruct send;
		send.type    = ML_TYPE_STREAMNAMESW;
		send.enqueue = force?(1 | 2):1;
		send.data    = (void *)temp;

		SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
	}
}

int MediaLibraryInterface::SkinComboBox(HWND comboBox)
{
	return (int)(INT_PTR)SendMessage(library, WM_ML_IPC, (WPARAM)comboBox, ML_IPC_SKIN_COMBOBOX);
}

void MediaLibraryInterface::UnskinComboBox(int token)
{
	SendMessage(library, WM_ML_IPC, (WPARAM)token, ML_IPC_UNSKIN_COMBOBOX);
}

const char *MediaLibraryInterface::GetIniDirectory()
{
	if (!iniDirectory)
	{
		iniDirectory = (const char*)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIDIRECTORY);
		if (((unsigned int)(ULONG_PTR)iniDirectory) < 65536)
			iniDirectory=0;
	}
	return iniDirectory;
}

const wchar_t *MediaLibraryInterface::GetIniDirectoryW()
{
	if (!iniDirectoryW)
	{
		iniDirectoryW = (const wchar_t*)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIDIRECTORYW);
		if (((unsigned int)(ULONG_PTR)iniDirectoryW) < 65536)
			iniDirectoryW=0;
	}
	return iniDirectoryW;
}

void MediaLibraryInterface::BuildPath(const wchar_t *pathEnd, wchar_t *path, size_t numChars)
{
	PathCombineW(path, GetIniDirectoryW(), pathEnd);
}

void MediaLibraryInterface::AddToSendTo(char description[], INT_PTR context, INT_PTR unique)
{
	mlAddToSendToStruct s;
	s.context = context;
	s.desc    = description;
	s.user32  = unique;

	SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOSENDTO);
}

void MediaLibraryInterface::AddToSendTo(wchar_t description[], INT_PTR context, INT_PTR unique)
{
	mlAddToSendToStructW s;
	s.context = context;
	s.desc    = description;
	s.user32  = unique;

	SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOSENDTOW);
}

void MediaLibraryInterface::BranchSendTo(INT_PTR context)
{
	mlAddToSendToStructW s = {0};
	s.context = context;

	SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_BRANCHSENDTO);
}

void MediaLibraryInterface::AddToBranchSendTo(const wchar_t description[], INT_PTR context, INT_PTR unique)
{
	mlAddToSendToStructW s;
	s.context = context;
	s.desc    = const_cast<wchar_t *>(description);
	s.user32  = unique;

	SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_ADDTOBRANCH);
}

void MediaLibraryInterface::EndBranchSendTo(const wchar_t description[], INT_PTR context)
{
	mlAddToSendToStructW s = {0};
	s.context              = context;
	s.desc                 = const_cast<wchar_t *>(description);

	SendMessage(library, WM_ML_IPC, (WPARAM)&s, ML_IPC_BRANCHSENDTO);
}

void MediaLibraryInterface::PlayFile(const wchar_t *url)
{
	wchar_t temp[2048] = {0};
	wchar_t *end=0;
	StringCchCopyExW(temp, 2047, url, &end, 0, 0);
	if (end)
	{
		end[1]=0; // double null terminate

		mlSendToWinampStruct send;
		send.type    = ML_TYPE_FILENAMESW;
		send.enqueue = 0 | 2;
		send.data    = (void *)temp;

		SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
	}
}

void MediaLibraryInterface::EnqueueFile(const wchar_t *url)
{
	wchar_t temp[2048] = {0};
	wchar_t *end=0;
	StringCchCopyExW(temp, 2047, url, &end, 0, 0);
	if (end)
	{
		end[1]=0; // double null terminate

		mlSendToWinampStruct send;
		send.type    = ML_TYPE_FILENAMESW;
		send.enqueue = 1 | 2;
		send.data    = (void *)temp;

		SendMessage(library, WM_ML_IPC, (WPARAM)&send, ML_IPC_SENDTOWINAMP);
	}
}

void MediaLibraryInterface::BuildPluginPath(const TCHAR *filename, TCHAR *path, size_t pathSize)
{
	if (!pluginDirectory)
		pluginDirectory = (const char *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETPLUGINDIRECTORY);
#ifdef UNICODE
	StringCchPrintf(path, pathSize, L"%S\\%s", pluginDirectory, filename);
#else
	StringCchPrintf(path, pathSize, "%s\\%s", pluginDirectory, filename);
#endif
}

void MediaLibraryInterface::AddToMediaLibrary(const char *filename)
{
	LMDB_FILE_ADD_INFO fi = {const_cast<char *>(filename), -1, -1};
	SendMessage(library, WM_ML_IPC, (WPARAM)&fi, ML_IPC_DB_ADDORUPDATEFILE);
	PostMessage(library, WM_ML_IPC, 0, ML_IPC_DB_SYNCDB);
}

void MediaLibraryInterface::AddToMediaLibrary(const wchar_t *filename)
{
	LMDB_FILE_ADD_INFOW fi = {const_cast<wchar_t *>(filename), -1, -1};
	SendMessage(library, WM_ML_IPC, (WPARAM)&fi, ML_IPC_DB_ADDORUPDATEFILEW);
	PostMessage(library, WM_ML_IPC, 0, ML_IPC_DB_SYNCDB);
}

IDispatch *MediaLibraryInterface::GetDispatchObject()
{
	IDispatch *dispatch = (IDispatch *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GET_DISPATCH_OBJECT);
	if (dispatch == (IDispatch *)1)
		return 0;
	else
		return dispatch;
}

int MediaLibraryInterface::GetUniqueDispatchId()
{
	return (int)(INT_PTR)SendMessage(winamp, WM_WA_IPC, 0, IPC_GET_UNIQUE_DISPATCH_ID);
}

void MediaLibraryInterface::ListSkinDisableHorizontalScrollbar(int listSkin)
{
	SendMessage(library, WM_ML_IPC, listSkin, ML_IPC_LISTVIEW_DISABLEHSCROLL);
}

DWORD MediaLibraryInterface::AddDispatch(wchar_t *name, IDispatch *object)
{
	DispatchInfo dispatchInfo;
	dispatchInfo.name     = name;
	dispatchInfo.dispatch = object;

	if (SendMessage(winamp, WM_WA_IPC, (WPARAM)&dispatchInfo, IPC_ADD_DISPATCH_OBJECT) == 0)
		return dispatchInfo.id;
	else
		return 0;
}

void MediaLibraryInterface::GetFileInfo(const char *filename, char *title, int titleCch, int *length)
{
	basicFileInfoStruct infoStruct = {0};
	infoStruct.filename = filename;
	infoStruct.title    = title;
	infoStruct.titlelen = titleCch;

	SendMessage(winamp, WM_WA_IPC, (WPARAM)&infoStruct, IPC_GET_BASIC_FILE_INFO);

	*length = infoStruct.length;
}

void MediaLibraryInterface::GetFileInfo(const wchar_t *filename, wchar_t *title, int titleCch, int *p_length)
{
	if (filename)
	{
		basicFileInfoStructW infoStruct = {0};
		infoStruct.filename = filename;
		infoStruct.title    = title;
		infoStruct.titlelen = titleCch;

		SendMessage(winamp, WM_WA_IPC, (WPARAM)&infoStruct, IPC_GET_BASIC_FILE_INFOW);

		if ( p_length != NULL )
			*p_length = infoStruct.length;
	}
	else
	{
		title[0] = 0;
		*p_length  = -1;
	}
}

const char *MediaLibraryInterface::GetWinampIni()
{
	if (winampIni && *winampIni)
		return winampIni;

	winampIni = (const char *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIFILE);

	return winampIni;
}

const wchar_t *MediaLibraryInterface::GetWinampIniW()
{
	if (winampIniW && *winampIniW)
		return winampIniW;

	winampIniW = (const wchar_t *)SendMessage(winamp, WM_WA_IPC, 0, IPC_GETINIFILEW);

	return winampIniW;
}

INT_PTR MediaLibraryInterface::GetChildId(INT_PTR id)
{
	return SendMessage(library, WM_ML_IPC, id, ML_IPC_TREEITEM_GETCHILD_ID);
}

INT_PTR MediaLibraryInterface::GetNextId(INT_PTR id)
{
	return SendMessage(library, WM_ML_IPC, id, ML_IPC_TREEITEM_GETNEXT_ID);
}

void MediaLibraryInterface::RenameTreeId(INT_PTR treeId, const wchar_t *newName)
{
	MLTREEITEMINFOW info = {0};
	info.mask            = MLTI_TEXT;
	info.item.size       = sizeof(info.item);
	info.item.id         = treeId;
	info.item.title      = const_cast<wchar_t *>(newName);

	SendMessage(library, WM_ML_IPC, (WPARAM) &info, ML_IPC_TREEITEM_SETINFOW);
}