Beatmup
fragment.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include <mutex>
21 
22 namespace Beatmup {
23  /**
24  Abstract fragmented signals representation.
25  Used internally for audio signals.
26  */
27  namespace Fragments {
28  /**
29  Represents a continuous set of data samples
30  */
31  class Fragment {
32  Fragment(const Fragment&) = delete; //!< disabling copying constructor
33 
34  private:
35  std::mutex access; //!< exclusive access
36  unsigned int referenceCount; //!< number of occurrences of this frame in sequences
37 
38  protected:
39  int sampleCount; //!< number of samples within this frame
40  Fragment();
41  virtual ~Fragment() {};
42 
43  public:
44  inline const int getSampleCount() const { return sampleCount; }
45  virtual Fragment* clone() const = 0;
46 
47  /**
48  Enables editing of the current frame
49  */
50  Fragment* edit();
51 
52  /**
53  References the frame when it is used one more time
54  */
55  Fragment* use();
56 
57  /**
58  Dereferences the frame when it is not used any more
59  */
60  void drop();
61  };
62 
63  /**
64  Pointer to a Fragment.
65  Handles reference counting of the pointer Fragment.
66  */
67  struct FragmentPtr {
68  public:
70  int offset; //!< offset in samples inside the fragment since its beginning
71  int length; //!< number of samples to use from the fragment
72  void operator =(const FragmentPtr&);
73 
74  /**
75  Initialize to null
76  */
77  FragmentPtr();
79  FragmentPtr(const FragmentPtr&);
81 
82  ~FragmentPtr();
83 
84  void editData();
85  inline bool isNull() const { return fragment == NULL; }
86  void nullify();
87  };
88  }}
Represents a continuous set of data samples.
Definition: fragment.h:31
void drop()
Dereferences the frame when it is not used any more.
Definition: fragment.cpp:46
std::mutex access
exclusive access
Definition: fragment.h:35
virtual Fragment * clone() const =0
unsigned int referenceCount
number of occurrences of this frame in sequences
Definition: fragment.h:36
int sampleCount
number of samples within this frame
Definition: fragment.h:39
Fragment * edit()
Enables editing of the current frame.
Definition: fragment.cpp:27
Fragment(const Fragment &)=delete
disabling copying constructor
Fragment * use()
References the frame when it is used one more time.
Definition: fragment.cpp:39
const int getSampleCount() const
Definition: fragment.h:44
Pointer to a Fragment.
Definition: fragment.h:67
void operator=(const FragmentPtr &)
Definition: fragment.cpp:58
int offset
offset in samples inside the fragment since its beginning
Definition: fragment.h:70
int length
number of samples to use from the fragment
Definition: fragment.h:71
FragmentPtr()
Initialize to null.
Definition: fragment.cpp:71