libvisual  0.5.0
lv_libvisual.cpp
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Dennis Smit <ds@nerds-incorporated.org>
7  * Chong Kai Xiong <kaixiong@codeleft.sg>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include "config.h"
25 #include "version.h"
26 
27 #include "lv_libvisual.h"
28 #include "lv_common.h"
29 
30 #include "lv_alpha_blend.h"
31 #include "lv_fourier.h"
32 #include "lv_plugin_registry.h"
33 #include "lv_log.h"
34 #include "lv_param.h"
35 #include "lv_util.h"
36 #include "private/lv_time_system.hpp"
37 
38 #include "gettext.h"
39 
40 extern "C" {
41  void visual_cpu_initialize (void);
42  void visual_mem_initialize (void);
43 }
44 
45 namespace LV
46 {
47 
48  namespace {
49 
50  RandomSeed random_seed ()
51  {
52  return RandomSeed (Time::now ().to_usecs ());
53  }
54 
55  } // anonymous namespace
56 
57  class System::Impl
58  {
59  public:
60 
61  ParamList params;
62  RandomContext rng;
63 
64  Impl ();
65 
66  static ParamList initial_params ();
67  };
68 
69  System::Impl::Impl ()
70  : params {initial_params ()}
71  , rng {random_seed ()}
72  {}
73 
74  ParamList System::Impl::initial_params ()
75  {
76  return {
77  visual_param_new_integer ("songinfo-show",
78  "Show song info",
79  1,
80  nullptr),
81  visual_param_new_integer ("songinfo-timeout",
82  "Songinfo timeout in seconds",
83  5,
84  nullptr),
85  visual_param_new_bool ("songinfo-in-plugins",
86  "Show songinfo in plugins",
87  true,
88  nullptr),
89  visual_param_new_integer ("songinfo-cover-width",
90  "Song cover art width",
91  128,
92  visual_param_in_range_integer (32, 1000)),
93  visual_param_new_integer ("songinfo-cover-height",
94  "Song cover art height",
95  128,
96  visual_param_in_range_integer (32, 1000))
97  };
98  }
99 
100  template <>
101  LV_API System* Singleton<System>::m_instance = nullptr;
102 
103  void System::init (int& argc, char**& argv)
104  {
105  if (m_instance) {
106  visual_log (VISUAL_LOG_WARNING, "Attempt to initialize LV a second time");
107  return;
108  }
109 
110  m_instance = new System (argc, argv);
111  }
112 
113  std::string System::get_version () const
114  {
115  return VISUAL_VERSION " (" LV_REVISION ")";
116  }
117 
118  int System::get_api_version () const
119  {
120  return VISUAL_API_VERSION;
121  }
122 
123  ParamList& System::get_params () const
124  {
125  return m_impl->params;
126  }
127 
128  RandomContext& System::get_rng () const
129  {
130  return m_impl->rng;
131  }
132 
133  void System::set_rng_seed (VisRandomSeed seed)
134  {
135  m_impl->rng.set_seed (seed);
136  }
137 
138  System::System (int& argc, char**& argv)
139  : m_impl(new Impl)
140  {
141  visual_log (VISUAL_LOG_INFO, "Starting Libvisual %s", get_version ().c_str ());
142 
143 #if ENABLE_NLS
144  bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
145  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
146 #endif
147 
148  // Initialize CPU caps
149  visual_cpu_initialize ();
150 
151  // Initialize Mem system
152  visual_mem_initialize ();
153 
154  // Initialize high-resolution timer system
155  TimeSystem::start ();
156 
157  // Initialize the plugin registry
158  PluginRegistry::init ();
159  }
160 
161  System::~System ()
162  {
164  TimeSystem::shutdown ();
165  }
166 
167 } // LV namespace