1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "song_info.h"
24 #include "tag_editor.h"
27 #include "screen_switcher.h"
32 # include "boost/lexical_cast.hpp"
33 #endif // HAVE_TAGLIB_H
35 using Global::MainHeight
;
36 using Global::MainStartY
;
40 const SongInfo::Metadata
SongInfo::Tags
[] =
42 { "Title", &MPD::Song::getTitle
, &MPD::MutableSong::setTitle
},
43 { "Artist", &MPD::Song::getArtist
, &MPD::MutableSong::setArtist
},
44 { "Album Artist", &MPD::Song::getAlbumArtist
, &MPD::MutableSong::setAlbumArtist
},
45 { "Album", &MPD::Song::getAlbum
, &MPD::MutableSong::setAlbum
},
46 { "Date", &MPD::Song::getDate
, &MPD::MutableSong::setDate
},
47 { "Track", &MPD::Song::getTrack
, &MPD::MutableSong::setTrack
},
48 { "Genre", &MPD::Song::getGenre
, &MPD::MutableSong::setGenre
},
49 { "Composer", &MPD::Song::getComposer
, &MPD::MutableSong::setComposer
},
50 { "Performer", &MPD::Song::getPerformer
, &MPD::MutableSong::setPerformer
},
51 { "Disc", &MPD::Song::getDisc
, &MPD::MutableSong::setDisc
},
52 { "Comment", &MPD::Song::getComment
, &MPD::MutableSong::setComment
},
57 : Screen(NC::Scrollpad(0, MainStartY
, COLS
, MainHeight
, "", Config
.main_color
, NC::Border::None
))
60 void SongInfo::resize()
62 size_t x_offset
, width
;
63 getWindowResizeParams(x_offset
, width
);
64 w
.resize(width
, MainHeight
);
65 w
.moveTo(x_offset
, MainStartY
);
69 std::wstring
SongInfo::title()
74 void SongInfo::switchTo()
76 using Global::myScreen
;
79 auto s
= currentSong(myScreen
);
82 SwitchTo::execute(this);
87 // redraw header after we're done with the file, since reading it from disk
88 // takes a bit of time and having header updated before content of a window
89 // is displayed doesn't look nice.
93 switchToPreviousScreen();
96 void SongInfo::PrepareSong(MPD::Song
&s
)
98 w
<< NC::Format::Bold
<< Config
.color1
<< "Filename: " << NC::Format::NoBold
<< Config
.color2
<< s
.getName() << '\n' << NC::Color::End
;
99 w
<< NC::Format::Bold
<< "Directory: " << NC::Format::NoBold
<< Config
.color2
;
100 ShowTag(w
, s
.getDirectory());
101 w
<< "\n\n" << NC::Color::End
;
102 w
<< NC::Format::Bold
<< "Length: " << NC::Format::NoBold
<< Config
.color2
<< s
.getLength() << '\n' << NC::Color::End
;
103 # ifdef HAVE_TAGLIB_H
104 if (!Config
.mpd_music_dir
.empty() && !s
.isStream())
106 std::string path_to_file
;
107 if (s
.isFromDatabase())
108 path_to_file
+= Config
.mpd_music_dir
;
109 path_to_file
+= s
.getURI();
110 TagLib::FileRef
f(path_to_file
.c_str());
113 std::string channels
;
114 switch (f
.audioProperties()->channels())
123 channels
= boost::lexical_cast
<std::string
>(f
.audioProperties()->channels());
126 w
<< NC::Format::Bold
<< "Bitrate: " << NC::Format::NoBold
<< Config
.color2
<< f
.audioProperties()->bitrate() << " kbps\n" << NC::Color::End
;
127 w
<< NC::Format::Bold
<< "Sample rate: " << NC::Format::NoBold
<< Config
.color2
<< f
.audioProperties()->sampleRate() << " Hz\n" << NC::Color::End
;
128 w
<< NC::Format::Bold
<< "Channels: " << NC::Format::NoBold
<< Config
.color2
<< channels
<< NC::Color::End
<< "\n";
130 auto rginfo
= Tags::readReplayGain(f
.file());
133 w
<< NC::Format::Bold
<< "\nReference loudness: " << NC::Format::NoBold
<< Config
.color2
<< rginfo
.referenceLoudness() << NC::Color::End
<< "\n";
134 w
<< NC::Format::Bold
<< "Track gain: " << NC::Format::NoBold
<< Config
.color2
<< rginfo
.trackGain() << NC::Color::End
<< "\n";
135 w
<< NC::Format::Bold
<< "Track peak: " << NC::Format::NoBold
<< Config
.color2
<< rginfo
.trackPeak() << NC::Color::End
<< "\n";
136 w
<< NC::Format::Bold
<< "Album gain: " << NC::Format::NoBold
<< Config
.color2
<< rginfo
.albumGain() << NC::Color::End
<< "\n";
137 w
<< NC::Format::Bold
<< "Album peak: " << NC::Format::NoBold
<< Config
.color2
<< rginfo
.albumPeak() << NC::Color::End
<< "\n";
141 # endif // HAVE_TAGLIB_H
142 w
<< NC::Color::Default
;
144 for (const Metadata
*m
= Tags
; m
->Name
; ++m
)
146 w
<< NC::Format::Bold
<< '\n' << m
->Name
<< ": " << NC::Format::NoBold
;
147 ShowTag(w
, s
.getTags(m
->Get
, Config
.tags_separator
));