Lumiera  0.pre.03
»edit your freedom«
playback-controller.cpp
Go to the documentation of this file.
1 /*
2  PlaybackController - playback controller object
3 
4  Copyright (C) Lumiera.org
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
34 #include "lib/error.hpp"
35 #include "include/logging.h"
36 
37 
38 namespace stage {
39 namespace ctrl {
40 
41  namespace error = lumiera::error;
42 
43 
44 
45  PlaybackController::PlaybackController()
46  : playing_(false)
47  , viewerHandle_(0)
48  {
49  instance = this;
50  }
51 
52  PlaybackController::~PlaybackController()
53  {
54  instance = nullptr;
55  }
56 
57 
58  PlaybackController* PlaybackController::instance;
59 
60  PlaybackController&
61  PlaybackController::get()
62  {
63  if (not instance)
64  throw error::Logic ("GTK UI is not in running state"
65  , LERR_(LIFECYCLE));
66 
67  return *instance;
68  }
69 
70  void
71  PlaybackController::play()
72  {
73  if (playHandle_)
74  {
75  playHandle_.play(true);
76  playing_ = true;
77  }
78  else if (viewerHandle_)
79  try
80  {
81  playHandle_ = lumiera::DummyPlayer::facade().start (viewerHandle_);
82  playing_ = true;
83  }
84  catch (lumiera::error::State& err)
85  {
86  WARN (stage, "failed to start playback: %s" ,err.what());
87  lumiera_error();
88  playing_ = false;
89  }
90  }
91 
92  void
93  PlaybackController::pause()
94  {
95  if (playHandle_)
96  playHandle_.play(false);
97  playing_ = false;
98  }
99 
100  void
101  PlaybackController::stop()
102  {
103  playHandle_.close();
104  playing_ = false;
105  }
106 
107  bool
108  PlaybackController::is_playing()
109  {
110  return playing_;
111  }
112 
113 
114 
115  void
116  PlaybackController::useDisplay (LumieraDisplaySlot display)
117  {
118  viewerHandle_ = display;
119  }
120 
121 
122 }} // namespace stage::ctrl
123 
A public service provided by the GUI, implementing the lumiera::Display facade interface.
This header is for including and configuring NoBug.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:124
Lumiera error handling (C++ interface).
This file contains the definition of the playback controller object.
static lib::Depend< DummyPlayer > facade
get an implementation instance of this service