handle single command and remove hacks used as substitute for it

mpd-git has single command, which provides functionality
of both "repeat one" and "stop after current track" modes.

repeat one = single && repeat
stop after current track = single && !repeat
This commit is contained in:
Andrzej Rybczak
2009-03-27 16:40:55 +01:00
parent 88c37b581d
commit 5f41640cd9
12 changed files with 67 additions and 69 deletions

View File

@@ -124,8 +124,6 @@
#
#autocenter_mode = "no"
#
#repeat_one_mode = "no"
#
#default_place_to_search_in = "database" (database/playlist)
#
#media_library_left_column = "a" (possible values: a,y,g,c,p, legend above)

View File

@@ -70,10 +70,10 @@
#
#key_toggle_repeat = 'r'
#
#key_toggle_repeat_one = 'R'
#
#key_toggle_random = 'z'
#
#key_toggle_single = 'y'
#
#key_shuffle = 'Z'
#
#key_toggle_crossfade = 'x'
@@ -136,8 +136,6 @@
#
#key_go_to_containing_directory = 'G'
#
#key_start_searching = 'y'
#
#key_go_to_parent_dir = 263 127
#
#key_switch_tag_type_list = '`'

View File

@@ -144,9 +144,6 @@ If enabled, statusbar will be displayed, otherwise hidden.
.B autocenter_mode = yes/no
Default state for autocenter mode at start.
.TP
.B repeat_one_mode = yes/no
Default state for "repeat one" mode at start.
.TP
.B default_find_mode = wrapped/normal
If set to "wrapped", going from last found position to next will take you to the first one (same goes for the first position and going to previous one), otherwise no actions will be performed.
.TP

View File

@@ -161,8 +161,8 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.AddSelected) << "Add selected items to playlist/m3u file\n\n";
*w << DisplayKeys(Key.ToggleRepeat) << "Toggle repeat mode\n";
*w << DisplayKeys(Key.ToggleRepeatOne) << "Toggle \"repeat one\" mode\n";
*w << DisplayKeys(Key.ToggleRandom) << "Toggle random mode\n";
*w << DisplayKeys(Key.ToggleSingle) << "Toggle single mode\n";
*w << DisplayKeys(Key.Shuffle) << "Shuffle playlist\n";
*w << DisplayKeys(Key.ToggleCrossfade) << "Toggle crossfade mode\n";
*w << DisplayKeys(Key.SetCrossfade) << "Set crossfade\n";
@@ -202,7 +202,6 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.SavePlaylist) << "Save playlist\n";
*w << DisplayKeys(Key.SortPlaylist) << "Sort/reverse playlist\n";
*w << DisplayKeys(Key.GoToNowPlaying) << "Go to currently playing position\n";
*w << DisplayKeys(Key.StartSearching) << "Toggle \"stop playing after current song\" option\n";
*w << DisplayKeys(Key.ToggleAutoCenter) << "Toggle auto center mode\n\n\n";
*w << " " << fmtBold << "Keys - Browse screen\n -----------------------------------------\n" << fmtBoldEnd;
@@ -218,7 +217,7 @@ void Help::GetKeybindings()
*w << " " << fmtBold << "Keys - Search engine\n -----------------------------------------\n" << fmtBoldEnd;
*w << DisplayKeys(Key.Enter) << "Add item to playlist and play/change option\n";
*w << DisplayKeys(Key.Space) << "Add item to playlist\n";
*w << DisplayKeys(Key.StartSearching) << "Start searching immediately\n\n\n";
*w << DisplayKeys(Key.ToggleSingle) << "Start searching immediately\n\n\n";
*w << " " << fmtBold << "Keys - Media library\n -----------------------------------------\n" << fmtBoldEnd;

View File

@@ -739,6 +739,7 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) {
status->volume = -1;
status->repeat = 0;
status->random = 0;
status->single = 0;
status->playlist = -1;
status->playlistLength = -1;
status->state = -1;
@@ -769,6 +770,9 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) {
else if(strcmp(re->name,"random")==0) {
status->random = atoi(re->value);
}
else if(strcmp(re->name,"single")==0) {
status->single = atoi(re->value);
}
else if(strcmp(re->name,"playlist")==0) {
status->playlist = strtol(re->value,NULL,10);
}
@@ -1692,6 +1696,14 @@ void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode) {
free(string);
}
void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode) {
int len = strlen("single")+2+INTLEN+3;
char *string = malloc(len);
snprintf(string, len, "single \"%i\"\n", singleMode);
mpd_executeCommand(connection,string);
free(string);
}
void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) {
int len = strlen("setvol")+2+INTLEN+3;
char *string = malloc(len);

View File

@@ -173,6 +173,8 @@ typedef struct mpd_Status {
int repeat;
/* 1 if random is on, 0 otherwise */
int random;
/* 1 if single mode is on, 0 otherwise */
int single;
/* playlist length */
int playlistLength;
/* playlist, use this to determine when the playlist has changed */
@@ -520,6 +522,8 @@ void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode);
void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
/* WARNING: don't use volume command, its depreacted */

View File

@@ -164,6 +164,7 @@ void Connection::UpdateStatus()
itsChanges.Crossfade = 1;
itsChanges.Random = 1;
itsChanges.Repeat = 1;
itsChanges.Single = 1;
itsChanges.PlayerState = 1;
itsChanges.StatusFlags = 1;
}
@@ -178,8 +179,9 @@ void Connection::UpdateStatus()
itsChanges.Crossfade = itsOldStatus->crossfade != itsCurrentStatus->crossfade;
itsChanges.Random = itsOldStatus->random != itsCurrentStatus->random;
itsChanges.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
itsChanges.Single = itsOldStatus->single != itsCurrentStatus->single;
itsChanges.PlayerState = itsOldStatus->state != itsCurrentStatus->state;
itsChanges.StatusFlags = itsChanges.Repeat || itsChanges.Random || itsChanges.Crossfade || itsChanges.DBUpdating;
itsChanges.StatusFlags = itsChanges.Repeat || itsChanges.Random || itsChanges.Single || itsChanges.Crossfade || itsChanges.DBUpdating;
}
itsUpdater(this, itsChanges, itsErrorHandlerUserdata);
}
@@ -482,6 +484,16 @@ void Connection::SetRandom(bool mode) const
}
}
void Connection::SetSingle(bool mode) const
{
if (isConnected)
{
mpd_sendSingleCommand(itsConnection, mode);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
void Connection::SetVolume(int vol)
{
if (isConnected)

View File

@@ -48,7 +48,7 @@ namespace MPD
struct StatusChanges
{
StatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0), StatusFlags(0) { }
StatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), Single(0), PlayerState(0), StatusFlags(0) { }
bool Playlist:1;
bool SongID:1;
bool Database:1;
@@ -58,6 +58,7 @@ namespace MPD
bool Crossfade:1;
bool Random:1;
bool Repeat:1;
bool Single:1;
bool PlayerState:1;
bool StatusFlags:1;
};
@@ -116,6 +117,7 @@ namespace MPD
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; }
bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; }
bool GetSingle() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->single : 0; }
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; }
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; }
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; }
@@ -137,6 +139,7 @@ namespace MPD
void SetRepeat(bool) const;
void SetRandom(bool) const;
void SetSingle(bool) const;
void SetCrossfade(int) const;
void SetVolume(int);

View File

@@ -1080,11 +1080,6 @@ int main(int argc, char *argv[])
Mpd->SetRepeat(!Mpd->GetRepeat());
Mpd->UpdateStatus();
}
else if (Keypressed(input, Key.ToggleRepeatOne))
{
Config.repeat_one_mode = !Config.repeat_one_mode;
ShowMessage("'Repeat one' mode: %s", Config.repeat_one_mode ? "On" : "Off");
}
else if (Keypressed(input, Key.Shuffle))
{
Mpd->Shuffle();
@@ -1095,6 +1090,22 @@ int main(int argc, char *argv[])
Mpd->SetRandom(!Mpd->GetRandom());
Mpd->UpdateStatus();
}
else if (Keypressed(input, Key.ToggleSingle))
{
if (myScreen == mySearcher && !mySearcher->Main()->isStatic(0))
{
mySearcher->Main()->Highlight(SearchEngine::SearchButton);
mySearcher->Main()->Highlighting(0);
mySearcher->Main()->Refresh();
mySearcher->Main()->Highlighting(1);
mySearcher->EnterPressed();
}
else
{
Mpd->SetSingle(!Mpd->GetSingle());
Mpd->UpdateStatus();
}
}
else if (Keypressed(input, Key.ToggleCrossfade))
{
Mpd->SetCrossfade(Mpd->GetCrossfade() ? 0 : Config.crossfade_time);
@@ -1276,22 +1287,6 @@ int main(int argc, char *argv[])
if (s)
myBrowser->LocateSong(*s);
}
else if (Keypressed(input, Key.StartSearching))
{
if (myScreen == myPlaylist && myPlaylist->isPlaying())
{
Config.stop_after_current_song = !Config.stop_after_current_song;
ShowMessage("Stop playing after current song: %s", Config.stop_after_current_song ? "on" : "off");
}
else if (myScreen == mySearcher && !mySearcher->Main()->isStatic(0))
{
mySearcher->Main()->Highlight(SearchEngine::SearchButton);
mySearcher->Main()->Highlighting(0);
mySearcher->Main()->Refresh();
mySearcher->Main()->Highlighting(1);
mySearcher->EnterPressed();
}
}
else if (Keypressed(input, Key.GoToPosition))
{
const Song *s = myPlaylist->NowPlayingSong();

View File

@@ -117,8 +117,8 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.SeekForward[0] = 'f';
keys.SeekBackward[0] = 'b';
keys.ToggleRepeat[0] = 'r';
keys.ToggleRepeatOne[0] = 'R';
keys.ToggleRandom[0] = 'z';
keys.ToggleSingle[0] = 'y';
keys.ToggleSpaceMode[0] = 't';
keys.ToggleAddMode[0] = 'T';
keys.Shuffle[0] = 'Z';
@@ -149,7 +149,6 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.SavePlaylist[0] = 'S';
keys.GoToNowPlaying[0] = 'o';
keys.GoToContainingDir[0] = 'G';
keys.StartSearching[0] = 'y';
keys.ToggleAutoCenter[0] = 'U';
keys.ToggleDisplayMode[0] = 'p';
keys.ToggleLyricsDB[0] = 'L';
@@ -184,8 +183,8 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.SeekForward[1] = null_key;
keys.SeekBackward[1] = null_key;
keys.ToggleRepeat[1] = null_key;
keys.ToggleRepeatOne[1] = null_key;
keys.ToggleRandom[1] = null_key;
keys.ToggleSingle[1] = null_key;
keys.ToggleSpaceMode[1] = null_key;
keys.ToggleAddMode[1] = null_key;
keys.Shuffle[1] = null_key;
@@ -216,7 +215,6 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.SavePlaylist[1] = null_key;
keys.GoToNowPlaying[1] = null_key;
keys.GoToContainingDir[1] = null_key;
keys.StartSearching[1] = null_key;
keys.ToggleAutoCenter[1] = null_key;
keys.ToggleDisplayMode[1] = null_key;
keys.ToggleLyricsDB[1] = null_key;
@@ -263,7 +261,6 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.header_visibility = true;
conf.statusbar_visibility = true;
conf.autocenter_mode = false;
conf.repeat_one_mode = false;
conf.wrapped_search = true;
conf.space_selects = false;
conf.ncmpc_like_songs_adding = false;
@@ -275,7 +272,6 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.display_screens_numbers_on_start = true;
conf.clock_display_seconds = false;
conf.ignore_leading_the = false;
conf.stop_after_current_song = false;
conf.block_search_constraints_change = true;
conf.use_console_editor = false;
conf.set_window_title = true;
@@ -356,10 +352,10 @@ void ReadKeys(ncmpcpp_keys &keys)
GetKeys(key, keys.SeekBackward);
else if (key.find("key_toggle_repeat ") != string::npos)
GetKeys(key, keys.ToggleRepeat);
else if (key.find("key_toggle_repeat_one ") != string::npos)
GetKeys(key, keys.ToggleRepeatOne);
else if (key.find("key_toggle_random ") != string::npos)
GetKeys(key, keys.ToggleRandom);
else if (key.find("key_toggle_single ") != string::npos)
GetKeys(key, keys.ToggleSingle);
else if (key.find("key_toggle_space_mode ") != string::npos)
GetKeys(key, keys.ToggleSpaceMode);
else if (key.find("key_toggle_add_mode ") != string::npos)
@@ -426,8 +422,6 @@ void ReadKeys(ncmpcpp_keys &keys)
GetKeys(key, keys.ToggleLyricsDB);
else if (key.find("key_go_to_containing_directory ") != string::npos)
GetKeys(key, keys.GoToContainingDir);
else if (key.find("key_start_searching ") != string::npos)
GetKeys(key, keys.StartSearching);
else if (key.find("key_go_to_parent_dir ") != string::npos)
GetKeys(key, keys.GoToParentDir);
else if (key.find("key_switch_tag_type_list ") != string::npos)
@@ -608,10 +602,6 @@ void ReadConfiguration(ncmpcpp_config &conf)
{
conf.autocenter_mode = v == "yes";
}
else if (cl.find("repeat_one_mode") != string::npos)
{
conf.repeat_one_mode = v == "yes";
}
else if (cl.find("default_find_mode") != string::npos)
{
conf.wrapped_search = v == "wrapped";

View File

@@ -64,8 +64,8 @@ struct ncmpcpp_keys
int SeekForward[2];
int SeekBackward[2];
int ToggleRepeat[2];
int ToggleRepeatOne[2];
int ToggleRandom[2];
int ToggleSingle[2];
int ToggleSpaceMode[2];
int ToggleAddMode[2];
int Shuffle[2];
@@ -96,7 +96,6 @@ struct ncmpcpp_keys
int SavePlaylist[2];
int GoToNowPlaying[2];
int GoToContainingDir[2];
int StartSearching[2];
int ToggleAutoCenter[2];
int ToggleDisplayMode[2];
int ToggleLyricsDB[2];
@@ -153,7 +152,6 @@ struct ncmpcpp_config
bool header_visibility;
bool statusbar_visibility;
bool autocenter_mode;
bool repeat_one_mode;
bool wrapped_search;
bool space_selects;
bool ncmpc_like_songs_adding;
@@ -165,7 +163,6 @@ struct ncmpcpp_config
bool display_screens_numbers_on_start;
bool clock_display_seconds;
bool ignore_leading_the;
bool stop_after_current_song;
bool block_search_constraints_change;
bool use_console_editor;

View File

@@ -175,7 +175,6 @@ void NcmpcppErrorCallback(Connection *Mpd, int errorid, const char *msg, void *)
void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{
static size_t playing_song_scroll_begin = 0;
static bool repeat_one_allowed = 0;
static string player_state;
static MPD::Song np;
@@ -324,7 +323,6 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
wFooter->SetColor(Config.statusbar_color);
Playlist::ReloadRemaining = 1;
myPlaylist->NowPlaying = -1;
Config.stop_after_current_song = 0;
player_state.clear();
break;
}
@@ -342,30 +340,21 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{
if (myPlaylist->isPlaying())
{
if (Config.repeat_one_mode && repeat_one_allowed)
Mpd->Play(myPlaylist->OldPlaying);
np = Mpd->GetCurrentSong();
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
if (Config.autocenter_mode && !myPlaylist->Main()->isFiltered())
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
repeat_one_allowed = 0;
if (!Mpd->GetElapsedTime())
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
if (Config.now_playing_lyrics && !Config.repeat_one_mode && myScreen == myLyrics && myOldScreen == myPlaylist)
if (Config.now_playing_lyrics && !Mpd->GetSingle() && myScreen == myLyrics && myOldScreen == myPlaylist)
Lyrics::Reload = 1;
}
Playlist::ReloadRemaining = 1;
playing_song_scroll_begin = 0;
if (Config.stop_after_current_song)
{
Mpd->Stop();
Config.stop_after_current_song = 0;
}
if (Mpd->GetState() == psPlay)
{
changed.ElapsedTime = 1;
@@ -377,10 +366,6 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{
int elapsed = Mpd->GetElapsedTime();
// 'repeat one' mode check - be sure that we deal with item with known length
if (np.GetTotalLength() && elapsed == np.GetTotalLength()-1)
repeat_one_allowed = 1;
if (!block_statusbar_update && Config.statusbar_visibility)
{
string tracklength;
@@ -427,6 +412,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
static char mpd_repeat;
static char mpd_random;
static char mpd_single;
static char mpd_crossfade;
static char mpd_db_updating;
@@ -440,6 +426,11 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
mpd_random = Mpd->GetRandom() ? 'z' : 0;
ShowMessage("Random is %s", !mpd_random ? "off" : "on");
}
if (changed.Single)
{
mpd_single = Mpd->GetSingle() ? 's' : 0;
ShowMessage("Single is %s", !mpd_single ? "off" : "on");
}
if (changed.Crossfade)
{
int crossfade = Mpd->GetCrossfade();
@@ -460,6 +451,8 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
switch_state += mpd_repeat;
if (mpd_random)
switch_state += mpd_random;
if (mpd_single)
switch_state += mpd_single;
if (mpd_crossfade)
switch_state += mpd_crossfade;
if (mpd_db_updating)