Skip to content

Commit

Permalink
Refactor playlist editor
Browse files Browse the repository at this point in the history
Reduce playlist editor's dependency on other modules
  • Loading branch information
MSDN-WhiteKnight committed Feb 18, 2023
1 parent 353fe97 commit e21fb5f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 83 deletions.
35 changes: 0 additions & 35 deletions SmallMediaPlayer/PictureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,6 @@ return TRUE;

}

void GetFileDirectory(wchar_t* path,wchar_t* out){
int i=0;
int k=0;
int LastIndex=0;
TCHAR buf[MAX_PATH];
StringCchCopy(buf,MAX_PATH,path);
while(1){
if(buf[i]==L'\\')LastIndex=i;
if(buf[i]==0)break;
i++;
}
lstrcpy(out,L"");
buf[LastIndex+1]=0;
lstrcat(out,buf);

}

void GetFileDirectoryA(char* path,char* out){
int i=0;
int k=0;
int LastIndex=0;
char buf[MAX_PATH];
lstrcpyA(buf,path);
while(1){
if(buf[i]=='\\')LastIndex=i;
if(buf[i]==0)break;
i++;
}
lstrcpyA(out,"");
buf[LastIndex+1]=0;
lstrcatA(out,buf);

}


void LoadCover(WCHAR* file){

UnloadCover();
Expand Down
1 change: 1 addition & 0 deletions SmallMediaPlayer/PictureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Strsafe.h>
#include <GdiPlus.h>
#include <shlobj.h>
#include "common.h"
using namespace Gdiplus;

//this module!!!
Expand Down
35 changes: 23 additions & 12 deletions SmallMediaPlayer/PlayListEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ HWND hlstBuffer=NULL;
UINT CountTracks=0;
UINT CurrentTrack=0;
bool fIncludeImages=false;
TCHAR* Extensions[COUNT_EXTENSIONS];
PLAYBACK_MODE CurrMode=NORMAL;
TAGS_GENERIC CurrFileTags={0};
bool fCurrFileTags=false;
Expand All @@ -28,9 +27,16 @@ HIMAGELIST ImageList=NULL;
bool Playlist_SortReverse=false;
SMP_ACTION Playlist_MsgLoopAction=NULL;
SMP_ACTION Playlist_NewTrackAction=NULL;
SMP_ACTION Playlist_EndAction=NULL;

TCHAR* ImageExtensions[]={
L"jpg", L"jpeg",L"bmp",L"png",L"gif"};
WCHAR* Extensions[COUNT_EXTENSIONS]={
L"mp3", L"aac", L"m4a", L"ogg", L"wma", L"ape", L"flac", L"wav", L"wv", L"mid", L"midi", L"cda",
L"avi", L"mpeg", L"mpg", L"mkv", L"mov", L"wmv"
};

WCHAR* ImageExtensions[]={
L"jpg", L"jpeg", L"bmp", L"png", L"gif"
};

TYPE_ICON_INFO arrTypeIcons[COUNT_TYPE_ICONS]={
{L"mp3",0,0},{L"flac",0,0},{L"wv",0,0},{L"wma"},
Expand All @@ -51,6 +57,7 @@ TCHAR* ImageExtensions[]={
switch(evt){
case SMP_EVENT_MSGLOOP: Playlist_MsgLoopAction = callback; break;
case SMP_EVENT_NEWTRACK: Playlist_NewTrackAction = callback; break;
case SMP_EVENT_PLAYLIST_END: Playlist_EndAction = callback; break;
}
}

Expand All @@ -61,6 +68,7 @@ TCHAR* ImageExtensions[]={
switch(evt){
case SMP_EVENT_MSGLOOP: callback = Playlist_MsgLoopAction; break;
case SMP_EVENT_NEWTRACK: callback = Playlist_NewTrackAction; break;
case SMP_EVENT_PLAYLIST_END: callback = Playlist_EndAction; break;
}

if(callback!=NULL) callback();
Expand Down Expand Up @@ -360,8 +368,6 @@ if(((UINT)n)>=CountTracks)return;
//***
SetCurrentTrackIndicator(TRUE);
//***

Progress.SetTrackPosition(0);
}

void PlayNextTrack(){
Expand All @@ -383,14 +389,19 @@ case RANDOM:CurrentTrack=rand()%CountTracks;break;
}


if(CurrentTrack>=CountTracks){

if(CurrentTrack>=CountTracks){ //end of playlist
CurrentTrack=0;
if(CurrMode==REPEAT_LIST){PlayTrackByNumber(CurrentTrack);}
else {StopTimer();
DisableFullScreen();
}
return;}

if(CurrMode==REPEAT_LIST){
PlayTrackByNumber(CurrentTrack);
}
else {
Playlist_OnEvent(SMP_EVENT_PLAYLIST_END);
DisableFullScreen();
}

return;
}

//scroll playlist
ListView_GetItemRect(PlayList,0,&rc,LVIR_SELECTBOUNDS);
Expand Down
28 changes: 1 addition & 27 deletions SmallMediaPlayer/PlayListEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,15 @@
#include <stdlib.h>
#include <stdio.h>
#include "player.h"
#include "ScrollbarControl.h"
#include <commctrl.h>
#define STRSAFE_NO_DEPRECATE
#include <Strsafe.h>
#include "tags.h"
#include "common.h"

#define COUNT_EXTENSIONS 18
#define COUNT_IMAGE_EXTENSIONS (sizeof(ImageExtensions)/sizeof(ImageExtensions[0]))

typedef struct {
BYTE type;
char sig[6];
}VORBIS_PACKET_HEADER;

typedef struct {
ULONG ver;
BYTE chans;
ULONG sample_rate;
long bitrate_max;
long bitrate;
long bitrate_min;
BYTE blocksize;
BYTE end;
}VORBIS_ID;

typedef struct{
TCHAR ext[10];
int iIcon;
Expand All @@ -40,18 +24,10 @@ typedef struct{

#define COUNT_TYPE_ICONS 16

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

//EXTERN VARS
extern ScrollbarControl Progress;

//THIS MODULE DECL.
extern HWND PlayList;
extern UINT CountTracks;
extern UINT CurrentTrack;
extern TCHAR* Extensions[COUNT_EXTENSIONS];
extern PLAYBACK_MODE CurrMode;
extern bool fIncludeImages;
extern HICON hDirIcon;
Expand Down Expand Up @@ -80,8 +56,6 @@ void LoadTextPlaylistA(char* file);
void SaveTextPlaylist(TCHAR* file);
void ReadPlaylistTags(char* str);
int FindTrack(TCHAR* fname);
BOOL ReadApeTags(TCHAR* file,TAGS_GENERIC* out);
BOOL ReadApeTagsA(char* file,TAGS_GENERIC* out);
void InsertPlaylistElement(WCHAR* fname,UINT pos);
void Playlist_Paste();void Playlist_Cut();void Playlist_Copy();
void Playlist_SelectAll();
Expand Down
20 changes: 19 additions & 1 deletion SmallMediaPlayer/common.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Small Media Player
* Copyright (c) 2022, 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 "common.h"
#include <stdint.h>
Expand All @@ -10,6 +10,24 @@ typedef struct LANGANDCODEPAGE {
WORD wCodePage;
} STRUCT_LANGANDCODEPAGE;

void GetFileDirectory(wchar_t* path,wchar_t* out){
int i=0;
int k=0;
int LastIndex=0;
TCHAR buf[MAX_PATH];
StringCchCopy(buf,MAX_PATH,path);

while(1){
if(buf[i]==L'\\') LastIndex=i;
if(buf[i]==0) break;
i++;
}

lstrcpy(out,L"");
buf[LastIndex+1]=0;
lstrcat(out,buf);
}

BOOL SMP_GetModuleFromObject(IUnknown* pObject, WCHAR* output, DWORD cchOutput){
HMODULE hModule = NULL;
WCHAR module[MAX_PATH]={0};
Expand Down
4 changes: 3 additions & 1 deletion SmallMediaPlayer/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef enum {
} PLAYER_EVENT;

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

typedef void (*PLAYER_EVENT_CALLBACK)(PLAYER_EVENT evt);
Expand Down Expand Up @@ -188,6 +188,8 @@ BOOL SMP_GetFileVersionInfo(const WCHAR* file, WCHAR* output, int cchOutput);
//Shows version info for a module where the implementation of the specified COM object is located
BOOL SMP_ShowObjectInfo(IUnknown* pObject, const WCHAR* strType, const WCHAR* strTitle);

void GetFileDirectory(wchar_t* path,wchar_t* out);

BOOL inline IsCursorShown(){
CURSORINFO ci={0};
ci.cbSize=sizeof(CURSORINFO);
Expand Down
9 changes: 2 additions & 7 deletions SmallMediaPlayer/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ void UpdateLength(){
InvalidateRect(hMainWnd,&rcInfoBox,TRUE);

RunTimer();
Progress.SetTrackPosition(0);
}

void UpdatePosition(){
Expand Down Expand Up @@ -1611,17 +1612,11 @@ CheckMenuRadioItem(GetMenu(hMainWnd),ID_MODE_NORMAL,ID_MODE_RANDOM,ID_MODE_NORMA

CountTracks=0;
PlayerState=FILE_NOT_LOADED;
Extensions[0]=TEXT("mp3");Extensions[1]=TEXT("mid");Extensions[2]=TEXT("wav");
Extensions[3]=TEXT("midi");Extensions[4]=TEXT("avi");Extensions[5]=TEXT("mpeg");
Extensions[6]=TEXT("wma");Extensions[7]=TEXT("wmv");Extensions[8]=TEXT("mpg");
Extensions[9]=TEXT("ogg");Extensions[10]=TEXT("cda");Extensions[11]=TEXT("aac");
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);

Playlist_SetEventCallback(SMP_EVENT_PLAYLIST_END, StopTimer);
}

//Initializes player state based on command line and settings
Expand Down

0 comments on commit e21fb5f

Please sign in to comment.