Skip to content

Commit

Permalink
Add playlist events
Browse files Browse the repository at this point in the history
Reduce playlist editor's dependency on UI by invoking external functions via even callbacks
  • Loading branch information
MSDN-WhiteKnight committed Feb 18, 2023
1 parent efe0d88 commit 353fe97
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
46 changes: 31 additions & 15 deletions SmallMediaPlayer/PlayListEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Small Media Player
* Copyright (c) 2021, MSDN.WhiteKnight (https://github.com/smallsoft-rus/media-player)
* Copyright (c) 2023, MSDN.WhiteKnight (https://github.com/smallsoft-rus/media-player)
* License: BSD 2.0 */

#include "PlayListEditor.h"
Expand All @@ -9,9 +9,6 @@
10.09.2017 - Выделение текущего элемента в списке воспроизведения '>'
*/

extern void ProcessMessages();
extern void GetFileDirectoryA(char* path,char* out);

HWND PlayList;
HWND hlstBuffer=NULL;
UINT CountTracks=0;
Expand All @@ -29,6 +26,8 @@ int indexDirIcon=0;
int indexMusicIcon=0;
HIMAGELIST ImageList=NULL;
bool Playlist_SortReverse=false;
SMP_ACTION Playlist_MsgLoopAction=NULL;
SMP_ACTION Playlist_NewTrackAction=NULL;

TCHAR* ImageExtensions[]={
L"jpg", L"jpeg",L"bmp",L"png",L"gif"};
Expand All @@ -48,6 +47,25 @@ TCHAR* ImageExtensions[]={
Playlist_SortReverse = sortReverse;
}

void Playlist_SetEventCallback(SMP_EVENT evt, SMP_ACTION callback){
switch(evt){
case SMP_EVENT_MSGLOOP: Playlist_MsgLoopAction = callback; break;
case SMP_EVENT_NEWTRACK: Playlist_NewTrackAction = callback; break;
}
}

void Playlist_OnEvent(SMP_EVENT evt){

SMP_ACTION callback = NULL;

switch(evt){
case SMP_EVENT_MSGLOOP: callback = Playlist_MsgLoopAction; break;
case SMP_EVENT_NEWTRACK: callback = Playlist_NewTrackAction; break;
}

if(callback!=NULL) callback();
}

BOOL GetPlaylistElement(int n,TCHAR* out){
BOOL res;
LVITEM item={0};
Expand Down Expand Up @@ -335,19 +353,15 @@ if(((UINT)n)>=CountTracks)return;
if(res==FALSE)res=ReadApeTags(str,&OpenedFileTags);
if(res==FALSE){ res=ReadTagsV1(str,&OpenedFileTags);}
if(res!=FALSE){fOpenedFileTags=true;} else {fOpenedFileTags=false;}


PlayFile(str);
UpdateLength();

//***
SetCurrentTrackIndicator(TRUE);
//***
PlayFile(str);
Playlist_OnEvent(SMP_EVENT_NEWTRACK);

RunTimer();
Progress.SetTrackPosition(0);
//***
SetCurrentTrackIndicator(TRUE);
//***

Progress.SetTrackPosition(0);
}

void PlayNextTrack(){
Expand All @@ -358,7 +372,9 @@ void PlayNextTrack(){
//***
SetCurrentTrackIndicator(FALSE);
//***
ProcessMessages();

//process pending messages in Windows message loop
Playlist_OnEvent(SMP_EVENT_MSGLOOP);

switch(CurrMode){
case NORMAL:case REPEAT_LIST:InterlockedIncrement((volatile LONG*)&CurrentTrack);break;
Expand Down
5 changes: 2 additions & 3 deletions SmallMediaPlayer/PlayListEditor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Small Media Player
* Copyright (c) 2021, MSDN.WhiteKnight (https://github.com/smallsoft-rus/media-player)
* Copyright (c) 2023, MSDN.WhiteKnight (https://github.com/smallsoft-rus/media-player)
* License: BSD 2.0 */
#ifndef PLAYLISTEDITOR_H
#define PLAYLISTEDITOR_H
Expand Down Expand Up @@ -41,8 +41,6 @@ typedef struct{
#define COUNT_TYPE_ICONS 16

//EXTERN FUNCTIONS
extern void UpdateLength();
extern void RunTimer();
extern void StopTimer();
extern void GetFileDirectory(wchar_t* path,wchar_t* out);

Expand Down Expand Up @@ -88,6 +86,7 @@ void InsertPlaylistElement(WCHAR* fname,UINT pos);
void Playlist_Paste();void Playlist_Cut();void Playlist_Copy();
void Playlist_SelectAll();
void Playlist_SetSortReverseFlag(bool sortReverse);
void Playlist_SetEventCallback(SMP_EVENT evt, SMP_ACTION callback);

void InitImageList();
int GetTypeIcon(TCHAR* ext);
Expand Down
7 changes: 7 additions & 0 deletions SmallMediaPlayer/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ typedef enum {
EVT_UNKNOWN=0,EVT_USERABORT,EVT_FILE_CLOSED,EVT_ERRORABORT,EVT_COMPLETE
} PLAYER_EVENT;

typedef enum {
SMP_EVENT_UNKNOWN=0, SMP_EVENT_MSGLOOP, SMP_EVENT_NEWTRACK
} SMP_EVENT;

typedef void (*PLAYER_EVENT_CALLBACK)(PLAYER_EVENT evt);

// Represents a callback without parameters
typedef void (*SMP_ACTION)();

typedef enum {
TN_UNKNOWN=0,
TN_SPLITTER,
Expand Down
10 changes: 7 additions & 3 deletions SmallMediaPlayer/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,12 @@ void UpdateLength(){
LoadCover(cover);
}

InvalidateRect(hCoverWnd,NULL,TRUE);
InvalidateRect(hCoverWnd,NULL,TRUE);

GetMultimediaInfo(txtMediaInfo,1000);
InvalidateRect(hMainWnd,&rcInfoBox,TRUE);

GetMultimediaInfo(txtMediaInfo,1000);
InvalidateRect(hMainWnd,&rcInfoBox,TRUE);
RunTimer();
}

void UpdatePosition(){
Expand Down Expand Up @@ -1617,6 +1619,8 @@ Extensions[12]=TEXT("mkv");Extensions[13]=TEXT("flac");Extensions[14]=TEXT("mov"
Extensions[15]=TEXT("wv");Extensions[16]=TEXT("ape");Extensions[17]=TEXT("m4a");

Player_InitWindows(hVideoWindow,hMainWnd);
Playlist_SetEventCallback(SMP_EVENT_MSGLOOP, ProcessMessages);
Playlist_SetEventCallback(SMP_EVENT_NEWTRACK, UpdateLength);

}

Expand Down

0 comments on commit 353fe97

Please sign in to comment.