LMMS
Loading...
Searching...
No Matches
PlayHandle.h
Go to the documentation of this file.
1/*
2 * PlayHandle.h - base class PlayHandle - core of rendering engine
3 *
4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_PLAY_HANDLE_H
26#define LMMS_PLAY_HANDLE_H
27
28#include <QList>
29#include <QMutex>
30
31#include "lmms_export.h"
32
33#include "Flags.h"
34#include "ThreadableJob.h"
35#include "LmmsTypes.h"
36
37class QThread;
38
39namespace lmms
40{
41
42class Track;
43class AudioBusHandle;
44class SampleFrame;
45
46class LMMS_EXPORT PlayHandle : public ThreadableJob
47{
48public:
49 enum class Type
50 {
54 PresetPreviewHandle = 0x08
55 } ;
57
58 constexpr static std::size_t MaxNumber = 1024;
59
60 PlayHandle( const Type type, f_cnt_t offset = 0 );
61
62 PlayHandle & operator = ( PlayHandle & p )
63 {
64 m_type = p.m_type;
65 m_offset = p.m_offset;
66 m_affinity = p.m_affinity;
67 m_usesBuffer = p.m_usesBuffer;
68 m_audioBusHandle = p.m_audioBusHandle;
69 return *this;
70 }
71
72 virtual ~PlayHandle();
73
74 virtual bool affinityMatters() const
75 {
76 return false;
77 }
78
79 const QThread* affinity() const
80 {
81 return m_affinity;
82 }
83
84 Type type() const
85 {
86 return m_type;
87 }
88
89 // required for ThreadableJob
90 void doProcessing() override;
91
92 bool requiresProcessing() const override
93 {
94 return !isFinished();
95 }
96
97 void lock()
98 {
99 m_processingLock.lock();
100 }
101 void unlock()
102 {
103 m_processingLock.unlock();
104 }
105 bool tryLock()
106 {
107 return m_processingLock.tryLock();
108 }
109 virtual void play( SampleFrame* buffer ) = 0;
110 virtual bool isFinished() const = 0;
111
112 // returns the frameoffset at the start of the playhandle,
113 // ie. how many empty frames should be inserted at the start of the first period
115 {
116 return m_offset;
117 }
118
119 void setOffset( f_cnt_t _offset )
120 {
121 m_offset = _offset;
122 }
123
124
125 virtual bool isFromTrack( const Track * _track ) const = 0;
126
127 bool usesBuffer() const
128 {
129 return m_usesBuffer;
130 }
131
132 void setUsesBuffer( const bool b )
133 {
134 m_usesBuffer = b;
135 }
136
141
143 {
144 m_audioBusHandle = busHandle;
145 }
146
147 void releaseBuffer();
148
149 SampleFrame* buffer();
150
151private:
154 QThread* m_affinity;
160} ;
161
162using PlayHandleList = QList<PlayHandle*>;
163using ConstPlayHandleList = QList<const PlayHandle*>;
164
166
167} // namespace lmms
168
169#endif // LMMS_PLAY_HANDLE_H
#define LMMS_DECLARE_OPERATORS_FOR_FLAGS(type)
Definition Flags.h:77
Job between PlayHandle and MixerChannel.
Definition AudioBusHandle.h:55
Definition Flags.h:34
Definition InstrumentPlayHandle.h:38
Definition NotePlayHandle.h:48
Definition PlayHandle.h:47
PlayHandle(const Type type, f_cnt_t offset=0)
Definition PlayHandle.cpp:36
void unlock()
Definition PlayHandle.h:101
AudioBusHandle * m_audioBusHandle
Definition PlayHandle.h:159
virtual void play(SampleFrame *buffer)=0
AudioBusHandle * audioBusHandle()
Definition PlayHandle.h:137
Type m_type
Definition PlayHandle.h:152
void setOffset(f_cnt_t _offset)
Definition PlayHandle.h:119
virtual bool isFinished() const =0
void setUsesBuffer(const bool b)
Definition PlayHandle.h:132
void lock()
Definition PlayHandle.h:97
bool m_bufferReleased
Definition PlayHandle.h:157
const QThread * affinity() const
Definition PlayHandle.h:79
bool usesBuffer() const
Definition PlayHandle.h:127
bool requiresProcessing() const override
Definition PlayHandle.h:92
Type type() const
Definition PlayHandle.h:84
virtual bool affinityMatters() const
Definition PlayHandle.h:74
virtual bool isFromTrack(const Track *_track) const =0
static constexpr std::size_t MaxNumber
Definition PlayHandle.h:58
SampleFrame * buffer()
Definition PlayHandle.cpp:73
void setAudioBusHandle(AudioBusHandle *busHandle)
Definition PlayHandle.h:142
QMutex m_processingLock
Definition PlayHandle.h:155
f_cnt_t m_offset
Definition PlayHandle.h:153
f_cnt_t offset() const
Definition PlayHandle.h:114
QThread * m_affinity
Definition PlayHandle.h:154
Flags< Type > Types
Definition PlayHandle.h:56
bool m_usesBuffer
Definition PlayHandle.h:158
SampleFrame * m_playHandleBuffer
Definition PlayHandle.h:156
bool tryLock()
Definition PlayHandle.h:105
Type
Definition PlayHandle.h:50
Definition SampleFrame.h:41
Definition SamplePlayHandle.h:43
ThreadableJob()
Definition ThreadableJob.h:47
Base-class for all tracks.
Definition Track.h:68
Definition AudioAlsa.cpp:35
QList< PlayHandle * > PlayHandleList
Definition PlayHandle.h:162
QList< const PlayHandle * > ConstPlayHandleList
Definition PlayHandle.h:163
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
uch * p
Definition crypt.c:594
b
Definition crypt.c:628