summaryrefslogtreecommitdiff
path: root/libs/ardour/mp3filesource.cc
blob: 7b90e93f3d009f4644c5eb25ae19a8c0238af74d (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
/*
 * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "pbd/error.h"
#include "pbd/compose.h"
#include "ardour/mp3filesource.h"

#include "pbd/i18n.h"

using namespace ARDOUR;
using namespace PBD;

/** Constructor to be called for existing external-to-session files
 * Sources created with this method are never writable or removable.
 */

Mp3FileSource::Mp3FileSource (Session& s, const string& path, int chn, Flag flags)
	: Source (s, DataType::AUDIO, path,
			Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
	, AudioFileSource (s, path,
			Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
	, _mp3 (path)
	, _channel (chn)
{
	_length = _mp3.length ();

	if (_channel >= (int) _mp3.channels ()) {
		error << string_compose("Mp3FileSource: file only contains %1 channels; %2 is invalid as a channel number (%3)", _mp3.channels (), _channel, name()) << endmsg;
		throw failed_constructor();
	}
}

Mp3FileSource::~Mp3FileSource ()
{
}

void
Mp3FileSource::close ()
{
}

samplecnt_t
Mp3FileSource::read_unlocked (Sample* dst, samplepos_t start, samplecnt_t cnt) const
{
	return _mp3.read_unlocked (dst, start, cnt, _channel);
}

int
Mp3FileSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
{
	try {
		Mp3FileImportableSource mp3 (path);
		_info.samplerate  = mp3.samplerate ();
		_info.channels    = mp3.channels ();
		_info.length      = mp3.length ();
		_info.format_name = string_compose (_("MPEG Layer %1 (%2 kbps)"), mp3.layer (), mp3.bitrate ());
		_info.timecode    = 0;
		_info.seekable    = false;
		return 0;
	} catch (...) {}
	return -1;
}