diff --git a/src/contrib/cddadecoder/CddaDataStream.h b/src/contrib/cddadecoder/CddaDataStream.h index 4d04656dc..75fad63da 100755 --- a/src/contrib/cddadecoder/CddaDataStream.h +++ b/src/contrib/cddadecoder/CddaDataStream.h @@ -43,10 +43,10 @@ class CddaDataStream : public IDataStream { public: CddaDataStream(); virtual ~CddaDataStream(); + virtual void Destroy(); virtual bool Open(const char *filename, unsigned int options = 0); virtual bool Close(); - virtual void Destroy(); virtual PositionType Read(void* buffer, PositionType readBytes); virtual bool SetPosition(PositionType position); virtual PositionType Position(); diff --git a/src/core/audio/Stream.cpp b/src/core/audio/Stream.cpp index c270cf1a9..fbca5abee 100644 --- a/src/core/audio/Stream.cpp +++ b/src/core/audio/Stream.cpp @@ -45,7 +45,7 @@ using musik::core::PluginFactory; static std::string TAG = "Stream"; Stream::Stream(unsigned int options) -: preferedBufferSampleSize(4096) +: preferedBufferSampleSize(2048) , options(options) , decoderSampleRate(0) , decoderSamplePosition(0) diff --git a/src/musikbox/app/layout/SearchLayout.cpp b/src/musikbox/app/layout/SearchLayout.cpp index cdacd7bab..a13538dba 100755 --- a/src/musikbox/app/layout/SearchLayout.cpp +++ b/src/musikbox/app/layout/SearchLayout.cpp @@ -49,6 +49,7 @@ using namespace musik::box; using namespace cursespp; #define SEARCH_HEIGHT 3 +#define LABEL_HEIGHT 1 SearchLayout::SearchLayout(PlaybackService& playback, LibraryPtr library) : LayoutBase() { @@ -75,13 +76,19 @@ void SearchLayout::Layout() { size_t inputX = x + ((cx - inputWidth) / 2); this->input->MoveAndResize(inputX, 0, cx / 2, SEARCH_HEIGHT); + size_t labelY = SEARCH_HEIGHT; size_t categoryWidth = cx / 3; - size_t categoryY = SEARCH_HEIGHT; + size_t categoryY = labelY + LABEL_HEIGHT; size_t categoryHeight = cy - SEARCH_HEIGHT; size_t lastCategoryWidth = cx - (categoryWidth * 2); + this->albumsLabel->MoveAndResize(0, labelY, categoryWidth, 1); this->albums->MoveAndResize(0, categoryY, categoryWidth, categoryHeight); + + this->artistsLabel->MoveAndResize(categoryWidth, labelY, categoryWidth, 1); this->artists->MoveAndResize(categoryWidth, categoryY, categoryWidth, categoryHeight); + + this->genresLabel->MoveAndResize(categoryWidth * 2, labelY, lastCategoryWidth, 1); this->genres->MoveAndResize(categoryWidth * 2, categoryY, lastCategoryWidth, categoryHeight); } @@ -90,6 +97,11 @@ void SearchLayout::Layout() { this->AddWindow(view); \ view->SetFocusOrder(order); +#define CREATE_LABEL(view, text) \ + view.reset(new cursespp::TextLabel()); \ + view->SetText(text, cursespp::TextLabel::AlignCenter); \ + this->AddWindow(view); + void SearchLayout::InitializeWindows(PlaybackService& playback) { this->input.reset(new cursespp::TextInput()); this->input->TextChanged.connect(this, &SearchLayout::OnInputChanged); @@ -101,6 +113,10 @@ void SearchLayout::InitializeWindows(PlaybackService& playback) { CREATE_CATEGORY(this->artists, constants::Track::ARTIST, 2); CREATE_CATEGORY(this->genres, constants::Track::GENRE, 3); + CREATE_LABEL(this->albumsLabel, "albums"); + CREATE_LABEL(this->artistsLabel, "artists"); + CREATE_LABEL(this->genresLabel, "genres"); + this->Layout(); } diff --git a/src/musikbox/app/layout/SearchLayout.h b/src/musikbox/app/layout/SearchLayout.h index 33498f0ac..299890fd2 100755 --- a/src/musikbox/app/layout/SearchLayout.h +++ b/src/musikbox/app/layout/SearchLayout.h @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -77,8 +78,11 @@ namespace musik { std::string value); musik::core::LibraryPtr library; - std::shared_ptr artists; + std::shared_ptr albumsLabel; std::shared_ptr albums; + std::shared_ptr artistsLabel; + std::shared_ptr artists; + std::shared_ptr genresLabel; std::shared_ptr genres; std::shared_ptr input; }; diff --git a/src/musikbox/app/util/Text.cpp b/src/musikbox/app/util/Duration.cpp similarity index 69% rename from src/musikbox/app/util/Text.cpp rename to src/musikbox/app/util/Duration.cpp index 658055cf7..f1b8de80c 100755 --- a/src/musikbox/app/util/Text.cpp +++ b/src/musikbox/app/util/Duration.cpp @@ -33,44 +33,12 @@ ////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" -#include "Text.h" - +#include "Duration.h" #include namespace musik { namespace box { - namespace text { - void Truncate(std::string& str, size_t len) { - /* not a simple substr anymore, gotta deal with multi-byte - characters... */ - if (u8len(str) > len) { - std::string::iterator it = str.begin(); - std::string::iterator end = str.end(); - - size_t c = 0; - while (c < len && it != str.end()) { - try { - utf8::next(it, end); - } - catch (...) { - /* invalid encoding, just treat as a single char */ - ++it; - } - - ++c; - } - - str = std::string(str.begin(), it); - } - } - - void Ellipsize(std::string& str, size_t len) { - if (u8len(str) > len) { - Truncate(str, len - 2); - str += ".."; - } - } - + namespace duration { std::string Duration(int seconds) { int mins = (seconds / 60); int secs = seconds - (mins * 60); diff --git a/src/musikbox/app/util/Duration.h b/src/musikbox/app/util/Duration.h new file mode 100755 index 000000000..30df47ece --- /dev/null +++ b/src/musikbox/app/util/Duration.h @@ -0,0 +1,47 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2016 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "stdafx.h" + +namespace musik { + namespace box { + namespace duration { + std::string Duration(std::string& str); + std::string Duration(int seconds); + std::string Duration(double seconds); + } + } +} diff --git a/src/musikbox/app/window/CategoryListView.cpp b/src/musikbox/app/window/CategoryListView.cpp index 2a75b97c9..367e61afd 100755 --- a/src/musikbox/app/window/CategoryListView.cpp +++ b/src/musikbox/app/window/CategoryListView.cpp @@ -38,10 +38,10 @@ #include #include #include +#include #include -#include #include #include "CategoryListView.h" @@ -51,7 +51,8 @@ using musik::core::audio::ITransport; using musik::core::IQuery; using namespace musik::core::library::constants; using namespace musik::box; -using cursespp::SingleLineEntry; + +using namespace cursespp; #define WINDOW_MESSAGE_QUERY_COMPLETED 1002 diff --git a/src/musikbox/app/window/EntryWithHeader.cpp b/src/musikbox/app/window/EntryWithHeader.cpp index 41b94c012..ce36d6d92 100755 --- a/src/musikbox/app/window/EntryWithHeader.cpp +++ b/src/musikbox/app/window/EntryWithHeader.cpp @@ -35,9 +35,10 @@ #include #include "EntryWithHeader.h" #include -#include +#include using namespace musik::box; +using namespace cursespp; EntryWithHeader::EntryWithHeader( const std::string& header, const std::string& value) @@ -70,7 +71,7 @@ size_t EntryWithHeader::GetLineCount() { std::string EntryWithHeader::GetLine(size_t line) { if (line == 0) { std::string ellipsized = this->header; - musik::box::text::Ellipsize(ellipsized, this->width); + text::Ellipsize(ellipsized, this->width); return ellipsized; } diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index 55e9e4932..fbf6057cf 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -37,13 +37,14 @@ #include #include #include +#include #include "TrackListView.h" #include -#include #include +#include #include #include @@ -195,7 +196,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { text::Ellipsize(artist, ARTIST_COL_WIDTH); text::Ellipsize(album, ALBUM_COL_WIDTH); text::Ellipsize(title, column1CharacterCount); - duration = text::Duration(duration); + duration = duration::Duration(duration); std::string text = boost::str( boost::format("%s %s %s %s %s") diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index 64be8ecc0..7adb7f263 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -201,8 +201,8 @@ void TransportWindow::Update() { int secondsCurrent = (int) round(transport.Position()); int secondsTotal = boost::lexical_cast(duration); - std::string currentTime = text::Duration(std::min(secondsCurrent, secondsTotal)); - std::string totalTime = text::Duration(secondsTotal); + std::string currentTime = duration::Duration(std::min(secondsCurrent, secondsTotal)); + std::string totalTime = duration::Duration(secondsTotal); size_t timerWidth = this->GetContentWidth() - diff --git a/src/musikbox/cursespp/Text.cpp b/src/musikbox/cursespp/Text.cpp new file mode 100755 index 000000000..2ce45d05a --- /dev/null +++ b/src/musikbox/cursespp/Text.cpp @@ -0,0 +1,73 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2016 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include "stdafx.h" +#include "Text.h" + +#include + +namespace cursespp { + namespace text { + void Truncate(std::string& str, size_t len) { + /* not a simple substr anymore, gotta deal with multi-byte + characters... */ + if (u8len(str) > len) { + std::string::iterator it = str.begin(); + std::string::iterator end = str.end(); + + size_t c = 0; + while (c < len && it != str.end()) { + try { + utf8::next(it, end); + } + catch (...) { + /* invalid encoding, just treat as a single char */ + ++it; + } + + ++c; + } + + str = std::string(str.begin(), it); + } + } + + void Ellipsize(std::string& str, size_t len) { + if (u8len(str) > len) { + Truncate(str, len - 2); + str += ".."; + } + } + } +} diff --git a/src/musikbox/app/util/Text.h b/src/musikbox/cursespp/Text.h similarity index 84% rename from src/musikbox/app/util/Text.h rename to src/musikbox/cursespp/Text.h index 151c0f3b2..4fe7f4d36 100755 --- a/src/musikbox/app/util/Text.h +++ b/src/musikbox/cursespp/Text.h @@ -36,14 +36,9 @@ #include "stdafx.h" -namespace musik { - namespace box { - namespace text { - void Truncate(std::string& str, size_t len); - void Ellipsize(std::string& str, size_t len); - std::string Duration(std::string& str); - std::string Duration(int seconds); - std::string Duration(double seconds); - } +namespace cursespp { + namespace text { + void Truncate(std::string& str, size_t len); + void Ellipsize(std::string& str, size_t len); } } diff --git a/src/musikbox/cursespp/TextLabel.cpp b/src/musikbox/cursespp/TextLabel.cpp new file mode 100755 index 000000000..ce537d90c --- /dev/null +++ b/src/musikbox/cursespp/TextLabel.cpp @@ -0,0 +1,104 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2016 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include + +#include "TextLabel.h" + +using namespace cursespp; + +inline static void redrawContents( + IWindow &window, + const TextLabel::Alignment alignment, + const std::string& text) +{ + WINDOW* c = window.GetContent(); + werase(c); + + int len = (int) u8len(text); + int cx = window.GetContentWidth(); + + if (len > cx) { + std::string ellipsized = text; + text::Ellipsize(ellipsized, cx); + wprintw(c, ellipsized.c_str()); + } + else if (alignment == TextLabel::AlignLeft) { + wprintw(c, text.c_str()); + } + else { /* center */ + int leftPad = + (alignment == TextLabel::AlignRight) + ? (cx - len) + : (cx - len) / 2; + + std::string padded; + for (int i = 0; i < leftPad; i++) { + padded += " "; + } + + padded += text; + wprintw(c, padded.c_str()); + } + + window.Repaint(); +} + +TextLabel::TextLabel() +: Window() +, alignment(AlignLeft) { + this->SetFrameVisible(false); +} + +TextLabel::~TextLabel() { +} + +void TextLabel::Show() { + Window::Show(); + redrawContents(*this, this->alignment, this->buffer); +} + +void TextLabel::SetText(const std::string& value, const Alignment alignment) { + if (value != this->buffer || alignment != this->alignment) { + this->buffer = value; + this->alignment = alignment; + redrawContents(*this, alignment, buffer); + } +} \ No newline at end of file diff --git a/src/musikbox/cursespp/TextLabel.h b/src/musikbox/cursespp/TextLabel.h new file mode 100755 index 000000000..140c0f325 --- /dev/null +++ b/src/musikbox/cursespp/TextLabel.h @@ -0,0 +1,70 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2016 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include + +namespace cursespp { + class TextLabel : +#if (__clang_major__ == 7 && __clang_minor__ == 3) + public std::enable_shared_from_this, +#endif + public cursespp::Window { + public: + enum Alignment { + AlignLeft, + AlignCenter, + AlignRight + }; + + TextLabel(); + virtual ~TextLabel(); + + virtual void SetText( + const std::string& value, + const Alignment alignment = AlignLeft); + + virtual std::string GetText() { return this->buffer; } + + virtual void Show(); + + private: + std::string buffer; + Alignment alignment; + }; +} diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index e29ec04aa..c73cdf721 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -124,9 +124,9 @@ + - @@ -144,7 +144,9 @@ + + @@ -166,9 +168,9 @@ + - @@ -199,7 +201,9 @@ + + diff --git a/src/musikbox/musikbox.vcxproj.filters b/src/musikbox/musikbox.vcxproj.filters index 9ad2fb4e7..624a05231 100755 --- a/src/musikbox/musikbox.vcxproj.filters +++ b/src/musikbox/musikbox.vcxproj.filters @@ -60,9 +60,6 @@ app\util - - app\util - cursespp @@ -105,6 +102,15 @@ app\layout + + cursespp + + + cursespp + + + app\util + @@ -195,9 +201,6 @@ app\util - - app\util - cursespp @@ -252,6 +255,15 @@ app\layout + + cursespp + + + cursespp + + + app\util +