1 
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 
4 /*
5     Rosegarden
6     A MIDI and audio sequencer and musical notation editor.
7     Copyright 2000-2021 the Rosegarden development team.
8 
9     Other copyrights also apply to some parts of this work.  Please
10     see the AUTHORS file and individual file headers for details.
11 
12     This program is free software; you can redistribute it and/or
13     modify it under the terms of the GNU General Public License as
14     published by the Free Software Foundation; either version 2 of the
15     License, or (at your option) any later version.  See the file
16     COPYING included with this distribution for more information.
17 */
18 
19 #ifndef RG_AUDIOPEAKSGENERATOR_H
20 #define RG_AUDIOPEAKSGENERATOR_H
21 
22 #include <QObject>
23 #include <QRect>
24 
25 #include <vector>
26 
27 class QEvent;
28 
29 
30 namespace Rosegarden
31 {
32 
33 class Segment;
34 class CompositionModelImpl;
35 class Composition;
36 class AudioPeaksThread;
37 
38 /// Generates peaks for an audio Segment.
39 /**
40  * Used by CompositionModelImpl to generate audio previews for an audio
41  * Segment.
42  *
43  * Uses AudioPeaksThread to generate the audio peaks (m_peaks).
44  */
45 class AudioPeaksGenerator : public QObject
46 {
47     Q_OBJECT
48 
49 public:
50     AudioPeaksGenerator(AudioPeaksThread &thread,
51                         const Composition &composition,
52                         const Segment *segment,
53                         const QRect &segmentRect,
54                         CompositionModelImpl *parent);
55     ~AudioPeaksGenerator() override;
56 
57     void setSegmentRect(const QRect &rect)  { m_rect = rect; }
58 
59     /// Generate audio peaks for the Segment.
60     /**
61      * The audioPeaksComplete() signal will be emitted on completion.
62      */
getShortcuts()63     void generateAsync();
64 
65     /// Stop a peak generation in progress.
66     void cancel();
67 
68     const std::vector<float> &getPeaks(unsigned int &channels) const
69     {
70         channels = m_channels;
71         return m_peaks;
72     }
73 
74     const Segment *getSegment() const  { return m_segment; }
75 
76 signals:
77     /// Emitted once the asynchronous generation of peaks is complete.
78     void audioPeaksComplete(AudioPeaksGenerator *);
79 
80 protected:
81     // QObject override.
82     bool event(QEvent *) override;
83 
84 private:
85     // ??? Instead of requiring that this comes in via the ctor, why not
86     //     get it directly from RosegardenDocument?  Or, even better, since
87     //     this is the main user, it should own the instance and allow
88     //     RosegardenDocument and CompositionView to get it from here.
89     AudioPeaksThread &m_thread;
90 
91     const Composition &m_composition;
92 
93     const Segment *m_segment;
94     QRect m_rect;
95     bool m_showMinima;
96 
97     /// Token from AudioPeaksThread to identify the work being done.
98     int m_token;
99 
100     unsigned int m_channels;
101     std::vector<float> m_peaks;
102 };
103 
104 
105 }
106 
107 #endif
108