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_AUDIOMANAGERDIALOG_H
20 #define RG_AUDIOMANAGERDIALOG_H
21 
22 #include "sound/AudioFile.h"
23 #include "misc/ConfigGroups.h"
24 #include "gui/general/ActionFileClient.h"
25 #include "gui/widgets/WarningGroupBox.h"
26 #include "base/Selection.h"
27 
28 #include <QMainWindow>
29 
30 class QWidget;
31 class QTimer;
32 class QString;
33 class QTreeWidget;
34 class QTreeWidgetItem;
35 class QLabel;
36 class QDropEvent;
37 class QCloseEvent;
38 class QShortcut;
39 class QUrl;
40 
41 //class KURL;
42 
43 
44 namespace Rosegarden
45 {
46 
47 
48 class AudioListView;
49 class Segment;
50 class RosegardenDocument;
51 class RealTime;
52 class AudioPlayingDialog;
53 class AudioFile;
54 class Command;
55 
56 /// Audio File Manager
57 class AudioManagerDialog : public QMainWindow, public ActionFileClient
58 {
59     Q_OBJECT
60 
61 public:
62     AudioManagerDialog(QWidget *parent,
63                        RosegardenDocument *doc);
64     ~AudioManagerDialog() override;
65 
66     // Populate the file list from the AudioFileManager
67     //
68 
69     // Return a pointer to the currently selected AudioFile -
70     // returns 0 if nothing is selected
71     //
72     AudioFile* getCurrentSelection();
73 
74     // Scroll and expand to show this selected item
75     //
76     void setSelected(AudioFileId id,
77                      const Segment *segment,
78                      bool propagate); // if true then we tell the segmentcanvas
79 
80     // Pop down playing dialog if it's currently up
81     //
82     void closePlayingDialog(AudioFileId id);
83 
84     // Can we playback audio currently?
85     //
86     void setAudioSubsystemStatus(bool ok);
87 
88     // Return the shortcut object
89     //
getShortcuts()90     QShortcut* getShortcuts() { return m_shortcuts; }
91 
92     // Add a new file to the audio file manager
93     //
94     bool addAudioFile(const QString &filePath);
95 
96 
97 public slots:
98     void slotAdd();
99     void slotPlayPreview();
100     void slotRename();
101     void slotInsert();
102     void slotRemove();
103     void slotRemoveAll();
104     void slotRemoveAllUnused();
105     void slotDeleteUnused();
106     void slotExportAudio();
107     void slotHelpRequested();
108     void slotHelpAbout();
109 
110 	//void slotItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
111 
112     // get selection
113 	void slotSelectionChanged();
114 //	void slotSelectionChanged(QTreeWidgetItem *);
115 
116     // Repopulate
117     //
118     void slotPopulateFileList();
119 
120     // Commands
121     //
122     void slotCommandExecuted();
123 
124     /**
125      * Accept a list of Segments and highlight accordingly
126      * Used to reflect a selection on the main view
127      * (when the user selects an audio track, the corresponding item
128      * in the audio manager should be selected in turn)
129      *
130      * We check for embedded audio segments and if we find exactly one
131      * we highlight it.  If we don't we unselect everything.
132      *
133      */
134     void slotSegmentSelection(const SegmentSelection &);
135 
136     /**
137      * Cancel the currently playing audio file
138      */
139     void slotCancelPlayingAudioFile();
140 
141     void slotClose();
142 
143     /**
144      * Turn a MIDI segment into a set of audio segments triggered
145      * by the MIDI Note Ons
146      */
147     void slotDistributeOnMidiSegment();
148 
149 signals:
150 
151     // Control signals so we can tell the sequencer about our changes
152     // or actions.
153     //
154     void addAudioFile(AudioFileId);
155     void deleteAudioFile(AudioFileId);
156     void playAudioFile(AudioFileId,
157                        const RealTime &,
158                        const RealTime &);
159     void cancelPlayingAudioFile(AudioFileId);
160     void deleteAllAudioFiles();
161 
162     /// We've selected a segment here, make the canvas select it too
163     /**
164      * RosegardenMainWindow::slotAudioManager() connects this to
165      * RosegardenMainViewWidget::slotPropagateSegmentSelection().
166      */
167     void segmentsSelected(const SegmentSelection&);
168 
169     void deleteSegments(const SegmentSelection&);
170     void insertAudioSegment(AudioFileId,
171                             const RealTime &,
172                             const RealTime &);
173 
174     void closing();
175 protected slots:
176     void slotDropped(QDropEvent *event, QTreeWidget*, const QList<QUrl> &sl );
177     void slotCancelPlayingAudio();
178 
179 protected:
180     bool addFile(const QUrl& kurl);
181     bool isSelectedTrackAudio();
182     void selectFileListItemNoSignal(QTreeWidgetItem*);
183     void updateActionState(bool haveSelection);
184 
185     void closeEvent(QCloseEvent *) override;
186 
187     //--------------- Data members ---------------------------------
188 
189     AudioListView *m_fileList;
190     WarningGroupBox    *m_wrongSampleRates;
191     RosegardenDocument *m_doc;
192 
193     QShortcut           *m_shortcuts;
194 
195     AudioFileId  m_playingAudioFile;
196     AudioPlayingDialog      *m_audioPlayingDialog;
197     QTimer                  *m_playTimer;
198 
199     static const char* const m_listViewLayoutName;
200     static const int         m_maxPreviewWidth;
201     static const int         m_previewHeight;
202 
203     bool                     m_audiblePreview;
204     int                      m_sampleRate;
205 };
206 
207 
208 
209 }
210 
211 #endif
212