summaryrefslogtreecommitdiffstats
path: root/src/qalcontext.h
blob: 5ecd13c9aa51d5f5be7ce4d11505f1a7fe22b13a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/******************************************************************************
 * This file is part of the QtOpenAL project
 * Copyright (c) 2011 Laszlo Papp <lpapp@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef QALCONTEXT_H
#define QALCONTEXT_H

#include "q_openal_export.h"

#include "qalattributes.h"

class QALBufferQueue;

class Q_OPENAL_EXPORT QALContext
{
    //Q_DECLARE_PRIVATE(QALContext)
public:
    /**
     * Constructor
     */
    QALContext(const QALAttributes &attributes = QALAttributes::defaultAttributes());

    /**
     * Desctructor
     */
    virtual ~QALContext();

    /**
     * Opens the device, starts it in the context, and then creates the
     * context accordingly
     *
     * @return True if the operation was successful; otherwise false
     */
    bool create();

    /**
     * Returns the attributes that the application requested, and what create()
     * will use to create the device/context with
     *
     * @see create
     */
    QALAttributes requestedAttributes() const;

    /*! 
      Sets the requested attributes for the devices.

      \sa attributes()
      */
    void setRequestedAttributes(const QALAttributes &attributes);

    /*! 
      Return the current attributes as given by the device. It constructs a new
      QALAttributes using the values directly from the device

      \sa requestedAttributes()
      */
    QALAttributes attributes() const;

    /**
     * Checks whether or not the context is valid.
     *
     * @return True, if the context is valid; otherwise false
     */
    bool isValid() const;

    /**
     * Destroys the context and closes the device
     *
     * @return True, if the destroy and close were successful; otherwise false
     */
    bool reset();

    /**
     * Tries to set the context current
     *
     * @return True, if the context could be set as current; otherwise false
     */
    bool makeCurrent();

    /**
     * Tries to set the current context to NULL
     *
     * @return  True, if the current context could be to NULL; otherwise false
     */
    bool doneCurrent();

    /**
     * Generates a buffer, opens the file with the audio decoder and then loads
     * the sound into it
     *
     * @param filename The file to open
     */
    ALuint cacheBuffer(const QString& filename);

    /**
     * Uses a QALBufferQueue to hold multiple buffers that get little portions
     * of the audio instead of loading the sound fully into a buffer
     */
    QALBufferQueue streamBuffer(const QString& filename);

    bool deleteBuffer(ALuint bufferId);

    bool deleteBuffers();

    void deleteBufferQueue(QALBufferQueue &bufferQueue);

    /**
     * Calls alcGetProcAddress with the opened device
     */
    void *getProcAddress(const QString &proc) const;


    private:
        class Private;
        Private *const d;
};

#endif