~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-factory/bear-editor/src/bf/code/sample.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Bear Engine - Editor library
 
3
 
 
4
    Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify it
 
7
    under the terms of the GNU General Public License as published by the
 
8
    Free Software Foundation; either version 2 of the License, or (at your
 
9
    option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful, but WITHOUT
 
12
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
    more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License along
 
17
    with this program; if not, write to the Free Software Foundation, Inc.,
 
18
    51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
    contact: plee-the-bear@gamned.org
 
21
 
 
22
    Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file bf/code/sample.cpp
 
26
 * \brief Implementation of the bf::sample class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#include "bf/sample.hpp"
 
30
 
 
31
#include "bf/compiled_file.hpp"
 
32
#include "bf/path_configuration.hpp"
 
33
 
 
34
/*----------------------------------------------------------------------------*/
 
35
/**
 
36
 * \brief Default constructor.
 
37
 */
 
38
bf::sample::sample()
 
39
  : m_loops(1), m_volume(1)
 
40
{
 
41
 
 
42
} // sample::sample()
 
43
 
 
44
/*----------------------------------------------------------------------------*/
 
45
/**
 
46
 * \brief Set the path to the resource to use.
 
47
 * \param name The new value.
 
48
 */
 
49
void bf::sample::set_path( const std::string& name )
 
50
{
 
51
  m_path = name;
 
52
} // sample::set_path()
 
53
 
 
54
/*----------------------------------------------------------------------------*/
 
55
/**
 
56
 * \brief Set the number of times the sample will be played.
 
57
 * \param loops The new value.
 
58
 */
 
59
void bf::sample::set_loops( const unsigned int loops )
 
60
{
 
61
  m_loops = loops;
 
62
} // sample::set_loops()
 
63
 
 
64
/*----------------------------------------------------------------------------*/
 
65
/**
 
66
 * \brief The volume at which the sample is played.
 
67
 * \param v The new value, in the interval (0,1).
 
68
 */
 
69
void bf::sample::set_volume( const double v )
 
70
{
 
71
  if (v > 1)
 
72
    m_volume = 1;
 
73
  else if ( v < 0 )
 
74
    m_volume = 0;
 
75
  else
 
76
    m_volume = v;
 
77
} // sample::set_volume()
 
78
 
 
79
/*----------------------------------------------------------------------------*/
 
80
/**
 
81
 * \brief Get how many times the sample will be played.
 
82
 */
 
83
unsigned int bf::sample::get_loops() const
 
84
{
 
85
  return m_loops;
 
86
} // sample::get_loops()
 
87
 
 
88
/*----------------------------------------------------------------------------*/
 
89
/**
 
90
 * \brief Get the volume at which the sample is played.
 
91
 */
 
92
double bf::sample::get_volume() const
 
93
{
 
94
  return m_volume;
 
95
} // sample::get_volume()
 
96
 
 
97
/*----------------------------------------------------------------------------*/
 
98
/**
 
99
 * \brief Get the path to the resource to use.
 
100
 */
 
101
const std::string& bf::sample::get_path() const
 
102
{
 
103
  return m_path;
 
104
} // sample::get_path()
 
105
 
 
106
/*----------------------------------------------------------------------------*/
 
107
/**
 
108
 * \brief Tell if two samples are the same.
 
109
 * \param that The instance to compare to.
 
110
 */
 
111
bool bf::sample::operator==( const sample& that ) const
 
112
{
 
113
  return (m_path == that.m_path)
 
114
    && (m_loops == that.m_loops)
 
115
    && (m_volume == that.m_volume);
 
116
} // sample::operator==()
 
117
 
 
118
/*----------------------------------------------------------------------------*/
 
119
/**
 
120
 * \brief Tell if two samples are different.
 
121
 * \param that The instance to compare to.
 
122
 */
 
123
bool bf::sample::operator!=( const sample& that ) const
 
124
{
 
125
  return !(*this == that);
 
126
} // sample::operator!=()
 
127
 
 
128
/*----------------------------------------------------------------------------*/
 
129
/**
 
130
 * \brief Compile the sample.
 
131
 * \param f The stream in which we write the compiled sample.
 
132
 */
 
133
void bf::sample::compile( compiled_file& f ) const
 
134
{
 
135
  std::string path(m_path);
 
136
 
 
137
  if ( path_configuration::get_instance().expand_file_name(path) )
 
138
    path_configuration::get_instance().get_relative_path(path);
 
139
 
 
140
  f << path << m_loops << m_volume;
 
141
} // sample::compile()