Debian Codegraph @

src/engine/converter.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2021 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include <engine/converter.h>
14 #include <engine/locking.h>
15
16 #include <startgui.h>
17 #include <joblist.h>
18 #include <player.h>
19 #include <config.h>
20 #include <utilities.h>
21
22 #include <jobs/engine/convert.h>
23
24 using namespace BoCA;
25 using namespace BoCA::AS;
26
27 freac::Converter::Converter() : finishedSignal(1)
28 {
29 finishedSignal.Wait();
30 }
31
32 freac::Converter::~Converter()
33 {
34 }
35
36 Void freac::Converter::Convert(const Array<Track> &tracks, Bool autoRip, Bool asynchronous)
37 {
38 /* Check if any track is locked by playback.
39 */
40 if (IsAnyTrackLocked(tracks))
41 {
42 BoCA::Utilities::ErrorMessage("Cannot start ripping while playing a track from the same drive!");
43
44 return;
45 }
46
47 /* Start conversion job.
48 */
49 Job *convert = new JobConvert(tracks, autoRip);
50
51 if (!asynchronous) convert->onFinish.Connect(&Converter::OnFinishJob, this);
52
53 convert->Schedule();
54
55 if (!asynchronous) finishedSignal.Wait();
56 }
57
58 Void freac::Converter::OnFinishJob()
59 {
60 finishedSignal.Release();
61 }
62
63 Bool freac::Converter::IsAnyTrackLocked(const Array<Track> &tracks) const
64 {
65 BoCA::Config *config = BoCA::Config::Get();
66
67 if (config->GetIntValue(Config::CategorySettingsID, Config::SettingsEnableConsoleID, Config::SettingsEnableConsoleDefault)) return False;
68
69 /* Check if currently playing a CD track.
70 */
71 Player *player = freacGUI::Get()->GetPlayer();
72
73 if (player->IsPlaying())
74 {
75 const Track &playingTrack = player->GetPlayingTrack();
76
77 if (!Locking::LockDeviceForTrack(playingTrack))
78 {
79 foreach (const Track &track, tracks)
80 {
81 if (!Locking::LockDeviceForTrack(track)) return True;
82
83 Locking::UnlockDeviceForTrack(track);
84 }
85 }
86 else
87 {
88 Locking::UnlockDeviceForTrack(playingTrack);
89 }
90 }
91
92 return False;
93 }