From c9619c88d69e484250c854eb74a5da8d378cfc64 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 7 Jan 2017 15:44:37 -0800 Subject: [PATCH] More proof of concept work, showing core and glue can be re-used for other apps easily. --- src/musikwin/Main.cpp | 54 +++++-- .../app/controller/MainController.cpp | 137 ++++++++++++++++++ src/musikwin/app/controller/MainController.h | 64 ++++++++ src/musikwin/musikwin.vcxproj | 2 + src/musikwin/musikwin.vcxproj.filters | 9 ++ 5 files changed, 253 insertions(+), 13 deletions(-) create mode 100644 src/musikwin/app/controller/MainController.cpp create mode 100644 src/musikwin/app/controller/MainController.h diff --git a/src/musikwin/Main.cpp b/src/musikwin/Main.cpp index 4b869fd58..8fec96f95 100644 --- a/src/musikwin/Main.cpp +++ b/src/musikwin/Main.cpp @@ -1,3 +1,42 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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. +// +////////////////////////////////////////////////////////////////////////////// + +/* required to take advantage of system theming */ +#pragma comment(linker,"\"/manifestdependency:type='win32' \ +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + #include #include @@ -7,9 +46,9 @@ #include #include -#include #include +#include #include @@ -33,18 +72,7 @@ int APIENTRY _tWinMain(HINSTANCE instance, HINSTANCE previousInstance, LPTSTR co MasterTransport transport; PlaybackService playback(mainWindow.Queue(), library, transport); - std::shared_ptr query = - std::shared_ptr(new SearchTrackListQuery(library, "o'o")); - - library->Enqueue(query, ILibrary::QuerySynchronous); - - playback.Play(*query->GetResult(), 0); - - //size_t count = vis::VisualizerCount(); - //if (count) { - // vis::SetSelectedVisualizer(vis::GetVisualizer(1)); - // vis::SelectedVisualizer()->Show(); - //} + MainController mainController(mainWindow, playback, library); app.Run(mainWindow); diff --git a/src/musikwin/app/controller/MainController.cpp b/src/musikwin/app/controller/MainController.cpp new file mode 100644 index 000000000..2cc81c9db --- /dev/null +++ b/src/musikwin/app/controller/MainController.cpp @@ -0,0 +1,137 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 "MainController.h" +#include +#include +#include +#include + +using namespace musik::win; +using namespace musik::core; +using namespace musik::core::audio; +using namespace musik::glue; +using namespace musik::core::library; +using namespace win32cpp; + +using ColumnRef = ListView::ColumnRef; + +static ColumnRef sNumberColumn = ListView::Column::Create(_T("#"), 50); +static ColumnRef sTitleColumn = ListView::Column::Create(_T("title")); +static ColumnRef sDurationColumn = ListView::Column::Create(_T("duration"), 100, TextAlignment::TextAlignRight); +static ColumnRef sArtistColumn = ListView::Column::Create(_T("artist")); + +class TrackListModel : public ListView::Model { + public: + static std::shared_ptr Create(PlaybackService& playback) { + return std::shared_ptr(new TrackListModel(playback)); + } + + TrackListModel(PlaybackService& playback) + : playback(playback) { + this->SetRowCount(playback.Count()); + } + + virtual uistring CellValueToString(int rowIndex, ColumnRef column) { + TrackPtr track = playback.GetTrackAtIndex(rowIndex); + if (track) { + if (column == sNumberColumn) { + return u8to16(track->GetValue(constants::Track::TRACK_NUM)); + } + else if (column == sTitleColumn) { + return u8to16(track->GetValue(constants::Track::TITLE)); + } + else if (column == sDurationColumn) { + return u8to16(duration::Duration(track->GetValue(constants::Track::DURATION))); + } + else if (column == sArtistColumn) { + return u8to16(track->GetValue(constants::Track::ARTIST)); + } + } + return _T(""); + } + + private: + PlaybackService& playback; +}; + +MainController::MainController( + MainWindow& mainWindow, + PlaybackService& playback, + LibraryPtr library) +: mainWindow(mainWindow) +, playback(playback) +, library(library) { + std::shared_ptr query = + std::shared_ptr(new SearchTrackListQuery(library, "o'o")); + + library->Enqueue(query, ILibrary::QuerySynchronous); + + playback.Play(*query->GetResult(), 0); + + this->categoryList = this->mainWindow.AddChild(new ListView()); + + this->trackList = this->mainWindow.AddChild(new ListView()); + this->trackList->AddColumn(sNumberColumn); + this->trackList->AddColumn(sTitleColumn); + this->trackList->AddColumn(sDurationColumn); + this->trackList->AddColumn(sArtistColumn); + this->trackList->SetModel(TrackListModel::Create(this->playback)); + + this->Layout(); + + this->mainWindow.Resized.connect(this, &MainController::OnMainWindowResized); +} + +MainController::~MainController() { +} + +void MainController::Layout() { + auto size = this->mainWindow.ClientSize(); + if (size.height > 0) { + static int padding = 8; + int categoryCx = size.width / 3; + int tracksCx = size.width - (categoryCx + padding); + int tracksX = categoryCx + padding; + + this->categoryList->MoveTo(0, 0); + this->categoryList->Resize(categoryCx, size.height); + this->trackList->MoveTo(tracksX, 0); + this->trackList->Resize(tracksCx, size.height); + } +} + +void MainController::OnMainWindowResized(Window* window, Size size) { + this->Layout(); +} \ No newline at end of file diff --git a/src/musikwin/app/controller/MainController.h b/src/musikwin/app/controller/MainController.h new file mode 100644 index 000000000..895eed16f --- /dev/null +++ b/src/musikwin/app/controller/MainController.h @@ -0,0 +1,64 @@ +////////////////////////////////////////////////////////////////////////////// +// +// 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 +#include + +namespace musik { namespace win { + class MainController : public sigslot::has_slots<> { + public: + MainController( + MainWindow& mainWindow, + musik::core::audio::PlaybackService& playback, + musik::core::LibraryPtr library); + + virtual ~MainController(); + + private: + void OnMainWindowResized(win32cpp::Window* window, win32cpp::Size size); + void Layout(); + + MainWindow& mainWindow; + musik::core::audio::PlaybackService& playback; + musik::core::LibraryPtr library; + + win32cpp::ListView* categoryList; + win32cpp::ListView* trackList; + }; +} } \ No newline at end of file diff --git a/src/musikwin/musikwin.vcxproj b/src/musikwin/musikwin.vcxproj index 4ba8b361c..b7445da4b 100644 --- a/src/musikwin/musikwin.vcxproj +++ b/src/musikwin/musikwin.vcxproj @@ -161,6 +161,7 @@ + @@ -207,6 +208,7 @@ + diff --git a/src/musikwin/musikwin.vcxproj.filters b/src/musikwin/musikwin.vcxproj.filters index de15c4dce..2492d16e6 100644 --- a/src/musikwin/musikwin.vcxproj.filters +++ b/src/musikwin/musikwin.vcxproj.filters @@ -11,6 +11,9 @@ {94c9ba27-fe20-4cf8-ab88-c592d44a291e} + + {5fd5f17a-985c-482e-bd21-b5a7d3246060} + @@ -143,6 +146,9 @@ app\view + + app\controller + @@ -260,6 +266,9 @@ app\view + + app\controller +