Compare commits

...

638 Commits

Author SHA1 Message Date
Jonas Kvinge
c4600b2187 Release 0.6.13 2020-07-13 23:01:33 +02:00
Jonas Kvinge
89b15e3b57 Add taglib include dirs to unit test CMake file 2020-07-13 22:53:32 +02:00
Jonas Kvinge
07d8c3e770 Add .clang-format to excluded files in maketarball 2020-07-13 22:52:38 +02:00
Jonas Kvinge
c5ae64070e Add some include and link directories to unit test CMake
Fixes unit tests compile on macOS
2020-07-13 22:28:39 +02:00
Jonas Kvinge
2cb7c52147 Update README.md 2020-07-13 20:40:34 +02:00
Jonas Kvinge
c045b16213 Update README.md 2020-07-13 20:39:01 +02:00
Jonas Kvinge
b29387d409 More fancy tabbar fixes
- Only use custom size override for large and small sidebar modes
- Use scroll buttons by default
- Set elide text mode off because macOS has it on by default
- Set tooltip for top icon only mode
- Set icon sizes except for on macOS
2020-07-13 18:29:48 +02:00
Jonas Kvinge
614a09db1d Fix some compile warnings 2020-07-13 18:11:57 +02:00
Strawbs Bot
bcc5450aef Update translations 2020-07-13 01:02:37 +02:00
Jonas Kvinge
b0420a0566 Adjust width of settingspages 2020-07-13 00:57:50 +02:00
Jonas Kvinge
08d627bc9f Update Changelog 2020-07-13 00:39:33 +02:00
Jonas Kvinge
5b5f048faf Add missing taglib test files 2020-07-13 00:12:15 +02:00
Jonas Kvinge
212ebae043 Fix tab order in Appearance settings 2020-07-12 21:33:39 +02:00
Jonas Kvinge
a0c99df6b2 Make icon size for small tabbar configurable too 2020-07-12 21:02:29 +02:00
Jonas Kvinge
b0fabd7897 Adjust fancy tabbar size 2020-07-12 19:43:59 +02:00
Jonas Kvinge
938811f24f Fix sizes of horizontal modes and icon on top modes in fancy tabbar 2020-07-12 18:53:41 +02:00
Strawbs Bot
374d6e4d0f Update translations 2020-07-12 01:01:47 +02:00
Jonas Kvinge
5f54cdee0f Add new tagreader tests 2020-07-10 20:41:37 +02:00
Jonas Kvinge
c2bd452391 Fix playlist shuffle test, current index will never be at the end 2020-07-10 17:06:20 +02:00
Jonas Kvinge
d2bfc73b91 Only set playlist view item delegates once 2020-07-10 16:18:31 +02:00
Jonas Kvinge
42c62206c8 Move the currently playing song to the top when the playlist is manually shuffled
Fixes #304
2020-07-09 20:52:06 +02:00
Jonas Kvinge
4208b512f8 Remove some unused stuff in CMakeLists.txt 2020-07-09 20:09:07 +02:00
Strawbs Bot
3a3d5cd487 Update translations 2020-07-09 01:02:03 +02:00
Jonas Kvinge
e143a6d126 Enable playlist model tests 2020-07-08 20:52:50 +02:00
Jonas Kvinge
a99a19aa60 Fix broken playlist undostack when i.e. removing duplicates and unavailable songs 2020-07-08 20:43:46 +02:00
Jonas Kvinge
aba7d2b6a4 Fix mock_playlistitem.h 2020-07-08 18:22:12 +02:00
Jonas Kvinge
2fc6f835a8 Update sqlite test to use FTS5 instead of FTS3 2020-07-08 17:46:04 +02:00
Jonas Kvinge
27ce0e6d60 Add REQUIRED to find_package for GnuTLS 2020-07-08 17:29:58 +02:00
Strawbs Bot
05c70f2adb Update translations 2020-07-08 01:12:31 +02:00
Jonas Kvinge
904097b7b1 Add back option to use system taglib, add warning at the bottom 2020-07-07 23:44:04 +02:00
Jonas Kvinge
4e003c12a6 Add a taste of Strawbs background image 2020-07-07 23:02:24 +02:00
Jonas Kvinge
24f2cfb29f Fix playlist background image not loading 2020-07-07 22:21:07 +02:00
Jonas Kvinge
3f2b683fca Change pcmanfm-qt to pcmanfm 2020-07-07 18:28:47 +02:00
Strawbs Bot
83cee26d7d Update translations 2020-07-07 01:03:43 +02:00
Jonas Kvinge
c7df0c9b28 Use Q_UNUSED 2020-07-06 20:32:17 +02:00
Jonas Kvinge
26a8bfaac4 Open directory instead of file for PCManFM 2020-07-06 20:27:48 +02:00
Strawbs Bot
fc8a3be7d9 Update translations 2020-07-05 01:02:03 +02:00
Jonas Kvinge
b195c4033d Remove Ubuntu Eoan from CI 2020-07-04 11:34:47 +02:00
Jonas Kvinge
ab2732c55d Remove Fedora 33 from CI 2020-07-04 11:20:07 +02:00
Jonas Kvinge
7fd5c058be Fix buffer overflow when coverting S24LE 2020-07-04 01:55:36 +02:00
Jonas Kvinge
b22e8b4702 Convert S24LE and F32LE for analyzer
Fixes #155
2020-07-04 00:29:11 +02:00
Strawbs Bot
e2c2af3447 Update translations 2020-07-03 01:13:01 +02:00
Jonas Kvinge
4cd738ecb5 Properly calculate tab width 2020-07-02 04:24:55 +02:00
Strawbs Bot
e838470c26 Update translations 2020-07-02 01:01:57 +02:00
Jonas Kvinge
68e0bc40e1 Dont use fixed font size in fancy tabbar 2020-07-01 17:23:57 +02:00
Jonas Kvinge
9fc8bcdf62 Increase tab size 2020-07-01 14:32:30 +02:00
Jonas Kvinge
227b14a0b6 Make text in fancy tabbar wrap if too wide 2020-07-01 02:53:18 +02:00
Strawbs Bot
abcd184d5d Update translations 2020-06-30 01:02:57 +02:00
Jonas Kvinge
3fd9f4b0df Make fancy tabbar large mode icon size configurable 2020-06-29 03:03:04 +02:00
Jonas Kvinge
12ff3e963b Increase icon sizes in fancy tabbar large mode 2020-06-29 02:15:11 +02:00
Jonas Kvinge
558e392234 Make search field clear buttons follow icon size settings 2020-06-29 01:09:02 +02:00
Strawbs Bot
e747c2e263 Update translations 2020-06-29 01:03:02 +02:00
Jonas Kvinge
4d78b30e8c Make icon sizes configurable, increase default sizes for icons
Fixes #250
2020-06-28 18:36:48 +02:00
Strawbs Bot
9a1520d5e3 Update translations 2020-06-28 01:13:47 +02:00
Jonas Kvinge
04f3543424 Rename some layouts in mainwindow UI 2020-06-28 00:17:22 +02:00
Jonas Kvinge
eae287be37 Remove -Wno-bool-conversion 2020-06-27 03:00:25 +02:00
Jonas Kvinge
a0e698b058 Remove add_dependencies for singleapplication 2020-06-27 02:53:45 +02:00
Jonas Kvinge
cd2932adea taglib: Only match APE if MAC is found in the beginning of the file 2020-06-27 02:01:24 +02:00
Strawbs Bot
286b270592 Update translations 2020-06-27 01:13:13 +02:00
Jonas Kvinge
d1ebef2cc5 Remove DSF and DSDIFF from lists of supported audio formats 2020-06-27 00:58:37 +02:00
Jonas Kvinge
deb567fde7 Enable show in file browser based on local songs
Fixes #472
2020-06-27 00:52:26 +02:00
Jonas Kvinge
26586fb9ef Fix some includes in taglib 2020-06-27 00:06:02 +02:00
Jonas Kvinge
5f71a558b9 Adapt most changes from taglib2 2020-06-26 23:30:30 +02:00
Jonas Kvinge
08882639e0 Move SingleApplication includes to non-system includes 2020-06-26 23:27:38 +02:00
Jonas Kvinge
837ae2932f Add SYSTEM to system includes in target_include_directories 2020-06-26 23:26:04 +02:00
Jonas Kvinge
b51cc21140 Use override 2020-06-26 23:01:57 +02:00
Jonas Kvinge
f1115ba706 Remove explicit twice 2020-06-26 22:43:46 +02:00
Jonas Kvinge
dc36aee7ff Change some explicit usage 2020-06-26 22:41:38 +02:00
Jonas Kvinge
740f9581e6 Change 0 to nullptr 2020-06-26 22:06:23 +02:00
Jonas Kvinge
de0e3a7bc9 Use initialization list in tidalrequest 2020-06-26 22:05:07 +02:00
Jonas Kvinge
95e894fb4d Update README.md 2020-06-26 20:35:13 +02:00
Jonas Kvinge
faacb0d69f Subsonic: Dont strip words from title
Fixes #476
2020-06-26 17:35:05 +02:00
Jonas Kvinge
28b139e1b8 Disable wasapi plugin in nsi 2020-06-25 23:28:53 +02:00
Jonas Kvinge
39b1e0676b Fix memory include 2020-06-25 22:51:00 +02:00
Jonas Kvinge
c05fc5bd36 Update README.md 2020-06-25 14:12:54 +02:00
Jonas Kvinge
bbae9157fb Update README.md 2020-06-25 14:00:23 +02:00
Jonas Kvinge
fc5c63a869 Update README.md 2020-06-25 13:59:29 +02:00
Jonas Kvinge
e2e068f8e5 Remove .github/ISSUE_TEMPLATE/feature_request.md 2020-06-25 13:45:08 +02:00
Jonas Kvinge
43a068e30e Use QRandomGenerator 2020-06-22 15:22:14 +02:00
Jonas Kvinge
2beb4b8c6f taglib: Remove virtual functions workaround in audioproperties 2020-06-22 03:20:17 +02:00
Jonas Kvinge
ad4230f7fa taglib: Remove added explicit in tiostream 2020-06-22 03:11:58 +02:00
Jonas Kvinge
00369a2cfe taglib: Fix some formatting 2020-06-22 03:11:35 +02:00
Jonas Kvinge
248e487dd5 taglib: Remove unused functions + add virtual and explicit 2020-06-22 02:32:37 +02:00
Jonas Kvinge
3a3dc02a66 taglib: Rename Properties to AudioProperties 2020-06-22 00:49:25 +02:00
Jonas Kvinge
f49c47c20d Remove xine from NSI 2020-06-21 22:49:06 +02:00
Jonas Kvinge
417ef1a7a4 Add libgstwasapi.dll to debug release 2020-06-21 22:47:13 +02:00
Strawbs Bot
8e8889483f Update translations 2020-06-21 01:02:03 +02:00
Jonas Kvinge
b5818a9b62 Look for 2.0 module of libplist and libusbmuxd
Fixes #467
2020-06-20 17:39:43 +02:00
Jonas Kvinge
e709f676dc Remove unused tooltip files 2020-06-20 17:31:36 +02:00
Jonas Kvinge
bb611bf655 Dont use HTML in tooltip on KDE
Fixes #466
2020-06-20 17:30:37 +02:00
Strawbs Bot
24e8ca67c5 Update translations 2020-06-20 01:02:05 +02:00
Jonas Kvinge
0695941a77 Fix showing/hiding playing widget when playback is started while window is hidden 2020-06-19 17:32:08 +02:00
Strawbs Bot
7c71efd1b3 Update translations 2020-06-19 01:02:43 +02:00
Jonas Kvinge
5099aff5c3 Fix increasing play count when stop after track is enabled
Fixes #458
2020-06-18 22:18:49 +02:00
Jonas Kvinge
d3463250a9 Add on startup options to show maximized or minimized 2020-06-18 21:46:36 +02:00
Jonas Kvinge
3b58c02db0 Improve CMake files (#460) 2020-06-17 22:56:20 +02:00
Jonas Kvinge
64f0313d3c Remove ifdef's on slots in shortcutsettings page 2020-06-17 19:58:21 +02:00
Strawbs Bot
d3958e757b Update translations 2020-06-17 01:01:57 +02:00
Jonas Kvinge
651020388d Use override 2020-06-15 21:55:05 +02:00
Jonas Kvinge
72ede666d4 Replace use of C style casts 2020-06-15 17:59:02 +02:00
Jonas Kvinge
a68c249d4e Use parentheses for macro arguments 2020-06-15 00:33:47 +02:00
Jonas Kvinge
56caab4461 Remove redundant initialization 2020-06-15 00:11:52 +02:00
Jonas Kvinge
13b60351a6 Replace use of deprecated C++ headers 2020-06-14 23:54:18 +02:00
Jonas Kvinge
ad49d38e46 CI: Remove extra media for mageia 2020-06-14 23:20:40 +02:00
Jonas Kvinge
082c9097e4 Fix parameter name mispatches 2020-06-14 18:58:24 +02:00
Jonas Kvinge
2fbdb29ebc Replace 0 with nullptr 2020-06-14 17:02:47 +02:00
Jonas Kvinge
ef34dce4dc Additional manual formatting to taglib sources 2020-06-14 17:01:05 +02:00
Jonas Kvinge
577b7d8ec8 Use lengthInMilliseconds() 2020-06-14 16:08:18 +02:00
Jonas Kvinge
4ce099294c Format taglib sources 2020-06-13 19:02:42 +02:00
Strawbs Bot
72bff7fa35 Update translations 2020-06-13 01:02:48 +02:00
Jonas Kvinge
8c36b8803f Update .github/workflows/ccpp.yml 2020-06-12 19:22:29 +02:00
Strawbs Bot
c69993bd57 Update translations 2020-06-12 01:02:54 +02:00
Strawbs Bot
ea3e4982d2 Update translations 2020-06-10 01:01:56 +02:00
Strawbs Bot
9a5f6c7b9b Update translations 2020-06-09 01:02:35 +02:00
Jonas Kvinge
033d56a4b3 Use SetMinimumSize in about dialog 2020-06-08 23:40:15 +02:00
Jonas Kvinge
dfa684cccc Turn back git revision 2020-06-08 19:04:56 +02:00
Jonas Kvinge
b4e0f43dfc Update ccpp.yml 2020-06-07 23:59:31 +02:00
Jonas Kvinge
783cf7f1b0 Release 0.6.12 2020-06-07 23:49:11 +02:00
Jonas Kvinge
92d6fc3fad Change default grouping to album disc 2020-06-07 23:36:37 +02:00
Jonas Kvinge
436cdea4fd Add libgstfaac.dll 2020-06-06 15:08:30 +02:00
Jonas Kvinge
6b144b3b1f Add faac to nsi 2020-06-06 14:56:31 +02:00
Jonas Kvinge
7820082eb8 Add windows builder 2020-06-06 01:50:40 +02:00
Strawbs Bot
e732f921a3 Update translations 2020-06-06 01:02:52 +02:00
Jonas Kvinge
8b7c5d8585 Fix saving OSD pretty settings 2020-06-05 23:46:07 +02:00
Jonas Kvinge
9e959b189c Save settings when tabbar colors are changed 2020-06-05 23:39:22 +02:00
Jonas Kvinge
5c7a4cdc22 Fix deprecated use of QProcess::startDetached 2020-06-05 22:15:58 +02:00
Strawbs Bot
756e619e07 Update translations 2020-06-05 01:02:01 +02:00
Jonas Kvinge
eea6194b90 Add liborc-0.4-0.dll to nsi 2020-06-04 07:41:49 +02:00
Strawbs Bot
a09c1fa154 Update translations 2020-06-04 01:01:40 +02:00
Strawbs Bot
38c742328c Update translations 2020-05-31 01:01:44 +02:00
Jonas Kvinge
1d5db1446d Sort folders added from file view
Fixes #449
2020-05-30 21:59:55 +02:00
Jonas Kvinge
3f5f3d143f Fix compile without gstreamer 2020-05-30 21:39:16 +02:00
Jonas Kvinge
d297a7198a Update CI 2020-05-30 03:49:37 +02:00
Strawbs Bot
e5bd99dee4 Update translations 2020-05-30 01:04:25 +02:00
Jonas Kvinge
2720e13e88 Update libprotobuf DLL 2020-05-30 00:20:16 +02:00
Jonas Kvinge
0e9c1789ff Dont append disc to album title
Fixes #438
2020-05-29 20:38:19 +02:00
Jonas Kvinge
281cb10f84 Fix shadowing member 2020-05-29 18:30:27 +02:00
Jonas Kvinge
69a92ffe72 Remove mistankely added include 2020-05-29 18:30:09 +02:00
Jonas Kvinge
6447f159e5 Fix endl 2020-05-29 18:06:50 +02:00
Jonas Kvinge
94430883ad Use Qt::endl with Qt 5.14 and higher 2020-05-29 18:04:31 +02:00
Jonas Kvinge
046512eb3d Use Qt::endl 2020-05-29 17:47:26 +02:00
Jonas Kvinge
4479d97e90 Change use of Qt::KeyboardModifiers 2020-05-29 17:47:10 +02:00
Jonas Kvinge
bf5fea8951 Replace use of QMultiMap::insertMulti with QMultiMap::insert 2020-05-29 17:46:41 +02:00
Jonas Kvinge
07282e3de6 Change use of QLabel::pixmap 2020-05-29 17:45:00 +02:00
Jonas Kvinge
c2f90a20df Replace hex with Qt::hex 2020-05-29 17:43:44 +02:00
Jonas Kvinge
481d2d699e Replace QWheelEvent::delta with QWheelEvent::angleDelta 2020-05-29 17:42:40 +02:00
Jonas Kvinge
cf9a7e6ed3 Dont do qsrand on Qt versions higher than Qt 5.10 2020-05-29 17:40:34 +02:00
Jonas Kvinge
c35235371a Replace QString::SkipEmptyParts with Qt::SkipEmptyParts on Qt 5.14.0 or higher 2020-05-29 17:40:11 +02:00
Jonas Kvinge
5d5723ad58 Replace qrand with QRandomGenerator when using Qt 5.10 or higher 2020-05-29 17:37:46 +02:00
Jonas Kvinge
6c77294a86 Fixes to imobiledeviceconnection support 2020-05-29 17:36:01 +02:00
Strawbs Bot
823f65f1ca Add Czech 2020-05-29 01:52:17 +02:00
Strawbs Bot
0c378c1642 Update translations 2020-05-29 01:05:58 +02:00
Jonas Kvinge
bbb4162867 Make it possible to maximize console dialog 2020-05-26 18:27:01 +02:00
Jonas Kvinge
5dbdde3f2b Make scrobbler show error dialog for all errors when option is on 2020-05-26 17:51:23 +02:00
Jonas Kvinge
2521954bd9 Change layout name 2020-05-26 00:02:16 +02:00
Jonas Kvinge
5f1002894e Only save settings that has been changed 2020-05-25 23:56:54 +02:00
Jonas Kvinge
0489b312a3 Fix CircleCI 2020-05-25 23:56:29 +02:00
Jonas Kvinge
732be5a34f Use g_free 2020-05-24 23:22:18 +02:00
Jonas Kvinge
1f45c78ebb Unmap buffer references in error cases 2020-05-24 23:21:26 +02:00
Strawbs Bot
8b86c79bf9 Update translations 2020-05-18 01:01:33 +02:00
Jonas Kvinge
710ed81067 Require sqlite on centos too 2020-05-17 19:36:37 +02:00
Jonas Kvinge
24ac0e7b9b Fix CircleCI tumbleweed build 2020-05-17 18:34:25 +02:00
Jonas Kvinge
15b2bfbb29 Set library paths for Linux too when USE_BUNDLE is set 2020-05-17 17:01:35 +02:00
Jonas Kvinge
b7494eb381 Increase about dialog height 2020-05-17 16:25:18 +02:00
Strawbs Bot
27ac590250 Update translations 2020-05-17 01:01:49 +02:00
Jonas Kvinge
972076edab Move ClearDiskCache connect 2020-05-16 19:35:25 +02:00
Jonas Kvinge
bfa9a1eb8a Fix tests
Fixes #440
2020-05-16 19:17:06 +02:00
Jonas Kvinge
b0966f14e6 Only connect ClearPixmapDiskCache if app is set 2020-05-16 18:25:13 +02:00
Jonas Kvinge
37cf0c2fb6 Turn back git revision 2020-05-16 18:24:51 +02:00
Jonas Kvinge
4eb11c32b0 Release 0.6.11 2020-05-16 14:40:35 +02:00
Jonas Kvinge
25457bc09a Release 0.6.11 2020-05-16 14:39:53 +02:00
Jonas Kvinge
d5cfb5f733 Merge branch 'master' of github.com:strawberrymusicplayer/strawberry 2020-05-16 14:14:34 +02:00
Jonas Kvinge
79ba6e628e Use art id from the API as cover filename for Subsonic
Fixes #433
2020-05-16 14:13:22 +02:00
King_DuckZ
ef73add05a Warning fix on gcc 8.3.0 (#439)
Fixes warning:
assuming signed overflow does not occur when
simplifying conditional to constant [-Wstrict-overflow]

Signed-off-by: Michele Santullo <m.santullo@posteo.net>

Co-authored-by: Michele Santullo <m.santullo@posteo.net>
2020-05-16 13:34:42 +02:00
Strawbs Bot
ec3d11fb27 Update translations 2020-05-16 01:03:55 +02:00
Jonas Kvinge
3fbc7031b5 Update about dialog 2020-05-16 00:45:15 +02:00
Jonas Kvinge
40beb5e428 Update Changelog 2020-05-15 23:54:15 +02:00
Jonas Kvinge
0f608c8ef0 Update debian/copyright 2020-05-15 23:48:44 +02:00
Jonas Kvinge
8509cb4743 Spotify: Fix clearing access token 2020-05-15 23:36:01 +02:00
Jonas Kvinge
f4429e8c4a Make Musicbrainz cover provider respect rate limiting 2020-05-15 22:53:21 +02:00
Jonas Kvinge
e9e0829cdc Remove end dash from title 2020-05-15 22:15:52 +02:00
Strawbs Bot
93f0230423 Update translations 2020-05-15 01:03:01 +02:00
plonibarploni
f26a0df4a4 strip directory from OpenInFileManager command (#436) 2020-05-14 22:19:26 +02:00
Jonas Kvinge
c7d4624282 Update README.md 2020-05-14 22:12:55 +02:00
Jonas Kvinge
b03eee2a22 Update Changelog 2020-05-14 22:10:18 +02:00
Jonas Kvinge
7d4d72e706 Make Discogs provider respect rate limiting 2020-05-14 19:31:40 +02:00
Jonas Kvinge
e3c367984b Make it possible to receive SearchResults before SearchFinished 2020-05-14 19:30:29 +02:00
Jonas Kvinge
0ebfa10d32 Update details in playing widget 2020-05-14 19:29:34 +02:00
Jonas Kvinge
16d9a077f0 emit SearchCoverInProgress before SearchCoverAutomatically 2020-05-14 19:29:07 +02:00
Strawbs Bot
a9d8bbad42 Update translations 2020-05-14 01:03:53 +02:00
Jonas Kvinge
d78bb94af3 Fix Tidal OAuth login 2020-05-13 21:56:11 +02:00
Jonas Kvinge
b139c0a824 Dont use song count from backend for CDDA devices 2020-05-13 19:42:13 +02:00
Jonas Kvinge
5b0b924d34 Fix crash in CD songloader 2020-05-13 19:00:57 +02:00
Strawbs Bot
f75acf820c Update translations 2020-05-13 01:05:26 +02:00
Jonas Kvinge
43a47f33ac Dont link chromaprint unless its enabled
Fixes #432
2020-05-12 22:39:56 +02:00
Jonas Kvinge
fcea3a0877 Add option to scrobbler setting for showing login error
Fixes #430
2020-05-12 22:25:00 +02:00
Jonas Kvinge
a950ec3bd5 Adjust login state widget placement for covers and lyrics settings 2020-05-12 22:15:53 +02:00
Jonas Kvinge
e35501ff0a Delete remaining network replies and local redirct server in destructor 2020-05-12 21:28:42 +02:00
Jonas Kvinge
4bfad9dad8 Fix use of QString::right() 2020-05-12 21:12:08 +02:00
Jonas Kvinge
c5c7a07c12 Add QImageReader::imageFormatsForMimeType replacement function 2020-05-12 19:48:37 +02:00
Jonas Kvinge
7e22e0e552 Use original image format when saving images from Subsonic and Tidal
Fixes #435
2020-05-12 18:50:57 +02:00
Jonas Kvinge
84ec4bdc79 Check content type for image in album cover fetcher search 2020-05-12 18:47:32 +02:00
Jonas Kvinge
2bcad9b637 Do AddOrUpdateSongs in database thread 2020-05-12 18:45:24 +02:00
Jonas Kvinge
c8d5f03070 Dont use reference in AlbumSongsReplyReceived 2020-05-12 15:58:36 +02:00
Jonas Kvinge
168e101a5a Subsonic: Disconnect signal/slots 2020-05-12 15:55:13 +02:00
Jonas Kvinge
b4bc7333d9 Use album id as cover filename for Subsonic
Fixes #433
2020-05-12 15:53:15 +02:00
Strawbs Bot
e8b58c940e Update translations 2020-05-11 01:03:48 +02:00
Jonas Kvinge
ec7202e3f6 Use refresh token for ListenBrainz 2020-05-11 00:51:18 +02:00
Jonas Kvinge
9a740f7962 Change variable name 2020-05-11 00:49:54 +02:00
Jonas Kvinge
9210fdee0d Make spotify refresh login 2020-05-10 17:10:20 +02:00
Jonas Kvinge
d7661f0964 Fix possible crash in album cover fetcher 2020-05-10 16:54:14 +02:00
Jonas Kvinge
139e148912 Use shared_ptr for scrobbler cache items 2020-05-10 14:59:04 +02:00
Jonas Kvinge
1b8dedb4ed Clear access token when login is expired 2020-05-10 14:53:40 +02:00
Jonas Kvinge
5d6b0fa329 Reset last played song when playlist is finished 2020-05-10 13:08:29 +02:00
Jonas Kvinge
f35bbd89c9 Initialize QNetworkReply pointer 2020-05-10 12:56:12 +02:00
Jonas Kvinge
538a9e42f4 Remove these 2020-05-10 12:50:37 +02:00
Jonas Kvinge
623147dea7 Add Json cover provider class 2020-05-10 12:49:11 +02:00
Jonas Kvinge
dfecd0cd12 Show Json parse error 2020-05-10 12:48:48 +02:00
Jonas Kvinge
fe3af3a676 Clear albums on close in cover manager 2020-05-10 11:50:05 +02:00
Strawbs Bot
25f60331ed Update translations 2020-05-10 01:04:15 +02:00
Jonas Kvinge
d4860a3426 Use defaults from context UI 2020-05-09 18:37:43 +02:00
Jonas Kvinge
e7e77ed86b Add automatically search for album cover to context settings 2020-05-09 18:31:10 +02:00
Jonas Kvinge
dc80459c59 Remove debug print 2020-05-09 02:30:32 +02:00
Jonas Kvinge
2f2de59234 Fix AuthError function 2020-05-09 02:07:51 +02:00
Jonas Kvinge
7bccc21878 Add setting for cover providers 2020-05-09 01:48:08 +02:00
Strawbs Bot
40f9dafa44 Update translations 2020-05-09 01:04:23 +02:00
Jonas Kvinge
355d436d29 Sort settings pages 2020-05-08 20:25:02 +02:00
Jonas Kvinge
079b684388 Remove duplicate include 2020-05-08 20:17:33 +02:00
Jonas Kvinge
fd11f46d30 Add album cover provider from Musixmatch 2020-05-08 20:14:16 +02:00
Jonas Kvinge
cb7099199a Fix memory include 2020-05-08 18:47:55 +02:00
Jonas Kvinge
8566d91e89 Remove some unneeded includes, etc 2020-05-08 18:44:07 +02:00
Jonas Kvinge
f44ce49ea7 Add setting for lyric providers and add more providers
Fixes #335
2020-05-08 18:35:36 +02:00
Jonas Kvinge
6ef69f6b32 Format code 2020-05-08 18:34:33 +02:00
Strawbs Bot
f5983d5f10 Update translations 2020-05-07 01:03:30 +02:00
Jonas Kvinge
54cce5e089 Use album grouping function 2020-05-06 22:35:55 +02:00
Jonas Kvinge
4e4e596a1e Change some parameters to const 2020-05-06 22:26:29 +02:00
Jonas Kvinge
727a1f5ad1 Sort songs in collection by song title instead of track if previous
grouping is not the album.

Fixes #295
2020-05-06 22:14:59 +02:00
Jonas Kvinge
85fa86625b Fix infinite loop in stylesheetloader
Fixes #361
2020-05-06 21:43:44 +02:00
Jonas Kvinge
2c91877f83 Add option to show/hide sidebar
Fixes #393
2020-05-06 18:15:17 +02:00
Jonas Kvinge
7d1fac44e9 Update non collection songs with manually unset cover 2020-05-05 23:57:37 +02:00
Jonas Kvinge
2e34abfc0d Fix mpris:artUrl when using embedded cover
Fixes #426
2020-05-04 23:23:24 +02:00
Jonas Kvinge
81ba63e247 Turn on git revision 2020-05-02 15:18:39 +02:00
Strawbs Bot
8b11a65522 Update translations 2020-05-02 01:01:45 +02:00
Jonas Kvinge
7190ad1d15 Remove styles directory when uninstalling 2020-05-01 19:55:45 +02:00
Jonas Kvinge
1c9bae5df5 Update libnettle dll in nsi 2020-05-01 18:41:36 +02:00
Jonas Kvinge
cc7fd73916 Update libhogweed dll in nsi 2020-05-01 16:55:58 +02:00
Jonas Kvinge
6d8725f268 Release 0.6.10 2020-05-01 16:42:20 +02:00
Jonas Kvinge
373c7cdbc4 Update Changelog 2020-05-01 16:40:54 +02:00
Jonas Kvinge
a4855bb33b Decrease margin for top title in context a little 2020-05-01 16:40:29 +02:00
Jonas Kvinge
57c1358ded Ignore replies not containing images from Discogs 2020-05-01 12:02:15 +02:00
Jonas Kvinge
eb4ce1feab Use toUtf8() not toLocal8Bit() when converting string for UNC path
Fixes #418
2020-04-30 17:32:31 +02:00
Strawbs Bot
838c17e144 Update translations 2020-04-30 01:03:38 +02:00
Strawbs Bot
4499cbca3c Update translations 2020-04-29 01:08:07 +02:00
Jonas Kvinge
a835a4a2f7 Minor fixes to collection pixmap cache
- Add variables for cache size defaults
- Increase default disk cache size
- Change the pixmap cache settings UI to look better
- Add current pixmap disk cache used to settings
2020-04-29 00:33:38 +02:00
Jonas Kvinge
9cc6a94353 Replace some NewClosure's with lambda connects 2020-04-28 22:29:10 +02:00
Jonas Kvinge
5ed9d9c4a0 Update Changelog 2020-04-28 22:28:45 +02:00
Jonas Kvinge
9c5ac7080d Remove unused connect 2020-04-28 22:28:24 +02:00
Jonas Kvinge
6346370e86 Set some properties on font size spinboxes 2020-04-28 20:56:35 +02:00
Jonas Kvinge
80697f8f30 Add toolchain files to cmake dir 2020-04-28 16:24:40 +02:00
Jonas Kvinge
18b8b56367 Use leap 15.1 for source build 2020-04-28 16:23:27 +02:00
Jonas Kvinge
760aacca26 Make context fonts configurable
Fixes #362
2020-04-28 01:11:00 +02:00
Strawbs Bot
1a4f0dcf5a Update translations 2020-04-28 01:02:50 +02:00
Jonas Kvinge
947484a71c Set content margin for label top in context 2020-04-27 22:20:50 +02:00
Jonas Kvinge
a74439d038 Always load 32x32 icon for engine and device
Fixes #417
2020-04-27 21:36:49 +02:00
Jonas Kvinge
c338618593 Do size checking of icon sizes when loading system theme icons 2020-04-27 21:36:08 +02:00
Jonas Kvinge
011897da53 Remove gstreamer registry file on startup for Windows
Workaround for issue #266
2020-04-27 15:54:37 +02:00
Jonas Kvinge
3fcaa58947 Add back libtag.dll (required for GStreamer plugin) 2020-04-27 15:52:38 +02:00
Strawbs Bot
ef8bd4362a Update translations 2020-04-27 01:03:05 +02:00
Jonas Kvinge
627a2ef6dd Dont use system icon for clear search field icon
Fixes #413
2020-04-27 00:24:49 +02:00
Jonas Kvinge
2732536d6e Fix device state text color in devices
Fixes #414
2020-04-27 00:22:46 +02:00
Jonas Kvinge
5a1b4b3ff8 Remove logging include 2020-04-26 18:49:18 +02:00
Jonas Kvinge
d93ec82e4f Fix save album cover to file
Fixes #412
2020-04-26 18:48:07 +02:00
Jonas Kvinge
15080972f3 Turn off uniformItemSizes
Fixes #411
2020-04-26 18:32:42 +02:00
Strawbs Bot
171b58f737 Update translations 2020-04-26 01:09:51 +02:00
Jonas Kvinge
c008ab6141 Fix resume playback on startup for CUE 2020-04-25 15:57:02 +02:00
Jonas Kvinge
f14c3654dc Add search for lyrics as a seperate option
Double click album to show fullsize

Fixes #299
2020-04-25 14:48:43 +02:00
Jonas Kvinge
ae05a61551 Read date and genre from individual tracks in cue sheets
Fixes #347
2020-04-25 13:47:25 +02:00
Jonas Kvinge
8e1def225b Move some files 2020-04-25 01:59:21 +02:00
Jonas Kvinge
6e061764ee Remove phonon 2020-04-25 01:42:29 +02:00
Jonas Kvinge
ac55b22839 Fix scrobble duration 2020-04-25 01:15:23 +02:00
Jonas Kvinge
49f77d3b75 Change timeouts 2020-04-25 00:13:48 +02:00
Jonas Kvinge
4abc650edf Make scrobbler handle streams 2020-04-25 00:07:42 +02:00
Jonas Kvinge
5ba00b61be Remove unneeded includes 2020-04-25 00:07:18 +02:00
Jonas Kvinge
bc16a6c4cb Sort album cover search results by score and pick the first 3 2020-04-25 00:03:43 +02:00
Jonas Kvinge
ea4dc6f040 Add link directories 2020-04-24 19:48:57 +02:00
Strawbs Bot
749ae8d5eb Update translations 2020-04-24 01:10:40 +02:00
Jonas Kvinge
7a56ffb7c3 Use COMPILE_LANGUAGE when setting compile options 2020-04-24 00:01:59 +02:00
Jonas Kvinge
e62ab23de2 Add taglib includes 2020-04-24 00:01:23 +02:00
Jonas Kvinge
c6f6118506 Use system taglib on macOS 2020-04-24 00:00:07 +02:00
Jonas Kvinge
8a5d5ad952 Fix some compile warnings in taglib 2020-04-23 21:51:14 +02:00
Jonas Kvinge
49e2615d14 Fix missing declaration 2020-04-23 21:50:50 +02:00
Jonas Kvinge
9289394261 Remove some compile options 2020-04-23 21:50:25 +02:00
Jonas Kvinge
8da4c88fd3 Fix compile warnings 2020-04-23 21:08:28 +02:00
Jonas Kvinge
a303850341 Use initialization list in cueparser 2020-04-23 21:07:17 +02:00
Jonas Kvinge
fb33610672 Remove unneeded this 2020-04-23 21:06:54 +02:00
Jonas Kvinge
d024dd6563 Minor code fixes to Subsonic 2020-04-23 21:06:26 +02:00
Jonas Kvinge
0be48f9f59 Minor code fixes to Tidal 2020-04-23 21:05:57 +02:00
Jonas Kvinge
df9292bafe Remove unneeded this 2020-04-23 21:05:17 +02:00
Jonas Kvinge
c1dcef3477 Improve Musicbrainz cover provider 2020-04-23 21:04:37 +02:00
Jonas Kvinge
48bc1f8361 Improve Last.fm cover provider code 2020-04-23 21:03:36 +02:00
Jonas Kvinge
2b2b4dbcf4 Improve Discogs cover provider 2020-04-23 21:02:48 +02:00
Jonas Kvinge
a1eadecdef Fix compile warnings in tests 2020-04-23 21:01:34 +02:00
Jonas Kvinge
f0b529952d Fix some compile warnings in singleapplication 2020-04-23 21:00:43 +02:00
Jonas Kvinge
c1ac2debb8 Fix some compile warnings in taglib 2020-04-23 21:00:16 +02:00
Jonas Kvinge
ac40094d37 Update CMakeLists.txt files 2020-04-23 20:59:09 +02:00
Jonas Kvinge
cb2bb4cb67 Fix CI 2020-04-22 15:38:10 +02:00
Strawbs Bot
f2965940cc Update translations 2020-04-22 01:01:32 +02:00
Strawbs Bot
c9ca147898 Update translations 2020-04-21 01:08:13 +02:00
Jonas Kvinge
c379d7f846 Minor code improvements to Deezer cover provider 2020-04-20 23:52:06 +02:00
Jonas Kvinge
45ae1ed265 Make Tidal album cover provider search for tracks too 2020-04-20 23:26:36 +02:00
Jonas Kvinge
9bf00eff40 Minor changes to Qobuz cover provider (and fix compile) 2020-04-20 22:58:57 +02:00
Jonas Kvinge
1677b3d5b9 Add Qobuz album cover provider 2020-04-20 22:12:40 +02:00
Jonas Kvinge
2a6806004a Fix update song length in context 2020-04-20 18:52:59 +02:00
Jonas Kvinge
39347d69df Only show song length in context when available 2020-04-20 18:46:26 +02:00
Jonas Kvinge
a2c0e4d4b1 Improve album cover loader, lyrics search and streaming support
- Improve album cover loader
- Add album cover loader result struct
- Move album cover thumbnail scaling to album cover loader
- Make init art manual look for album cover images in song directory
- Make album cover search work for songs outside of collection and
  streams
- Make album cover search work based on artist + title if album is not
  present
- Update art manual in playlist for local files, devices and CDDA
- Make lyrics search work for streams
- Add stream dialog to menu
- Remove dead code in InternetSearchModel
- Simplify code in InternetSearchView
2020-04-20 18:03:18 +02:00
Jonas Kvinge
ab2ffd9ac1 Add configure internet service to menu 2020-04-20 18:01:45 +02:00
Jonas Kvinge
c69fff52cc Remove useless using std 2020-04-20 17:49:06 +02:00
Strawbs Bot
1cfe61dc72 Update translations 2020-04-20 01:01:39 +02:00
Strawbs Bot
a23f39d81e Update translations 2020-04-19 01:01:32 +02:00
Strawbs Bot
b7724ff583 Update translations 2020-04-18 01:01:40 +02:00
Jonas Kvinge
e5dba60fab Remove song_id and artist_id from initialization list 2020-04-17 22:17:57 +02:00
Jonas Kvinge
2ccf489a83 Remove debug line 2020-04-17 17:23:43 +02:00
Jonas Kvinge
068939ca0b Fallback to SHA1 hash for cover filename if artist / album is stripped 2020-04-17 17:22:50 +02:00
Strawbs Bot
94ba8614ec Update translations 2020-04-16 01:01:39 +02:00
Strawbs Bot
f12a0c2379 Update translations 2020-04-15 01:01:28 +02:00
Strawbs Bot
8ab257645b Update translations 2020-04-14 01:11:19 +02:00
Jonas Kvinge
6331a0615f Update device schema 2020-04-13 23:24:35 +02:00
Jonas Kvinge
a21855fa20 Merge pull request #406 from strawberrymusicplayer/tidal
Add back Tidal support
2020-04-13 22:37:41 +02:00
Jonas Kvinge
12150c2180 Change database file 2020-04-13 19:05:55 +02:00
Jonas Kvinge
d90aecb164 Add back Tidal support 2020-04-13 19:04:06 +02:00
Jonas Kvinge
e738f2bc9f Recreate indexes and views in upgrade schema 11 2020-04-13 16:32:31 +02:00
Jonas Kvinge
2f72c41cda Improve internet classes 2020-04-13 06:30:40 +02:00
Jonas Kvinge
aa43d42cdb Remove const from signal slot connects 2020-04-13 05:57:48 +02:00
Jonas Kvinge
be8228e33c Fix song_id check 2020-04-13 04:17:45 +02:00
Jonas Kvinge
5591472dbd Change artist and song ID to strings 2020-04-13 03:39:51 +02:00
Strawbs Bot
30e6ced4e9 Update translations 2020-04-13 01:01:36 +02:00
Strawbs Bot
5f4c2bae89 Update translations 2020-04-12 01:01:28 +02:00
Strawbs Bot
0f036d9a43 Update translations 2020-04-11 01:01:39 +02:00
Strawbs Bot
1695ac3a32 Update translations 2020-04-10 01:02:01 +02:00
Jonas Kvinge
07a19ba619 Use slash 2020-04-09 20:41:14 +02:00
Jonas Kvinge
4dd78d89a0 Add option to remove problematic filename characters 2020-04-09 19:59:31 +02:00
Jonas Kvinge
8f4056faa6 Allow all characters except slash and backslash when organising music
Fixes #404
2020-04-09 18:14:02 +02:00
Jonas Kvinge
7b40c33892 Add missing semicolon in desktop file 2020-04-09 16:02:06 +02:00
Jonas Kvinge
b06bb5142f Turn on git revision 2020-04-09 16:01:12 +02:00
Jonas Kvinge
d576156ee1 Update snap version 2020-04-09 03:41:08 +02:00
Jonas Kvinge
77079968a5 Release 0.6.9 2020-04-09 02:32:32 +02:00
Jonas Kvinge
e12aca6214 Update maketarball.sh.in 2020-04-09 02:32:17 +02:00
Strawbs Bot
2a72891f28 Update translations 2020-04-09 00:42:40 +02:00
Jonas Kvinge
6fe47e78f1 Remove APE file detection by content
Fixes #373
2020-04-09 00:26:25 +02:00
Jonas Kvinge
0094894b52 Update ccpp.yml 2020-04-08 23:57:59 +02:00
Jonas Kvinge
0951bfb7ac Update Changelog 2020-04-08 23:38:00 +02:00
Jonas Kvinge
60e8519b65 Fix track and title in playlist not being movable
Fixes #403
2020-04-08 22:44:39 +02:00
Jonas Kvinge
78df0ed707 Change variable name 2020-04-08 22:32:01 +02:00
Jonas Kvinge
e3da0d6c9f Update config.yml 2020-04-08 19:27:32 +02:00
Jonas Kvinge
5df30580a6 Switch GitHub actions to use openSUSE 2020-04-08 01:15:39 +02:00
Strawbs Bot
4816b7dcd8 Update translations 2020-04-08 01:09:21 +02:00
Jonas Kvinge
75bced198b Hide open Audio CD on Windows 2020-04-08 01:00:21 +02:00
Jonas Kvinge
b500813617 Disable open Audio CD on Windows 2020-04-08 00:56:19 +02:00
Jonas Kvinge
a80037f7fc Update .travis.yml 2020-04-08 00:42:00 +02:00
Jonas Kvinge
1a6345342f Add Travis-CI 2020-04-07 17:05:01 +02:00
Jonas Kvinge
21b2193cd0 Add explicit 2020-04-07 16:49:15 +02:00
Jonas Kvinge
3efc496c41 Add better error handling for CDDA loader 2020-04-07 16:48:12 +02:00
Strawbs Bot
16340fbb78 Add Hungarian 2020-04-07 02:02:31 +02:00
Jonas Kvinge
a858b28bc4 Remove unused QGuiApplication include 2020-04-07 01:44:03 +02:00
Jonas Kvinge
307961cc7e Center organise and transcoder dialog on same screen as mainwindow 2020-04-07 01:26:17 +02:00
Strawbs Bot
3074377b55 Update translations 2020-04-07 01:03:31 +02:00
Jonas Kvinge
5a3edc00ac Remove extra check for oversized window 2020-04-06 23:14:23 +02:00
Jonas Kvinge
5a5f50e1e4 Use current_screen() function in OSD Pretty 2020-04-06 23:01:50 +02:00
Jonas Kvinge
7f39a38d6c Center cover manager on same screen as mainwindow 2020-04-06 22:30:03 +02:00
Jonas Kvinge
8321a48af7 Add missing QGuiApplication include 2020-04-06 22:26:55 +02:00
Jonas Kvinge
7e613f032e Add upgrade step to GitHub Actions 2020-04-06 22:26:19 +02:00
Jonas Kvinge
1c38c39db2 Center settings on current screen 2020-04-06 22:02:32 +02:00
Jonas Kvinge
4a0235c2ed Check for null pointer in OSD Pretty 2020-04-06 22:01:44 +02:00
Jonas Kvinge
b92961fda0 Merge branch 'circleci' 2020-04-06 06:46:39 +02:00
Jonas Kvinge
a2a06be62f Merge pull request #399 from plonibarploni/patch-2
Fix 'Show in file browser' for Caja
2020-04-06 05:21:18 +02:00
plonibarploni
c0956ed3b0 Fix 'Show in file browser' for Caja 2020-04-05 22:33:06 -04:00
Jonas Kvinge
3705e4e4d4 Add Ubuntu Focal to CircleCI 2020-04-06 03:07:09 +02:00
Jonas Kvinge
3fdbe84573 Rewrite parts of context to be adjustable and adjust album to width 2020-04-06 02:47:57 +02:00
Strawbs Bot
fb8e7d803f Update translations 2020-04-06 01:01:36 +02:00
Strawbs Bot
b01821aa03 Add Polish
Fixes #397
2020-04-05 13:24:58 +02:00
Strawbs Bot
69f974c9d0 Update translations 2020-04-05 01:02:31 +02:00
Jonas Kvinge
5db8b743fe Subsonic: Fix setting size 2020-04-04 23:34:04 +02:00
Jonas Kvinge
c424b0c888 Subsonic: Check if int values are strings 2020-04-04 23:31:27 +02:00
Strawbs Bot
d035c7d3b8 Update translations 2020-04-01 01:01:37 +02:00
Jonas Kvinge
144ffbc428 Subsonic: Handle track as string 2020-04-01 00:33:00 +02:00
Jonas Kvinge
afa8486d40 Update bug_report.md 2020-03-22 20:33:46 +01:00
Jonas Kvinge
a4cd42c448 Update README.md 2020-03-22 19:39:24 +01:00
Jonas Kvinge
853f4b75fa Update README.md 2020-03-22 00:17:40 +01:00
Jonas Kvinge
b95612287f This is a combination of 2 commits. (#390)
Add CircleCI
2020-03-20 16:17:11 +01:00
Jonas Kvinge
64e779172c Remove Travis-CI from master branch 2020-03-20 00:33:05 +01:00
Jonas Kvinge
10a136b4a3 Update macdeploy.py 2020-03-19 21:54:02 +01:00
Jonas Kvinge
ddc3af28ab Add back Travis-CI for macOS builds 2020-03-19 19:21:24 +01:00
Strawbs Bot
f602948dcf Update translations 2020-03-19 01:03:27 +01:00
Jonas Kvinge
973229cf4e Dont allow copy music to optical drives
Fixes #387
2020-03-17 20:44:51 +01:00
Strawbs Bot
d1f5cbea4a Update translations 2020-03-17 01:01:55 +01:00
Jonas Kvinge
49fe670ddb Center text of track column in tag fetcher
Fixes #388
2020-03-16 23:30:53 +01:00
Strawbs Bot
d6d87675c9 Update translations 2020-03-16 01:02:00 +01:00
Jonas Kvinge
1ca1927904 Only search for cover automatically for collection songs 2020-03-15 02:56:22 +01:00
Jonas Kvinge
454c3d1a3c Fix macOS build 2020-03-15 02:00:13 +01:00
Jonas Kvinge
11f5004112 Use a shorter playlist name when songs are added from file view
Fixes #363
2020-03-15 01:56:48 +01:00
Jonas Kvinge
625343f698 Check xdg-mime on Unix to find default file manager on Unix
Fixes #382
2020-03-15 01:21:30 +01:00
Jonas Kvinge
89d96a3ec1 Update README.md 2020-03-12 19:36:07 +01:00
Jonas Kvinge
c4c47fa196 Update README.md 2020-03-12 19:28:42 +01:00
Jonas Kvinge
ca35894b82 Update README.md 2020-03-12 19:27:00 +01:00
Jonas Kvinge
0213b6556b Add missing memory include 2020-03-08 19:13:13 +01:00
Jonas Kvinge
4edfd9be30 Merge branch 'master' of github.com:strawberrymusicplayer/strawberry 2020-03-08 18:40:56 +01:00
Jonas Kvinge
e55d9cafb6 Update logger 2020-03-08 18:40:39 +01:00
Jonas Kvinge
8deb0ed556 Move setting highDPI options 2020-03-08 18:36:48 +01:00
Strawbs Bot
82f995f243 Add Korean 2020-03-07 15:26:13 +01:00
Jonas Kvinge
b41c2ca724 Update README.md 2020-03-07 15:19:11 +01:00
Strawbs Bot
06ddbaf2cc Update translations 2020-03-01 01:02:03 +01:00
Jonas Kvinge
2adbfe1fbd Update required Qt version in README 2020-02-29 21:50:59 +01:00
Jonas Kvinge
7ae049b559 Require Qt 5.6 or higher 2020-02-29 21:50:10 +01:00
Jonas Kvinge
72913ceb1a Check that Qt version is higher than 5.9 to use QDir::isEmpty() 2020-02-29 21:40:20 +01:00
Jonas Kvinge
6a2be22fa1 Remove empty directories when organizing music
Fixes #353
2020-02-28 22:23:12 +01:00
Strawbs Bot
eaf20ce8d2 Update translations 2020-02-26 01:07:17 +01:00
Jonas Kvinge
97f9e142b4 Set hiDPI options 2020-02-25 01:15:05 +01:00
Jonas Kvinge
2e0f7b367f Remove tidal and qobuz
Fixes #369
2020-02-25 01:08:03 +01:00
Jonas Kvinge
7312e3f452 Find backtrace quiet 2020-02-23 20:42:30 +01:00
Strawbs Bot
8faa9f075b Update translations 2020-02-23 01:02:20 +01:00
Jonas Kvinge
584dcae075 Change variables 2020-02-22 17:39:06 +01:00
Jonas Kvinge
910e869b8d Use selectedRows() where possible 2020-02-22 15:31:25 +01:00
Jonas Kvinge
469e00b396 Remove setBaseStyle() 2020-02-22 13:43:33 +01:00
Strawbs Bot
ec46c758ba Update translations 2020-02-22 01:01:59 +01:00
Jonas Kvinge
8970e46bce More code fixes to mainwindow 2020-02-22 00:09:45 +01:00
Jonas Kvinge
3a4107d903 Workaround crash when mapToSource() fails 2020-02-21 22:42:21 +01:00
Jonas Kvinge
52ee21d550 Remove C++11Compat.cmake 2020-02-18 01:22:04 +01:00
Strawbs Bot
cdda4826cb Update translations 2020-02-18 01:02:19 +01:00
Jonas Kvinge
6745df5041 Update libffi 2020-02-17 20:22:02 +01:00
Jonas Kvinge
3d3efe1117 Remove extra whitespace 2020-02-17 20:21:45 +01:00
Strawbs Bot
82e5ae05ce Update translations 2020-02-17 01:01:39 +01:00
Strawbs Bot
0dbdd55a6a Update translations 2020-02-12 01:09:03 +01:00
Jonas Kvinge
424b0e61cb Remove extra newlines 2020-02-12 00:07:05 +01:00
Jonas Kvinge
533da8f89c Use isLocalFile() 2020-02-12 00:06:19 +01:00
Strawbs Bot
31506662db Update translations 2020-02-10 01:08:12 +01:00
Jonas Kvinge
7ff1a88ca8 Add QCoreApplication to xineengine.cpp 2020-02-09 04:20:22 +01:00
Jonas Kvinge
1851f26e3f Reduce includes 2020-02-09 02:29:35 +01:00
Jonas Kvinge
84cd65dd6c Reduce includes 2020-02-08 15:03:11 +01:00
Jonas Kvinge
8e0d792bf0 Reduce includes 2020-02-08 03:40:30 +01:00
Strawbs Bot
e74548b991 Update translations 2020-02-08 01:04:53 +01:00
Jonas Kvinge
2356ff5ebb Fix tabs order
Fixes #366
2020-02-08 00:01:12 +01:00
Gavin D. Howard
691f5d99ca Implement disk caching of album art (#360)
* Implement disk caching of album art

This includes a button to clear the cache in the settings, as
requested.

Closes #358

* Make the cache size defaults match

* Implement the review by jonaski

* Fix more problems with the PR
2020-02-07 23:18:18 +01:00
Jonas Kvinge
ab7b65a30b Remove chartlyrics 2020-02-06 22:33:38 +01:00
Daniel Kolesa
814bb3006c libstrawberry-common: check for library/includes for backtrace() (#364)
This is a non-standard header, so it should be checked properly.
This fixes compilation with musl libc and possibly other C library
implementations.
2020-02-06 20:04:23 +01:00
Jonas Kvinge
4bd4d3ae03 Update ccpp.yml 2020-02-06 18:40:05 +01:00
Jonas Kvinge
af1b0ace19 Use bultin taglib on Windows too by default 2020-02-06 18:37:02 +01:00
Jonas Kvinge
fb54febe03 Update .gitignore 2020-02-06 18:36:34 +01:00
Strawbs Bot
28faae5a4a Update translations 2020-01-29 01:03:25 +01:00
Jonas Kvinge
624a920aec Dont update temporary metadata while editing song with inline editor 2020-01-28 19:41:46 +01:00
Jonas Kvinge
2bf8187bff Add missing signal 2020-01-28 18:19:15 +01:00
Jonas Kvinge
cf06bf91e3 Change git url 2020-01-24 17:27:29 +01:00
Jonas Kvinge
e96f0504c0 Move related stuff into Rpm/Deb Cmake files 2020-01-21 23:53:28 +01:00
Jonas Kvinge
5fd61725bd Fixes for debian packaging 2020-01-21 23:15:15 +01:00
Jonas Kvinge
3fddfa075b Update .gitignore 2020-01-21 23:14:40 +01:00
Strawbs Bot
d712e5c409 Update translations 2020-01-21 01:01:48 +01:00
Jonas Kvinge
6287afae6c Fix Subsonic compatibility with LMS
Fixes #354
2020-01-20 19:19:14 +01:00
Jonas Kvinge
925540055a Use QString::number 2020-01-20 18:15:37 +01:00
Jonas Kvinge
d4373aae93 Subsonic: Handle album id as string 2020-01-20 17:45:40 +01:00
Jonas Kvinge
c4be310081 Use static taglib on windows 2020-01-16 20:46:10 +01:00
Jonas Kvinge
d1aa276465 Move -DTAGLIB_STATIC 2020-01-16 01:56:47 +01:00
Jonas Kvinge
2af6fc7452 Add -DTAGLIB_STATIC 2020-01-16 01:40:30 +01:00
Jonas Kvinge
ed15394a96 Delete qwindowsvistastyle.dll on uninstall 2020-01-15 23:12:08 +01:00
Jonas Kvinge
3791d11162 Disable libgstwasapi.dll 2020-01-15 17:12:18 +01:00
Jonas Kvinge
032ddabc06 Add qwindowsvistastyle.dll to nsi 2020-01-15 01:27:14 +01:00
Jonas Kvinge
bfb93ac6ed Update alsa in snap 2020-01-12 18:42:50 +01:00
Jonas Kvinge
f6d889d752 Add qtwayland5 to snap
Fixes #344
2020-01-12 18:02:13 +01:00
Jonas Kvinge
a7053f4269 Update README.md 2020-01-12 17:02:46 +01:00
Jonas Kvinge
233a6d06be Update README.md 2020-01-12 17:02:19 +01:00
Jonas Kvinge
853224148f Remove macOS builds 2020-01-12 16:56:19 +01:00
Jonas Kvinge
c5c8c27b2e Update README.md 2020-01-12 16:34:04 +01:00
Jonas Kvinge
d352d5fcff Turn back git revision 2020-01-07 21:41:31 +01:00
Strawbs Bot
0003de9320 Update translations 2020-01-07 01:01:46 +01:00
Jonas Kvinge
04f43e77af Update Changelog 2020-01-05 23:49:34 +01:00
Jonas Kvinge
be7cc55488 Release 0.6.8 2020-01-05 23:27:31 +01:00
Jonas Kvinge
c8f3379a48 Fix crash when deleting playlist folder. 2020-01-05 23:26:07 +01:00
Jonas Kvinge
b5a7945e49 Use QModelIndex::model() 2020-01-05 23:25:23 +01:00
Strawbs Bot
0bdac2e97d Update translations 2020-01-05 22:52:27 +01:00
Jonas Kvinge
1468a821fb Fix restoring to correct screen when maximized 2020-01-05 22:21:55 +01:00
Jonas Kvinge
3cdc8dc4b6 Use QWidget::screen() with Qt 5.14 2020-01-05 19:15:28 +01:00
Jonas Kvinge
aa255aa7e6 Use current screen, not primary screen 2020-01-05 19:14:25 +01:00
Strawbs Bot
66e5ccb9cc Update translations 2020-01-05 01:02:24 +01:00
Jonas Kvinge
2215f300bf Added option to disable playlist clear button
Fixes #339
2020-01-04 06:38:25 +01:00
Jonas Kvinge
eec767406b Add confirmation before clearing playlists with more than 500 songs 2020-01-04 06:11:21 +01:00
Jonas Kvinge
31aa42c2fa Fix compile with translations on Windows 2020-01-03 02:07:37 +01:00
Strawbs Bot
e912c59402 Add Italian 2020-01-03 01:46:38 +01:00
Strawbs Bot
c9988976f3 Update translations 2020-01-03 01:02:34 +01:00
Jonas Kvinge
443be1c2c8 Increase lyrics score if lyrics text > 60 2020-01-02 19:21:27 +01:00
Jonas Kvinge
7f442cff3b Fix QProxyStyle 2020-01-02 18:57:53 +01:00
Strawbs Bot
3696ae44ad Update translations 2019-12-31 01:09:52 +01:00
Jonas Kvinge
fc2d601424 Remove useless stdbool.h include 2019-12-30 23:14:40 +01:00
Jonas Kvinge
8818f24114 Fix compile with Qt 5.14 and above 2019-12-30 02:28:54 +01:00
Jonas Kvinge
0e12c8249e Fix actions builds 2019-12-30 00:49:39 +01:00
Strawbs Bot
06d62a70a9 Update translations 2019-12-30 00:35:45 +01:00
Jonas Kvinge
76d8018ca2 Remove HTML from translations 2019-12-29 23:53:54 +01:00
Jonas Kvinge
4123b41a5e Merge branch 'master' of github.com:jonaski/strawberry 2019-12-29 23:47:07 +01:00
Jonas Kvinge
5930257fed Remove HTML from translations 2019-12-29 23:46:49 +01:00
Jonas Kvinge
d3d60327ab Remove the answer to life the universe and everything 2019-12-29 23:46:35 +01:00
Strawbs Bot
5080ffb9fc Update translations 2019-12-29 23:41:39 +01:00
Jonas Kvinge
9b688a5179 Remove HTML from translations
Fixes #260
2019-12-29 23:37:48 +01:00
Strawbs Bot
a603dc5227 Update translations 2019-12-29 01:02:01 +01:00
Jonas Kvinge
c25f682caf Emit ExitFinished if no internet services are enabled 2019-12-28 03:35:07 +01:00
Jonas Kvinge
27a2fd298d Add the device view container widget to the tabbar
Fixes bugs related to the tabbar and the widgets being unresponsive

Fixes #279
Fixes #321
2019-12-28 03:13:41 +01:00
Strawbs Bot
bb38053cb3 Update translations 2019-12-24 01:01:42 +01:00
Strawbs Bot
5e82ee8695 Add German 2019-12-22 14:56:55 +01:00
Strawbs Bot
6c691ff9a8 Update translations 2019-12-22 14:55:33 +01:00
Jonas Kvinge
ac5a14fe4a Add StartupWMClass to desktop file
Fixes #305
2019-12-22 14:16:24 +01:00
Jonas Kvinge
00402d13ef Fix collection watcher on macOS
Fixes #324
2019-12-22 14:15:25 +01:00
Gavin D. Howard
079a559247 Make context title and summary changeable (#329)
* Make context title and summary changeable

Closes #30

* Fix checkboxes on context settings page

So...I am new to Qt, and I forgot that checkboxes can have a label.
Duh. Fixed.

* Put context settings in a different place

* Put ReplaceMessage and ReplaceVariable in Utilities
2019-12-22 12:09:05 +01:00
Strawbs Bot
a19ea8fdba Update translations 2019-12-22 01:04:20 +01:00
Jonas Kvinge
c6e172f942 Remove unused afc_port_ variable 2019-12-22 00:54:56 +01:00
Jonas Kvinge
bdc9f3e8bf Use AFC_E_SUCCESS 2019-12-22 00:45:01 +01:00
Jonas Kvinge
8ec5a587fc Fix compile 2019-12-21 22:34:42 +01:00
Jonas Kvinge
9caf46f2fb Use QString::asprintf 2019-12-21 22:07:04 +01:00
Jonas Kvinge
13fdbfc5e8 Use QString::asprintf 2019-12-21 21:56:48 +01:00
Jonas Kvinge
882c94110e Update temporary metadata when tags are changed 2019-12-21 21:55:24 +01:00
Jonas Kvinge
97bc980611 Upgrade packages 2019-12-21 18:26:51 +01:00
Jonas Kvinge
be9bf5c173 Replace use of QSet::fromList with Qt 5.14 and above 2019-12-21 18:22:18 +01:00
Jonas Kvinge
6df38c389c Replace use of QSet::toList() with QSet::values() 2019-12-21 18:19:09 +01:00
Jonas Kvinge
6c6bceb8cc Replace use of QString::sprintf 2019-12-21 18:17:58 +01:00
Jonas Kvinge
b5a897bb4d Replace use of QString::sprintf 2019-12-21 18:15:45 +01:00
Jonas Kvinge
ab85b716bb Replace use of QTime::start() with QElapsedTimer 2019-12-21 18:11:54 +01:00
Jonas Kvinge
8e256e6d5c Fix indent 2019-12-21 17:55:24 +01:00
Jonas Kvinge
288036a63b Fix spelling 2019-12-21 17:54:43 +01:00
Jonas Kvinge
f2005c3343 Update README.md 2019-12-11 20:46:15 +01:00
Jonas Kvinge
79d516b899 Update README.md 2019-12-11 20:45:27 +01:00
Jonas Kvinge
28b2f6eae3 Update README.md 2019-12-11 20:21:03 +01:00
Strawbs Bot
09ed2b945c Update translations 2019-12-07 12:45:08 +01:00
Jonas Kvinge
74aec89ef0 Add French 2019-12-05 19:58:07 +01:00
Jonas Kvinge
4faa23d099 Add Indonesian 2019-12-05 19:57:14 +01:00
Jonas Kvinge
5c4997ab20 Turn back git revision 2019-12-05 19:53:41 +01:00
Jonas Kvinge
cd490ca946 Release 0.6.7 2019-11-27 23:09:49 +01:00
Jonas Kvinge
793f6b00e6 Allow 4 tagreader workers 2019-11-27 22:57:51 +01:00
Strawbs Bot
c1ec568fda Update translations 2019-11-27 01:03:22 +01:00
Jonas Kvinge
4e2b52975e Remove require for sqlite on centos since we use customized sqlite 2019-11-26 23:43:34 +01:00
Jonas Kvinge
c141df6b86 Remove low-latency setting for wasapisink 2019-11-26 22:30:56 +01:00
Jonas Kvinge
63b781765a Update copyrights 2019-11-26 22:30:14 +01:00
Jonas Kvinge
c121e141e7 Remove duplicate entries in Changelog 2019-11-26 22:29:13 +01:00
Jonas Kvinge
7544c9a9f5 Update nsi with libprotobuf-22.dll 2019-11-26 19:42:38 +01:00
Jonas Kvinge
722a088515 Only remove pixmap cache when removing parents in collection model 2019-11-26 19:42:05 +01:00
Jonas Kvinge
0ce75bff58 Remove unused code in context albums 2019-11-26 19:41:32 +01:00
Strawbs Bot
3744b6d3de Update translations 2019-11-26 01:02:03 +01:00
Jonas Kvinge
a4ebd91e8d Make sure QSqlQuery::exec() was successful 2019-11-25 22:43:09 +01:00
Jonas Kvinge
3bb0ee916d Update Changelog 2019-11-25 22:31:42 +01:00
Jonas Kvinge
fd6afdf5f3 Extend url test 2019-11-25 22:30:33 +01:00
Jonas Kvinge
47c13a840e Handle different urls in collection backend for backward compatibility 2019-11-25 22:29:12 +01:00
Jonas Kvinge
5b61992b3c Save cover urls encoded 2019-11-25 22:28:48 +01:00
Jonas Kvinge
36331dc253 Fix removing nodes from pending art 2019-11-25 22:25:29 +01:00
Strawbs Bot
4265cf31b2 Update translations 2019-11-25 01:05:00 +01:00
Jonas Kvinge
337e47269f Remove portable, we dont use it 2019-11-25 00:35:48 +01:00
Jonas Kvinge
7039234471 Fix compile collection model test 2019-11-25 00:35:16 +01:00
Jonas Kvinge
f7f9333d91 Add collection backend url tests 2019-11-25 00:34:59 +01:00
Jonas Kvinge
bf35665932 Update all songs for the same directory+album when updating compilations
- Fixes a bug where the songs are stuck in various artists, because the
album has child songs, it will be stuck with various artists as the
parent node.
2019-11-25 00:28:49 +01:00
Jonas Kvinge
089a2271c2 Add GitHub Actions 2019-11-24 20:04:05 +01:00
Jonas Kvinge
f8e83e3631 Fix loading replay gain setting
Fixes #311
2019-11-24 19:34:05 +01:00
Strawbs Bot
46fd329913 Update translations 2019-11-23 01:07:52 +01:00
Jonas Kvinge
6b9ba96e77 Revert "Tidal: Add explicit to album titles"
This reverts commit b7d360d850.
2019-11-21 22:55:39 +01:00
Jonas Kvinge
b7d360d850 Tidal: Add explicit to album titles 2019-11-20 22:13:28 +01:00
Jonas Kvinge
8e226302ab Allow scrobbling songs without album
Fixes #309
2019-11-20 21:30:41 +01:00
Jonas Kvinge
7795b9edaf Dont replace metadata when loading playlists 2019-11-20 19:34:57 +01:00
Jonas Kvinge
9375d9699a No 2019-11-19 21:51:15 +01:00
Jonas Kvinge
cf0442d5b8 Fix setting pixmap cache limit 2019-11-19 21:49:46 +01:00
Jonas Kvinge
b386ca14df Show fullsize cover on doubleclick 2019-11-19 21:20:36 +01:00
Jonas Kvinge
ea47fae31e Add seperator between "unset cover" and "show fullsize" 2019-11-19 21:19:44 +01:00
Jonas Kvinge
e0fed07b10 Change pixmap cache limit 2019-11-19 21:03:06 +01:00
Jonas Kvinge
779d5ff7b6 Dont reset pixmap cache on model reset 2019-11-19 20:56:03 +01:00
Jonas Kvinge
eb6fbd03ec Update Changelog 2019-11-19 20:49:54 +01:00
Jonas Kvinge
95409d1b0e Remove unused variables 2019-11-19 20:47:06 +01:00
Jonas Kvinge
49599c8731 Add back ChartLyrics
This reverts commit c992768efe.
2019-11-19 20:45:22 +01:00
Jonas Kvinge
572f94e000 Update Changelog 2019-11-18 17:25:57 +01:00
Jonas Kvinge
c0a2ad5f50 Change comment 2019-11-18 17:16:58 +01:00
Jonas Kvinge
71fa5acc74 Fix previous player and doubleclick playlist song behaviour settings 2019-11-17 23:46:10 +01:00
Jonas Kvinge
bac5b7679d Use killproc.exe instead in nsi 2019-11-17 16:34:30 +01:00
Strawbs Bot
93ade821a5 Update translations 2019-11-17 01:10:32 +01:00
Jonas Kvinge
a718e19979 Use KillProc in nsi 2019-11-15 23:25:12 +01:00
Jonas Kvinge
8ac83a46f5 Remove clang compiler flag 2019-11-15 23:24:37 +01:00
Jonas Kvinge
1b65dcd7df Fix comparison between signed/unsigned 2019-11-15 00:23:06 +01:00
Jonas Kvinge
bbad45f1e7 Minor cmake fixes 2019-11-15 00:22:41 +01:00
Jonas Kvinge
331b9cca18 Remove sudo 2019-11-14 21:23:50 +01:00
Jonas Kvinge
a9accb7d85 Refactor scrobbler authentication code
Fix a crash when authentication is cancelled
2019-11-14 21:07:30 +01:00
Jonas Kvinge
1862e70628 Declare song using source 2019-11-14 00:09:35 +01:00
Jonas Kvinge
c4f7054ca6 Use QUrl::FullyEncoded in update compilations 2019-11-13 23:51:04 +01:00
Jonas Kvinge
175e568a28 Minor improvements to update compilations 2019-11-13 21:27:04 +01:00
Jonas Kvinge
c8d580e7de No need to delete pixmap cache when deleting empty parents 2019-11-13 21:16:48 +01:00
Jonas Kvinge
bc0c50ee65 Remove commented code 2019-11-13 21:12:50 +01:00
Jonas Kvinge
45e9dd96d1 Remove left click on analyzer to popup menu
Fixes #294
2019-11-11 00:01:39 +01:00
Jonas Kvinge
1cc73562a3 Turn back git revision 2019-11-10 15:35:36 +01:00
Jonas Kvinge
d870ef0bd5 Release 0.6.6 2019-11-09 17:21:08 +01:00
Jonas Kvinge
53d308dac5 Exclude .github dir in maketarball.sh 2019-11-09 17:16:18 +01:00
Jonas Kvinge
89b06ae7c7 Mulitply samples by channels, dont hardcode to 2 2019-11-09 16:34:17 +01:00
Jonas Kvinge
d38485a8ad Update Changelog 2019-11-09 16:30:23 +01:00
Jonas Kvinge
834877c503 Refactor gstreamer engine code, equalizer and fix stereo balancer 2019-11-08 23:07:21 +01:00
Jonas Kvinge
d033b79af4 Remove exclusive for wasapisink
Fixes #283
2019-11-07 20:26:25 +01:00
Jonas Kvinge
daec2cc203 Remove g_type_init 2019-11-06 21:53:27 +01:00
Jonas Kvinge
4e593cebab Add const 2019-11-06 21:53:09 +01:00
Jonas Kvinge
73d7701e94 Update FUNDING.yml 2019-11-05 19:38:46 +01:00
Strawbs Bot
24f1d7a72f Update translations 2019-11-04 01:07:14 +01:00
Jonas Kvinge
6387a01d7b Fix updating compilations
Fixes #288
2019-11-03 23:23:04 +01:00
Jonas Kvinge
e838840548 Remove duplicate check 2019-11-03 19:56:10 +01:00
Jonas Kvinge
6a430b441e Remove debug line 2019-11-03 19:56:01 +01:00
Jonas Kvinge
7b977ea839 Rename EngineDevice --> DeviceFinders, Add MMDeviceFinder 2019-11-03 19:53:08 +01:00
Jonas Kvinge
62b8521cbe Update Changelog 2019-10-29 19:27:03 +01:00
Martin Delille
308244d901 Change email (#287)
I didn't noticed you mention me in the *About...* section. Thank you for that even if it is an oversized thank you for the contributions made! : sweat_smile:

I just update it to my personal address.
2019-10-29 19:12:29 +01:00
Jonas Kvinge
6f521183f9 Fix spelling 2019-10-28 20:20:13 +01:00
Jonas Kvinge
76c6f7e733 Update README.md 2019-10-28 20:06:22 +01:00
Strawbs Bot
80ebfbeb6b Update translations 2019-10-28 01:02:39 +01:00
Jonas Kvinge
793901b319 Revert accidental change to flac test file 2019-10-28 00:05:29 +01:00
Jonas Kvinge
3950df8ec9 Add libgstwasapi.dll to nsi 2019-10-27 23:55:03 +01:00
Jonas Kvinge
e800b236aa Simplify the pipeline
Fix issue where bitrate is updated incorrectly by stream discoverer
Fixes issue #282
Also make it possible to enable stereo balancer without enabling the
equalizer
2019-10-27 23:48:54 +01:00
Jonas Kvinge
4ab7871106 Add wasapisink to directsound devicefinder 2019-10-27 23:47:28 +01:00
Jonas Kvinge
3de85549b6 Add option to automatically select current playing track 2019-10-27 02:11:51 +01:00
Jonas Kvinge
73164f7182 Update scrobble point when song is restarted 2019-10-27 02:09:34 +01:00
Strawbs Bot
004b000890 Update translations 2019-10-21 01:23:16 +02:00
Jonas Kvinge
d9c703d944 Add gst/audio/audio.h include 2019-10-20 20:04:23 +02:00
Jonas Kvinge
364b650033 Convert S32LE to S16LE for analyzer 2019-10-20 18:52:58 +02:00
Jonas Kvinge
156eb874db Fix analyzer and cleanup old pipeline code
- Move HandoffCallback to audio queue
- Add new callback for detecting source format
- Remove old decodebin stuff
2019-10-20 02:56:47 +02:00
Strawbs Bot
1a28dd0311 Update translations 2019-10-20 01:24:47 +02:00
Jonas Kvinge
e29b4b8609 Add more alternative icon names 2019-10-20 01:11:40 +02:00
Jonas Kvinge
c02997e6d9 More icon fixes 2019-10-20 00:59:22 +02:00
Jonas Kvinge
7c9fc91af9 Enable system theme icons, add iconmapper and rename some icon names 2019-10-20 00:17:28 +02:00
Jonas Kvinge
cf5198ac64 Limit tagreader workers to 2 2019-10-19 15:09:18 +02:00
Strawbs Bot
e76ddd6dd2 Update translations 2019-10-19 14:56:24 +02:00
Jonas Kvinge
e3a4cf1cf5 Add option to prefer album artist when sending scrobbles
Fixes #274
2019-10-19 02:56:23 +02:00
Jonas Kvinge
5844616ea8 Only ignore closeEvent when minimizing to system tray
Fixes #277
2019-10-19 02:21:20 +02:00
Jonas Kvinge
abeb580228 Disable analyzer for other bit depths than 16
This removes the splitting of the pipeline with the tee.
Move HandoffCallback to the source, which makes it possible to convert the audio buffer in HandoffCallback later.
Until then just disable analyzer for other formats.

Removes tee and probe queue converter and sink
2019-10-19 01:45:24 +02:00
Ike Devolder
4d888dfce8 subsonic: change disc to discNumber (#278)
As found in the v1.13.0 xsd, the disc is named discNumber in the api,
currently there is a check for disc which will never be found in the
response.

@see http://www.subsonic.org/pages/inc/api/schema/subsonic-rest-api-1.13.0.xsd

Signed-off-by: BlackEagle <ike.devolder@gmail.com>
2019-10-17 17:06:30 +02:00
Jonas Kvinge
08ff6f0ede Only use gcc 2019-10-13 00:17:01 +02:00
Jonas Kvinge
c458c27231 Switch to opensuse leap 15.1 2019-10-12 23:49:41 +02:00
Jonas Kvinge
9821b70c38 Dont use gst_caps_to_string as it causes hang with some formats 2019-10-12 01:58:01 +02:00
Jonas Kvinge
8ab8401110 Update libprotobuf in nsi 2019-10-06 17:53:00 +02:00
Strawbs Bot
4f798c85cf Update translations 2019-10-05 01:01:44 +02:00
Jonas Kvinge
1949bdb43f Merge branch 'master' of github.com:jonaski/strawberry 2019-10-04 17:09:08 +02:00
Jonas Kvinge
8cf2e6b31b Remove all lines in settings 2019-10-04 17:08:35 +02:00
Jonas Kvinge
b1069f9f18 Disable use system icons option 2019-10-04 17:08:12 +02:00
Strawbs Bot
fb8dfa9ae9 Update translations 2019-10-04 01:07:02 +02:00
Jonas Kvinge
4402a56e94 Fix compile with optional components disabled 2019-10-03 23:29:52 +02:00
Jonas Kvinge
f449808ba3 Fix: imobiledevice depends on libgpod enabled 2019-10-03 22:54:40 +02:00
Jonas Kvinge
5599739433 Fix lowercased playlist album artist column
Fixes #275
2019-10-03 18:25:50 +02:00
Jonas Kvinge
197cf85f56 Turn back git revision 2019-10-01 21:42:08 +02:00
1174 changed files with 97454 additions and 45612 deletions

631
.circleci/config.yml Normal file
View File

@@ -0,0 +1,631 @@
version: 2.1
commands:
cmake:
description: Configure build
steps:
- run:
name: Configure build
command: cmake ..
working_directory: build
build_source:
description: Create source tarball
steps:
- run:
name: Create source tarball
command: ../dist/scripts/maketarball.sh
working_directory: build
build_rpm:
description: Build RPM
steps:
- run:
name: Create RPM build sources directories
command: mkdir -p ~/rpmbuild/SOURCES /usr/src/packages/SOURCES
- run:
name: Copy source tarball 1
command: cp strawberry-*.tar.xz ~/rpmbuild/SOURCES/
working_directory: build
- run:
name: Copy source tarball 2
command: cp strawberry-*.tar.xz /usr/src/packages/SOURCES/
working_directory: build
- run:
name: Build RPM
command: rpmbuild -ba ../dist/unix/strawberry.spec
working_directory: build
build_deb:
description: Build Deb
steps:
- run:
name: make deb
command: dpkg-buildpackage -b -d -uc -us -nc -j2
install_opensuse_dependencies:
description: Install openSUSE dependencies
steps:
- run:
name: Update packages
command: zypper --non-interactive --gpg-auto-import-keys ref
- run:
name: Install openSUSE dependencies
command: >
zypper --non-interactive --gpg-auto-import-keys install
lsb-release
rpm-build
git
tar
make
cmake
gcc
gcc-c++
gettext-tools
glibc-devel
libboost_headers-devel
boost-devel
glib2-devel
glib2-tools
dbus-1-devel
alsa-devel
libnotify-devel
libgnutls-devel
protobuf-devel
sqlite3-devel
libpulse-devel
gstreamer-devel
gstreamer-plugins-base-devel
libxine-devel
vlc-devel
libQt5Core-devel
libQt5Gui-devel
libQt5Widgets-devel
libQt5Concurrent-devel
libQt5Network-devel
libQt5Sql-devel
libQt5DBus-devel
libQt5Test-devel
libqt5-qtx11extras-devel
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libcdio-devel
libgpod-devel
libplist-devel
libmtp-devel
libusbmuxd-devel
libchromaprint-devel
desktop-file-utils
update-desktop-files
appstream-glib
hicolor-icon-theme
install_fedora_dependencies:
description: Install Fedora dependencies
steps:
- run:
name: Update packages
command: yum update --assumeyes
- run:
name: Upgrade packages
command: yum upgrade --assumeyes
- run:
name: Install Fedora dependencies
command: >
dnf install --assumeyes
@development-tools
redhat-lsb-core
git
glibc
gcc-c++
rpmdevtools
make
cmake
pkgconfig
glib
man
tar
gettext
openssh
boost-devel
dbus-devel
protobuf-devel
protobuf-compiler
sqlite-devel
alsa-lib-devel
pulseaudio-libs-devel
libnotify-devel
gnutls-devel
qt5-qtbase-devel
qt5-qtx11extras-devel
qt5-qttools-devel
gstreamer1-devel
gstreamer1-plugins-base-devel
taglib-devel
libcdio-devel
libgpod-devel
libplist-devel
libusbmuxd-devel
libmtp-devel
libchromaprint-devel
fftw-devel
desktop-file-utils
libappstream-glib
hicolor-icon-theme
install_centos_dependencies:
description: Install CentOS dependencies
steps:
- run:
name: Install epel-release
command: dnf install -y epel-release
- run:
name: Install epel-release-latest-8.noarch.rpm
command: dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
- run:
name: Install config-manager
command: dnf install -y 'dnf-command(config-manager)'
- run:
name: PowerTools
command: dnf config-manager --set-enabled PowerTools
- run:
name: DNF Clean All
command: dnf clean all
- run:
name: Update packages
command: dnf update -y
- run:
name: Install CentOS dependencies
command: >
dnf install -y
glibc
gcc-c++
make
libtool
cmake3
rpmdevtools
redhat-lsb-core
git
man
tar
gettext
boost-devel
fuse-devel
dbus-devel
libnotify-devel
gnutls-devel
sqlite-devel
protobuf-devel
protobuf-compiler
alsa-lib-devel
pulseaudio-libs-devel
qt5-devel
qt5-qtbase-devel
qt5-qtx11extras-devel
qt5-qttools-devel
fftw-devel
libchromaprint-devel
libcdio-devel
libgpod-devel
libplist-devel
libusbmuxd-devel
libmtp-devel
libjpeg-devel
cairo-devel
dbus-x11
xorg-x11-server-Xvfb
xorg-x11-xauth
vim-common
desktop-file-utils
libappstream-glib
appstream-data
hicolor-icon-theme
python3-pip
python3-devel
gstreamer1-devel
gstreamer1-plugins-base-devel
install_mageia_dependencies:
description: Install Mageia dependencies
steps:
- run:
name: Update packages
command: urpmi.update -a
- run:
name: Configure auto update
command: urpmi --auto-update
- run:
name: Install dependencies
command: >
urpmi --force
urpmi-debuginfo-install
git
tar
rpmdevtools
make
cmake
glibc
binutils
gcc-c++
man
gettext
notification-daemon
dbus-devel
libgnutls-devel
lib64boost-devel
lib64protobuf-devel
protobuf-compiler
lib64sqlite3-devel
lib64alsa2-devel
lib64pulseaudio-devel
lib64notify-devel
lib64qt5core-devel
lib64qt5gui-devel
lib64qt5widgets-devel
lib64qt5network-devel
lib64qt5concurrent-devel
lib64qt5sql-devel
lib64qt5dbus-devel
lib64qt5x11extras-devel
lib64qt5help-devel
libqt5test-devel
lib64gstreamer1.0-devel
lib64gstreamer-plugins-base1.0-devel
lib64cdio-devel
lib64gpod-devel
lib64plist-devel
lib64usbmuxd-devel
lib64mtp-devel
lib64raw1394-devel
lib64chromaprint-devel
libfftw-devel
desktop-file-utils
appstream-util
libappstream-glib8
hicolor-icon-theme
qt5ct
lib64mesaegl1
install_debian_dependencies:
description: Install Debian dependencies
steps:
- run:
name: Install Debian dependencies
command: >
apt-get update && apt-get install -y
build-essential
ssh
git
make
cmake
gcc
pkg-config
fakeroot
gettext
lsb-release
libglib2.0-dev
dpkg-dev
libdbus-1-dev
libboost-dev
libprotobuf-dev
protobuf-compiler
libsqlite3-dev
libgnutls28-dev
libasound2-dev
libpulse-dev
qtbase5-dev
qtbase5-dev-tools
qtbase5-private-dev
libqt5x11extras5-dev
qttools5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
gstreamer1.0-alsa
gstreamer1.0-pulseaudio
libchromaprint-dev
libfftw3-dev
libcdio-dev
libmtp-dev
libgpod-dev
libimobiledevice-dev
libplist-dev
libusbmuxd-dev
install_ubuntu_dependencies:
description: Install Ubuntu dependencies
steps:
- run:
name: Setup environment
command: |
echo 'export DEBIAN_FRONTEND=noninteractive' >> $BASH_ENV
source $BASH_ENV
- run:
name: Install Ubuntu dependencies
command: >
apt-get update && apt-get install -y
build-essential
ssh
git
make
cmake
pkg-config
gcc
fakeroot
wget
curl
gettext
lsb-release
dpkg-dev
libglib2.0-dev
libboost-dev
libdbus-1-dev
libprotobuf-dev
protobuf-compiler
libsqlite3-dev
libgnutls28-dev
libasound2-dev
libpulse-dev
qtbase5-dev
qtbase5-dev-tools
qtbase5-private-dev
libqt5x11extras5-dev
qttools5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev
gstreamer1.0-alsa
gstreamer1.0-pulseaudio
libchromaprint-dev
libfftw3-dev
libcdio-dev
libmtp-dev
libgpod-dev
libimobiledevice-dev
libplist-dev
libusbmuxd-dev
jobs:
build_source:
docker:
- image: opensuse/leap:15.1
steps:
- install_opensuse_dependencies
- checkout
- cmake
- build_source
build_opensuse_tumbleweed:
docker:
- image: opensuse/tumbleweed
environment:
RPM_BUILD_NCPUS: "2"
steps:
- run:
name: Update packages
command: zypper --non-interactive --gpg-auto-import-keys ref
- run:
name: Upgrade packages
command: zypper --non-interactive --gpg-auto-import-keys dup
- install_opensuse_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_opensuse_lp151:
docker:
- image: opensuse/leap:15.1
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_opensuse_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_opensuse_lp152:
docker:
- image: opensuse/leap:15.2
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_opensuse_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_fedora_31:
docker:
- image: fedora:31
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_fedora_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_fedora_32:
docker:
- image: fedora:32
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_fedora_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_centos_8:
docker:
- image: centos:8
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_centos_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_mageia_7:
docker:
- image: mageia:7
environment:
RPM_BUILD_NCPUS: "2"
steps:
- install_mageia_dependencies
- checkout
- cmake
- build_source
- build_rpm
build_debian_stretch:
docker:
- image: debian:stretch
steps:
- install_debian_dependencies
- checkout
- cmake
- build_deb
build_debian_buster:
docker:
- image: debian:buster
steps:
- install_debian_dependencies
- checkout
- cmake
- build_deb
build_debian_bullseye:
docker:
- image: debian:bullseye
steps:
- install_debian_dependencies
- checkout
- cmake
- build_deb
build_ubuntu_bionic:
docker:
- image: ubuntu:bionic
steps:
- install_ubuntu_dependencies
- checkout
- cmake
- build_deb
build_ubuntu_focal:
docker:
- image: ubuntu:focal
steps:
- install_ubuntu_dependencies
- checkout
- cmake
- build_deb
build_ubuntu_groovy:
docker:
- image: ubuntu:groovy
steps:
- install_ubuntu_dependencies
- checkout
- cmake
- build_deb
workflows:
version: 2
build_all:
jobs:
- build_source:
filters:
tags:
only: /.*/
- build_opensuse_tumbleweed:
filters:
tags:
only: /.*/
- build_opensuse_lp151:
filters:
tags:
only: /.*/
- build_opensuse_lp152:
filters:
tags:
only: /.*/
- build_fedora_31:
filters:
tags:
only: /.*/
- build_fedora_32:
filters:
tags:
only: /.*/
- build_mageia_7:
filters:
tags:
only: /.*/
- build_centos_8:
filters:
tags:
only: /.*/
- build_debian_stretch:
filters:
tags:
only: /.*/
- build_debian_buster:
filters:
tags:
only: /.*/
- build_debian_bullseye:
filters:
tags:
only: /.*/
- build_ubuntu_bionic:
filters:
tags:
only: /.*/
- build_ubuntu_focal:
filters:
tags:
only: /.*/
- build_ubuntu_groovy:
filters:
tags:
only: /.*/

2
.github/FUNDING.yml vendored
View File

@@ -1 +1 @@
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FRJUYV5QP6HW8 github: jonaski

View File

@@ -7,6 +7,8 @@ assignees: ''
--- ---
For general technical questions and help with technical issues please use the forum on https://forum.strawberrymusicplayer.org/
**Describe the bug** **Describe the bug**
A clear and concise description of what the bug is. A clear and concise description of what the bug is.

View File

@@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

1154
.github/workflows/ccpp.yml vendored Normal file

File diff suppressed because it is too large Load Diff

5
.gitignore vendored
View File

@@ -73,6 +73,11 @@ CMakeLists.txt.user*
target_wrapper.* target_wrapper.*
compile_commands.json compile_commands.json
*.kdev4
*.vscode
*.code-workspace
*.sublime-workspace
# Temporary files # Temporary files
*~ *~
*.autosave *.autosave

View File

@@ -1,13 +1,11 @@
sudo: required sudo: required
language: C++ language: C++
os: os:
- linux
- osx - osx
services: services:
- docker - docker
compiler: compiler:
- gcc - gcc
- clang
before_install: before_install:
- if ! [ "$DEPLOY_KEY_ENC" == "" ]; then - if ! [ "$DEPLOY_KEY_ENC" == "" ]; then
@@ -17,21 +15,20 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
docker build -f Dockerfile -t strawberry-build . || travis_terminate 1; docker build -f Dockerfile -t strawberry-build . || travis_terminate 1;
docker run --name build -itd strawberry-build /bin/bash || travis_terminate 1; docker run --name build -itd strawberry-build /bin/bash || travis_terminate 1;
docker exec build git clone https://github.com/jonaski/strawberry; docker exec build git clone https://github.com/strawberrymusicplayer/strawberry;
fi fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
git fetch --unshallow || travis_terminate 1; git fetch --unshallow || travis_terminate 1;
git pull || travis_terminate 1; git pull || travis_terminate 1;
brew update || travis_terminate 1; brew unlink python@2 || travis_terminate 1;
brew unlink python || travis_terminate 1; brew install glib pkgconfig libffi protobuf protobuf-c qt gettext gnutls fftw sqlite chromaprint zlib taglib;
brew install glib pkgconfig libffi protobuf protobuf-c qt gettext gnutls fftw sqlite chromaprint;
brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav; brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav;
brew install libcdio libmtp libimobiledevice libplist; brew install libcdio libmtp libimobiledevice libplist;
brew install create-dmg; brew install create-dmg;
export Qt5_DIR=/usr/local/opt/qt5/lib/cmake; export Qt5_DIR=/usr/local/opt/qt5/lib/cmake;
export Qt5LinguistTools_DIR=/usr/local/opt/qt5/lib/cmake/Qt5LinguistTools; export Qt5LinguistTools_DIR=/usr/local/opt/qt5/lib/cmake/Qt5LinguistTools;
export PATH="/usr/local/opt/gettext/bin:$PATH"; export PATH="/usr/local/opt/gettext/bin:$PATH";
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig/:$PKG_CONFIG_PATH; export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig/:/usr/local/opt/zlib/lib/pkgconfig:$PKG_CONFIG_PATH";
ls /usr/local/lib/gstreamer-1.0; ls /usr/local/lib/gstreamer-1.0;
fi fi
before_script: before_script:
@@ -42,7 +39,7 @@ script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
make -j8 || travis_terminate 1; make -j8 || travis_terminate 1;
make install || travis_terminate 1; make install || travis_terminate 1;
sudo make dmg; make dmg;
fi fi
after_success: after_success:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls -lh strawberry*.dmg; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls -lh strawberry*.dmg; fi
@@ -50,7 +47,7 @@ after_success:
if [[ "$TRAVIS_BRANCH" == "master" ]]; then if [[ "$TRAVIS_BRANCH" == "master" ]]; then
rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos; rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos;
elif [[ "$TRAVIS_BRANCH" == "macos" ]]; then elif [[ "$TRAVIS_BRANCH" == "macos" ]]; then
rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos-test; rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos;
fi fi
fi fi

View File

@@ -1,16 +1,8 @@
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 3.0)
include(CheckIncludeFiles) include(CheckIncludeFiles)
include(CheckFunctionExists) include(CheckFunctionExists)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -Wall -Woverloaded-virtual -Wno-sign-compare -fpermissive")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wpedantic")
endif()
if(CMAKE_VERSION VERSION_GREATER 3.0) if(CMAKE_VERSION VERSION_GREATER 3.0)
check_function_exists(geteuid HAVE_GETEUID) check_function_exists(geteuid HAVE_GETEUID)
check_function_exists(getpwuid HAVE_GETPWUID) check_function_exists(getpwuid HAVE_GETPWUID)
@@ -19,14 +11,37 @@ endif()
set(SINGLEAPP-SOURCES singleapplication.cpp singleapplication_p.cpp) set(SINGLEAPP-SOURCES singleapplication.cpp singleapplication_p.cpp)
set(SINGLEAPP-MOC-HEADERS singleapplication.h singleapplication_p.h) set(SINGLEAPP-MOC-HEADERS singleapplication.h singleapplication_p.h)
QT5_WRAP_CPP(SINGLEAPP-SOURCES-MOC ${SINGLEAPP-MOC-HEADERS}) QT5_WRAP_CPP(SINGLEAPP-SOURCES-MOC ${SINGLEAPP-MOC-HEADERS})
ADD_LIBRARY(singleapplication STATIC ${SINGLEAPP-SOURCES} ${SINGLEAPP-SOURCES-MOC}) add_library(singleapplication STATIC ${SINGLEAPP-SOURCES} ${SINGLEAPP-SOURCES-MOC})
target_link_libraries(singleapplication Qt5::Core Qt5::Widgets Qt5::Network) target_include_directories(singleapplication SYSTEM PRIVATE
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
)
target_include_directories(singleapplication PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(singleapplication PRIVATE
${Qt5Core_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Network_LIBRARIES}
)
set(SINGLECOREAPP-SOURCES singlecoreapplication.cpp singlecoreapplication_p.cpp) set(SINGLECOREAPP-SOURCES singlecoreapplication.cpp singlecoreapplication_p.cpp)
set(SINGLECOREAPP-MOC-HEADERS singlecoreapplication.h singlecoreapplication_p.h) set(SINGLECOREAPP-MOC-HEADERS singlecoreapplication.h singlecoreapplication_p.h)
QT5_WRAP_CPP(SINGLECOREAPP-SOURCES-MOC ${SINGLECOREAPP-MOC-HEADERS}) QT5_WRAP_CPP(SINGLECOREAPP-SOURCES-MOC ${SINGLECOREAPP-MOC-HEADERS})
ADD_LIBRARY(singlecoreapplication STATIC ${SINGLECOREAPP-SOURCES} ${SINGLECOREAPP-SOURCES-MOC}) add_library(singlecoreapplication STATIC ${SINGLECOREAPP-SOURCES} ${SINGLECOREAPP-SOURCES-MOC})
target_link_libraries(singlecoreapplication Qt5::Core Qt5::Widgets Qt5::Network) target_include_directories(singlecoreapplication SYSTEM PRIVATE
${Qt5Core_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
)
target_include_directories(singlecoreapplication PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(singlecoreapplication PRIVATE
${Qt5Core_LIBRARIES}
${Qt5Network_LIBRARIES}
)
configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h") configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

View File

@@ -31,13 +31,22 @@
// //
// //
#include <cstdlib>
#include <limits>
#include <QtGlobal> #include <QtGlobal>
#include <QCoreApplication> #include <QCoreApplication>
#include <QThread> #include <QThread>
#include <QSharedMemory> #include <QSharedMemory>
#include <QLocalSocket>
#include <QByteArray> #include <QByteArray>
#include <QElapsedTimer>
#include <QtDebug>
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
# include <QRandomGenerator>
#else
# include <QDateTime> # include <QDateTime>
#include <QTime> #endif
#include "singleapplication.h" #include "singleapplication.h"
#include "singleapplication_p.h" #include "singleapplication_p.h"
@@ -88,7 +97,7 @@ SingleApplication::SingleApplication(int &argc, char *argv[], bool allowSecondar
} }
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data()); InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data());
QTime time; QElapsedTimer time;
time.start(); time.start();
// Make sure the shared memory block is initialised and in consistent state // Make sure the shared memory block is initialised and in consistent state
@@ -105,8 +114,12 @@ SingleApplication::SingleApplication(int &argc, char *argv[], bool allowSecondar
d->memory->unlock(); d->memory->unlock();
// Random sleep here limits the probability of a collision between two racing apps // Random sleep here limits the probability of a collision between two racing apps
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QThread::sleep(QRandomGenerator::global()->bounded(8u, 18u));
#else
qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max()); qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max());
QThread::sleep(8 + static_cast<unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10)); QThread::sleep(8 + static_cast<unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10));
#endif
} }
if (inst->primary == false) { if (inst->primary == false) {

View File

@@ -36,7 +36,8 @@
#include <QtGlobal> #include <QtGlobal>
#include <QApplication> #include <QApplication>
#include <QLocalSocket> #include <QFlags>
#include <QByteArray>
class SingleApplicationPrivate; class SingleApplicationPrivate;
@@ -91,7 +92,7 @@ public:
* @see See the corresponding QAPPLICATION_CLASS constructor for reference * @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/ */
explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 ); explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleApplication(); ~SingleApplication() override;
/** /**
* @brief Returns if the instance is the primary instance * @brief Returns if the instance is the primary instance

View File

@@ -44,12 +44,14 @@
# include <pwd.h> # include <pwd.h>
#endif #endif
#include <QDir> #include <QIODevice>
#include <QSharedMemory>
#include <QByteArray> #include <QByteArray>
#include <QDataStream> #include <QDataStream>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QLocalServer> #include <QLocalServer>
#include <QLocalSocket> #include <QLocalSocket>
#include <QDir>
#include "singleapplication.h" #include "singleapplication.h"
#include "singleapplication_p.h" #include "singleapplication_p.h"
@@ -59,8 +61,8 @@
# include <lmcons.h> # include <lmcons.h>
#endif #endif
SingleApplicationPrivate::SingleApplicationPrivate(SingleApplication *q_ptr) SingleApplicationPrivate::SingleApplicationPrivate(SingleApplication *_q_ptr)
: q_ptr(q_ptr), : q_ptr(_q_ptr),
memory(nullptr), memory(nullptr),
socket(nullptr), socket(nullptr),
server(nullptr), server(nullptr),
@@ -114,13 +116,10 @@ void SingleApplicationPrivate::genBlockServerName() {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QByteArray username; QByteArray username;
#if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID) #if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID)
uid_t uid = geteuid(); struct passwd *pw = getpwuid(geteuid());
if (uid != -1) {
struct passwd *pw = getpwuid(uid);
if (pw) { if (pw) {
username = pw->pw_name; username = pw->pw_name;
} }
}
#endif #endif
if (username.isEmpty()) username = qgetenv("USER"); if (username.isEmpty()) username = qgetenv("USER");
appData.addData(username); appData.addData(username);
@@ -187,7 +186,7 @@ void SingleApplicationPrivate::startPrimary() {
void SingleApplicationPrivate::startSecondary() {} void SingleApplicationPrivate::startSecondary() {}
void SingleApplicationPrivate::connectToPrimary(int msecs, ConnectionType connectionType) { void SingleApplicationPrivate::connectToPrimary(const int msecs, const ConnectionType connectionType) {
// Connect to the Local Server of the Primary Instance if not already connected. // Connect to the Local Server of the Primary Instance if not already connected.
if (socket == nullptr) { if (socket == nullptr) {
@@ -215,9 +214,7 @@ void SingleApplicationPrivate::connectToPrimary(int msecs, ConnectionType connec
QByteArray initMsg; QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly); QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
writeStream.setVersion(QDataStream::Qt_5_6); writeStream.setVersion(QDataStream::Qt_5_6);
#endif
writeStream << blockServerName.toLatin1(); writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType); writeStream << static_cast<quint8>(connectionType);
@@ -229,9 +226,8 @@ void SingleApplicationPrivate::connectToPrimary(int msecs, ConnectionType connec
QByteArray header; QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly); QDataStream headerStream(&header, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6); headerStream.setVersion(QDataStream::Qt_5_6);
#endif
headerStream << static_cast <quint64>(initMsg.length()); headerStream << static_cast <quint64>(initMsg.length());
socket->write(header); socket->write(header);
@@ -310,15 +306,13 @@ void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
return; return;
} }
if (sock->bytesAvailable() < (qint64) sizeof(quint64)) { if (sock->bytesAvailable() < static_cast<qint64>(sizeof(quint64))) {
return; return;
} }
QDataStream headerStream(sock); QDataStream headerStream(sock);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6); headerStream.setVersion(QDataStream::Qt_5_6);
#endif
// Read the header to know the message length // Read the header to know the message length
quint64 msgLen = 0; quint64 msgLen = 0;
@@ -327,7 +321,7 @@ void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
info.stage = StageBody; info.stage = StageBody;
info.msgLen = msgLen; info.msgLen = msgLen;
if (sock->bytesAvailable() >= (qint64) msgLen) { if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
readInitMessageBody(sock); readInitMessageBody(sock);
} }
@@ -342,7 +336,7 @@ void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
} }
ConnectionInfo &info = connectionMap[sock]; ConnectionInfo &info = connectionMap[sock];
if (sock->bytesAvailable() < (qint64)info.msgLen) { if (sock->bytesAvailable() < static_cast<qint64>(info.msgLen)) {
return; return;
} }
@@ -350,9 +344,7 @@ void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
QByteArray msgBytes = sock->read(info.msgLen); QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes); QDataStream readStream(msgBytes);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
readStream.setVersion(QDataStream::Qt_5_6); readStream.setVersion(QDataStream::Qt_5_6);
#endif
// server name // server name
QByteArray latin1Name; QByteArray latin1Name;
@@ -394,14 +386,14 @@ void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
} }
void SingleApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, quint32 instanceId) { void SingleApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
Q_Q(SingleApplication); Q_Q(SingleApplication);
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll()); Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
} }
void SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, quint32 instanceId) { void SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
if (closedSocket->bytesAvailable() > 0) if (closedSocket->bytesAvailable() > 0)
Q_EMIT slotDataAvailable(closedSocket, instanceId); Q_EMIT slotDataAvailable(closedSocket, instanceId);

View File

@@ -35,13 +35,15 @@
#define SINGLEAPPLICATION_P_H #define SINGLEAPPLICATION_P_H
#include <QtGlobal> #include <QtGlobal>
#include <QLocalSocket> #include <QObject>
#include <QLocalServer>
#include <QSharedMemory>
#include <QMap> #include <QMap>
#include "singleapplication.h" #include "singleapplication.h"
class QLocalServer;
class QLocalSocket;
class QSharedMemory;
struct InstancesInfo { struct InstancesInfo {
bool primary; bool primary;
quint32 secondary; quint32 secondary;
@@ -72,14 +74,14 @@ class SingleApplicationPrivate : public QObject {
}; };
Q_DECLARE_PUBLIC(SingleApplication) Q_DECLARE_PUBLIC(SingleApplication)
SingleApplicationPrivate( SingleApplication *q_ptr ); explicit SingleApplicationPrivate(SingleApplication *_q_ptr);
~SingleApplicationPrivate(); ~SingleApplicationPrivate() override;
void genBlockServerName(); void genBlockServerName();
void initializeMemoryBlock(); void initializeMemoryBlock();
void startPrimary(); void startPrimary();
void startSecondary(); void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType ); void connectToPrimary(const int msecs, const ConnectionType connectionType);
quint16 blockChecksum(); quint16 blockChecksum();
qint64 primaryPid(); qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket); void readInitMessageHeader(QLocalSocket *socket);
@@ -96,8 +98,8 @@ class SingleApplicationPrivate : public QObject {
public slots: public slots:
void slotConnectionEstablished(); void slotConnectionEstablished();
void slotDataAvailable(QLocalSocket*, quint32); void slotDataAvailable(QLocalSocket*, const quint32);
void slotClientConnectionClosed(QLocalSocket*, quint32); void slotClientConnectionClosed(QLocalSocket*, const quint32);
}; };
#endif // SINGLEAPPLICATION_P_H #endif // SINGLEAPPLICATION_P_H

View File

@@ -31,13 +31,22 @@
// //
// //
#include <cstdlib>
#include <limits>
#include <QtGlobal> #include <QtGlobal>
#include <QCoreApplication> #include <QCoreApplication>
#include <QThread> #include <QThread>
#include <QSharedMemory> #include <QSharedMemory>
#include <QLocalSocket>
#include <QByteArray> #include <QByteArray>
#include <QElapsedTimer>
#include <QtDebug>
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
# include <QRandomGenerator>
#else
# include <QDateTime> # include <QDateTime>
#include <QTime> #endif
#include "singlecoreapplication.h" #include "singlecoreapplication.h"
#include "singlecoreapplication_p.h" #include "singlecoreapplication_p.h"
@@ -57,8 +66,7 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow
// Store the current mode of the program // Store the current mode of the program
d->options = options; d->options = options;
// Generating an application ID used for identifying the shared memory // Generating an application ID used for identifying the shared memory block and QLocalServer
// block and QLocalServer
d->genBlockServerName(); d->genBlockServerName();
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
@@ -89,7 +97,7 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow
} }
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data()); InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data());
QTime time; QElapsedTimer time;
time.start(); time.start();
// Make sure the shared memory block is initialised and in consistent state // Make sure the shared memory block is initialised and in consistent state
@@ -106,8 +114,12 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow
d->memory->unlock(); d->memory->unlock();
// Random sleep here limits the probability of a collision between two racing apps // Random sleep here limits the probability of a collision between two racing apps
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QThread::sleep(QRandomGenerator::global()->bounded(8u, 18u));
#else
qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max()); qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max());
QThread::sleep(8 + static_cast<unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10)); QThread::sleep(8 + static_cast<unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10));
#endif
} }
if (inst->primary == false) { if (inst->primary == false) {

View File

@@ -36,7 +36,8 @@
#include <QtGlobal> #include <QtGlobal>
#include <QCoreApplication> #include <QCoreApplication>
#include <QLocalSocket> #include <QFlags>
#include <QByteArray>
class SingleCoreApplicationPrivate; class SingleCoreApplicationPrivate;
@@ -91,7 +92,7 @@ public:
* @see See the corresponding QAPPLICATION_CLASS constructor for reference * @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/ */
explicit SingleCoreApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 ); explicit SingleCoreApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleCoreApplication(); ~SingleCoreApplication() override;
/** /**
* @brief Returns if the instance is the primary instance * @brief Returns if the instance is the primary instance

View File

@@ -44,12 +44,14 @@
# include <pwd.h> # include <pwd.h>
#endif #endif
#include <QDir> #include <QIODevice>
#include <QSharedMemory>
#include <QByteArray> #include <QByteArray>
#include <QDataStream> #include <QDataStream>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QLocalServer> #include <QLocalServer>
#include <QLocalSocket> #include <QLocalSocket>
#include <QDir>
#include "singlecoreapplication.h" #include "singlecoreapplication.h"
#include "singlecoreapplication_p.h" #include "singlecoreapplication_p.h"
@@ -59,8 +61,8 @@
# include <lmcons.h> # include <lmcons.h>
#endif #endif
SingleCoreApplicationPrivate::SingleCoreApplicationPrivate(SingleCoreApplication *q_ptr) SingleCoreApplicationPrivate::SingleCoreApplicationPrivate(SingleCoreApplication *_q_ptr)
: q_ptr(q_ptr), : q_ptr(_q_ptr),
memory(nullptr), memory(nullptr),
socket(nullptr), socket(nullptr),
server(nullptr), server(nullptr),
@@ -114,13 +116,10 @@ void SingleCoreApplicationPrivate::genBlockServerName() {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QByteArray username; QByteArray username;
#if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID) #if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID)
uid_t uid = geteuid(); struct passwd *pw = getpwuid(geteuid());
if (uid != -1) {
struct passwd *pw = getpwuid(uid);
if (pw) { if (pw) {
username = pw->pw_name; username = pw->pw_name;
} }
}
#endif #endif
if (username.isEmpty()) username = qgetenv("USER"); if (username.isEmpty()) username = qgetenv("USER");
appData.addData(username); appData.addData(username);
@@ -187,7 +186,7 @@ void SingleCoreApplicationPrivate::startPrimary() {
void SingleCoreApplicationPrivate::startSecondary() {} void SingleCoreApplicationPrivate::startSecondary() {}
void SingleCoreApplicationPrivate::connectToPrimary(int msecs, ConnectionType connectionType) { void SingleCoreApplicationPrivate::connectToPrimary(const int msecs, const ConnectionType connectionType) {
// Connect to the Local Server of the Primary Instance if not already connected. // Connect to the Local Server of the Primary Instance if not already connected.
if (socket == nullptr) { if (socket == nullptr) {
@@ -215,9 +214,7 @@ void SingleCoreApplicationPrivate::connectToPrimary(int msecs, ConnectionType co
QByteArray initMsg; QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly); QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
writeStream.setVersion(QDataStream::Qt_5_6); writeStream.setVersion(QDataStream::Qt_5_6);
#endif
writeStream << blockServerName.toLatin1(); writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType); writeStream << static_cast<quint8>(connectionType);
@@ -229,9 +226,8 @@ void SingleCoreApplicationPrivate::connectToPrimary(int msecs, ConnectionType co
QByteArray header; QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly); QDataStream headerStream(&header, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6); headerStream.setVersion(QDataStream::Qt_5_6);
#endif
headerStream << static_cast <quint64>(initMsg.length()); headerStream << static_cast <quint64>(initMsg.length());
socket->write(header); socket->write(header);
@@ -310,15 +306,13 @@ void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
return; return;
} }
if (sock->bytesAvailable() < (qint64)sizeof(quint64)) { if (sock->bytesAvailable() < static_cast<qint64>(sizeof(quint64))) {
return; return;
} }
QDataStream headerStream(sock); QDataStream headerStream(sock);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6); headerStream.setVersion(QDataStream::Qt_5_6);
#endif
// Read the header to know the message length // Read the header to know the message length
quint64 msgLen = 0; quint64 msgLen = 0;
@@ -327,7 +321,7 @@ void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
info.stage = StageBody; info.stage = StageBody;
info.msgLen = msgLen; info.msgLen = msgLen;
if (sock->bytesAvailable() >= (qint64) msgLen) { if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
readInitMessageBody(sock); readInitMessageBody(sock);
} }
@@ -342,7 +336,7 @@ void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
} }
ConnectionInfo &info = connectionMap[sock]; ConnectionInfo &info = connectionMap[sock];
if (sock->bytesAvailable() < (qint64)info.msgLen) { if (sock->bytesAvailable() < static_cast<qint64>(info.msgLen)) {
return; return;
} }
@@ -350,9 +344,7 @@ void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
QByteArray msgBytes = sock->read(info.msgLen); QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes); QDataStream readStream(msgBytes);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
readStream.setVersion(QDataStream::Qt_5_6); readStream.setVersion(QDataStream::Qt_5_6);
#endif
// server name // server name
QByteArray latin1Name; QByteArray latin1Name;
@@ -394,14 +386,14 @@ void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
} }
void SingleCoreApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, quint32 instanceId) { void SingleCoreApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
Q_Q(SingleCoreApplication); Q_Q(SingleCoreApplication);
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll()); Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
} }
void SingleCoreApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, quint32 instanceId) { void SingleCoreApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
if (closedSocket->bytesAvailable() > 0) if (closedSocket->bytesAvailable() > 0)
Q_EMIT slotDataAvailable(closedSocket, instanceId); Q_EMIT slotDataAvailable(closedSocket, instanceId);

View File

@@ -35,13 +35,15 @@
#define SINGLECOREAPPLICATION_P_H #define SINGLECOREAPPLICATION_P_H
#include <QtGlobal> #include <QtGlobal>
#include <QLocalSocket> #include <QObject>
#include <QLocalServer>
#include <QSharedMemory>
#include <QMap> #include <QMap>
#include "singlecoreapplication.h" #include "singlecoreapplication.h"
class QLocalServer;
class QLocalSocket;
class QSharedMemory;
struct InstancesInfo { struct InstancesInfo {
bool primary; bool primary;
quint32 secondary; quint32 secondary;
@@ -72,14 +74,14 @@ class SingleCoreApplicationPrivate : public QObject {
}; };
Q_DECLARE_PUBLIC(SingleCoreApplication) Q_DECLARE_PUBLIC(SingleCoreApplication)
SingleCoreApplicationPrivate( SingleCoreApplication *q_ptr ); explicit SingleCoreApplicationPrivate(SingleCoreApplication *_q_ptr);
~SingleCoreApplicationPrivate(); ~SingleCoreApplicationPrivate() override;
void genBlockServerName(); void genBlockServerName();
void initializeMemoryBlock(); void initializeMemoryBlock();
void startPrimary(); void startPrimary();
void startSecondary(); void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType ); void connectToPrimary(const int msecs, const ConnectionType connectionType);
quint16 blockChecksum(); quint16 blockChecksum();
qint64 primaryPid(); qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket); void readInitMessageHeader(QLocalSocket *socket);
@@ -96,8 +98,8 @@ class SingleCoreApplicationPrivate : public QObject {
public slots: public slots:
void slotConnectionEstablished(); void slotConnectionEstablished();
void slotDataAvailable(QLocalSocket*, quint32); void slotDataAvailable(QLocalSocket*, const quint32);
void slotClientConnectionClosed(QLocalSocket*, quint32); void slotClientConnectionClosed(QLocalSocket*, const quint32);
}; };
#endif // SINGLECOREAPPLICATION_P_H #endif // SINGLECOREAPPLICATION_P_H

View File

@@ -1,8 +1,4 @@
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -fpermissive -Wall -Woverloaded-virtual -Wno-sign-compare -Wno-delete-non-virtual-dtor")
set(TAGLIB_SOVERSION_CURRENT 17) set(TAGLIB_SOVERSION_CURRENT 17)
set(TAGLIB_SOVERSION_REVISION 0) set(TAGLIB_SOVERSION_REVISION 0)
@@ -12,70 +8,24 @@ math(EXPR TAGLIB_SOVERSION_MAJOR "${TAGLIB_SOVERSION_CURRENT} - ${TAGLIB_SOVERSI
math(EXPR TAGLIB_SOVERSION_MINOR "${TAGLIB_SOVERSION_AGE}") math(EXPR TAGLIB_SOVERSION_MINOR "${TAGLIB_SOVERSION_AGE}")
math(EXPR TAGLIB_SOVERSION_PATCH "${TAGLIB_SOVERSION_REVISION}") math(EXPR TAGLIB_SOVERSION_PATCH "${TAGLIB_SOVERSION_REVISION}")
include(TestBigEndian)
test_big_endian(IS_BIG_ENDIAN)
if(NOT IS_BIG_ENDIAN)
add_definitions(-DSYSTEM_BYTEORDER=1)
else()
add_definitions(-DSYSTEM_BYTEORDER=2)
endif()
include(ConfigureChecks.cmake) include(ConfigureChecks.cmake)
configure_file(config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/config.h") set(TESTS_DIR "${CMAKE_SOURCE_DIR}/tests/taglib/")
configure_file(taglib_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h) configure_file(taglib-config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/taglib-config.h")
add_definitions(-DHAVE_CONFIG_H) add_definitions(-DHAVE_CONFIG_H)
add_definitions(-DTAGLIB_STATIC) add_definitions(-DTAGLIB_STATIC)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/toolkit
${CMAKE_CURRENT_SOURCE_DIR}/asf
${CMAKE_CURRENT_SOURCE_DIR}/mpeg
${CMAKE_CURRENT_SOURCE_DIR}/ogg
${CMAKE_CURRENT_SOURCE_DIR}/ogg/flac
${CMAKE_CURRENT_SOURCE_DIR}/flac
${CMAKE_CURRENT_SOURCE_DIR}/mpc
${CMAKE_CURRENT_SOURCE_DIR}/mp4
${CMAKE_CURRENT_SOURCE_DIR}/ogg/vorbis
${CMAKE_CURRENT_SOURCE_DIR}/ogg/speex
${CMAKE_CURRENT_SOURCE_DIR}/ogg/opus
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2/frames
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
${CMAKE_CURRENT_SOURCE_DIR}/ape
${CMAKE_CURRENT_SOURCE_DIR}/wavpack
${CMAKE_CURRENT_SOURCE_DIR}/trueaudio
${CMAKE_CURRENT_SOURCE_DIR}/riff
${CMAKE_CURRENT_SOURCE_DIR}/riff/aiff
${CMAKE_CURRENT_SOURCE_DIR}/riff/wav
${CMAKE_CURRENT_SOURCE_DIR}/mod
${CMAKE_CURRENT_SOURCE_DIR}/s3m
${CMAKE_CURRENT_SOURCE_DIR}/it
${CMAKE_CURRENT_SOURCE_DIR}/xm
${CMAKE_CURRENT_SOURCE_DIR}/dsf
${CMAKE_CURRENT_SOURCE_DIR}/dsdiff
${CMAKE_SOURCE_DIR}/3rdparty
)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIR})
elseif(HAVE_ZLIB_SOURCE)
include_directories(${ZLIB_SOURCE})
endif()
set(tag_HDRS set(tag_HDRS
tag.h tag.h
fileref.h fileref.h
audioproperties.h audioproperties.h
taglib_export.h taglib_export.h
${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h
toolkit/taglib.h toolkit/taglib.h
toolkit/tstring.h toolkit/tstring.h
toolkit/tlist.h toolkit/tlist.h
toolkit/tlist.tcc toolkit/tlist.tcc
toolkit/tstringlist.h toolkit/tstringlist.h
toolkit/tstringhandler.h
toolkit/tbytevector.h toolkit/tbytevector.h
toolkit/tbytevectorlist.h toolkit/tbytevectorlist.h
toolkit/tbytevectorstream.h toolkit/tbytevectorstream.h
@@ -84,6 +34,8 @@ set(tag_HDRS
toolkit/tfilestream.h toolkit/tfilestream.h
toolkit/tmap.h toolkit/tmap.h
toolkit/tmap.tcc toolkit/tmap.tcc
toolkit/tpicture.h
toolkit/tpicturemap.h
toolkit/tpropertymap.h toolkit/tpropertymap.h
toolkit/trefcounter.h toolkit/trefcounter.h
toolkit/tdebuglistener.h toolkit/tdebuglistener.h
@@ -343,8 +295,10 @@ set(dsdiff_SRCS
) )
set(toolkit_SRCS set(toolkit_SRCS
toolkit/taglib.cpp
toolkit/tstring.cpp toolkit/tstring.cpp
toolkit/tstringlist.cpp toolkit/tstringlist.cpp
toolkit/tstringhandler.cpp
toolkit/tbytevector.cpp toolkit/tbytevector.cpp
toolkit/tbytevectorlist.cpp toolkit/tbytevectorlist.cpp
toolkit/tbytevectorstream.cpp toolkit/tbytevectorstream.cpp
@@ -352,28 +306,40 @@ set(toolkit_SRCS
toolkit/tfile.cpp toolkit/tfile.cpp
toolkit/tfilestream.cpp toolkit/tfilestream.cpp
toolkit/tdebug.cpp toolkit/tdebug.cpp
toolkit/tpicture.cpp
toolkit/tpicturemap.cpp
toolkit/tpropertymap.cpp toolkit/tpropertymap.cpp
toolkit/trefcounter.cpp toolkit/trefcounter.cpp
toolkit/tdebuglistener.cpp toolkit/tdebuglistener.cpp
toolkit/tzlib.cpp toolkit/tzlib.cpp
) )
if(HAVE_ZLIB_SOURCE)
set(zlib_SRCS
${ZLIB_SOURCE}/adler32.c
${ZLIB_SOURCE}/crc32.c
${ZLIB_SOURCE}/inffast.c
${ZLIB_SOURCE}/inflate.c
${ZLIB_SOURCE}/inftrees.c
${ZLIB_SOURCE}/zutil.c
)
endif()
set(tag_LIB_SRCS set(tag_LIB_SRCS
${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS} ${mpeg_SRCS}
${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS} ${id3v1_SRCS}
${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS} ${riff_SRCS} ${aiff_SRCS} ${wav_SRCS} ${id3v2_SRCS}
${asf_SRCS} ${mp4_SRCS} ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS} ${opus_SRCS} ${dsf_SRCS} ${dsdiff_SRCS} ${frames_SRCS}
${ogg_SRCS}
${vorbis_SRCS}
${oggflacs_SRCS}
${mpc_SRCS}
${ape_SRCS}
${toolkit_SRCS}
${flacs_SRCS}
${wavpack_SRCS}
${speex_SRCS}
${trueaudio_SRCS}
${riff_SRCS}
${aiff_SRCS} ${wav_SRCS}
${asf_SRCS}
${mp4_SRCS}
${mod_SRCS}
${s3m_SRCS}
${it_SRCS}
${xm_SRCS}
${opus_SRCS}
${dsf_SRCS}
${dsdiff_SRCS}
${zlib_SRCS} ${zlib_SRCS}
tag.cpp tag.cpp
tagunion.cpp tagunion.cpp
@@ -384,9 +350,40 @@ set(tag_LIB_SRCS
add_library(tag STATIC ${tag_LIB_SRCS} ${tag_HDRS}) add_library(tag STATIC ${tag_LIB_SRCS} ${tag_HDRS})
if(HAVE_ZLIB AND NOT HAVE_ZLIB_SOURCE) target_include_directories(tag PRIVATE
target_link_libraries(tag ${ZLIB_LIBRARIES}) ${ZLIB_INCLUDE_DIR}
endif() ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/toolkit
${CMAKE_CURRENT_SOURCE_DIR}/asf
${CMAKE_CURRENT_SOURCE_DIR}/mpeg
${CMAKE_CURRENT_SOURCE_DIR}/ogg
${CMAKE_CURRENT_SOURCE_DIR}/ogg/flac
${CMAKE_CURRENT_SOURCE_DIR}/flac
${CMAKE_CURRENT_SOURCE_DIR}/mpc
${CMAKE_CURRENT_SOURCE_DIR}/mp4
${CMAKE_CURRENT_SOURCE_DIR}/ogg/vorbis
${CMAKE_CURRENT_SOURCE_DIR}/ogg/speex
${CMAKE_CURRENT_SOURCE_DIR}/ogg/opus
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2/frames
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
${CMAKE_CURRENT_SOURCE_DIR}/ape
${CMAKE_CURRENT_SOURCE_DIR}/wavpack
${CMAKE_CURRENT_SOURCE_DIR}/trueaudio
${CMAKE_CURRENT_SOURCE_DIR}/riff
${CMAKE_CURRENT_SOURCE_DIR}/riff/aiff
${CMAKE_CURRENT_SOURCE_DIR}/riff/wav
${CMAKE_CURRENT_SOURCE_DIR}/mod
${CMAKE_CURRENT_SOURCE_DIR}/s3m
${CMAKE_CURRENT_SOURCE_DIR}/it
${CMAKE_CURRENT_SOURCE_DIR}/xm
${CMAKE_CURRENT_SOURCE_DIR}/dsf
${CMAKE_CURRENT_SOURCE_DIR}/dsdiff
${CMAKE_SOURCE_DIR}/3rdparty
)
target_link_libraries(tag PRIVATE ${ZLIB_LIBRARIES})
set_target_properties(tag PROPERTIES set_target_properties(tag PROPERTIES
VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH} VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH}
@@ -403,4 +400,3 @@ foreach(header ${tag_HDRS})
COPYONLY COPYONLY
) )
endforeach() endforeach()

View File

@@ -1,5 +1,6 @@
include(CheckLibraryExists) include(CheckLibraryExists)
include(CheckTypeSize) include(CheckTypeSize)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
# Check if the size of numeric types are suitable. # Check if the size of numeric types are suitable.

View File

@@ -31,14 +31,16 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include <memory>
#include <tstring.h>
#include <tdebug.h> #include "tbytevector.h"
#include <tagunion.h> #include "tstring.h"
#include <id3v1tag.h> #include "tdebug.h"
#include <id3v2header.h> #include "tagunion.h"
#include <tpropertymap.h> #include "id3v1tag.h"
#include <tagutils.h> #include "id3v2header.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "apefile.h" #include "apefile.h"
#include "apetag.h" #include "apetag.h"
@@ -46,110 +48,86 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{ enum { ApeAPEIndex = 0,
enum { ApeAPEIndex = 0, ApeID3v1Index = 1 }; ApeID3v1Index = 1 };
} }
class APE::File::FilePrivate class APE::File::FilePrivate {
{
public: public:
FilePrivate() : FilePrivate() : APELocation(-1),
APELocation(-1),
APESize(0), APESize(0),
ID3v1Location(-1), ID3v1Location(-1),
ID3v2Header(0),
ID3v2Location(-1), ID3v2Location(-1),
ID3v2Size(0), ID3v2Size(0) {}
properties(0) {}
~FilePrivate() long long APELocation;
{ long long APESize;
delete ID3v2Header;
delete properties;
}
long APELocation; long long ID3v1Location;
long APESize;
long ID3v1Location; std::unique_ptr<ID3v2::Header> ID3v2Header;
long long ID3v2Location;
long long ID3v2Size;
ID3v2::Header *ID3v2Header; DoubleTagUnion tag;
long ID3v2Location;
long ID3v2Size;
TagUnion tag; std::unique_ptr<AudioProperties> properties;
Properties *properties;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool APE::File::isSupported(IOStream *stream) bool APE::File::isSupported(IOStream *stream) {
{
// An APE file has an ID "MAC " somewhere. An ID3v2 tag may precede. // An APE file has an ID "MAC " somewhere. An ID3v2 tag may precede.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true); const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true);
return (buffer.find("MAC ") >= 0); return (buffer.find("MAC ") == 0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
APE::File::File(FileName file, bool readProperties, Properties::ReadStyle) : APE::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
APE::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) : APE::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
APE::File::~File() APE::File::~File() {
{
delete d; delete d;
} }
Strawberry_TagLib::TagLib::Tag *APE::File::tag() const Strawberry_TagLib::TagLib::Tag *APE::File::tag() const {
{
return &d->tag; return &d->tag;
} }
PropertyMap APE::File::properties() const PropertyMap APE::File::setProperties(const PropertyMap &properties) {
{
return d->tag.properties();
}
void APE::File::removeUnsupportedProperties(const StringList &properties)
{
d->tag.removeUnsupportedProperties(properties);
}
PropertyMap APE::File::setProperties(const PropertyMap &properties)
{
if (ID3v1Tag()) if (ID3v1Tag())
ID3v1Tag()->setProperties(properties); ID3v1Tag()->setProperties(properties);
return APETag(true)->setProperties(properties); return APETag(true)->setProperties(properties);
} }
APE::Properties *APE::File::audioProperties() const APE::AudioProperties *APE::File::audioProperties() const {
{ return d->properties.get();
return d->properties;
} }
bool APE::File::save() bool APE::File::save() {
{
if (readOnly()) { if (readOnly()) {
debug("APE::File::save() -- File is read only."); debug("APE::File::save() -- File is read only.");
return false; return false;
@@ -218,37 +196,35 @@ bool APE::File::save()
} }
return true; return true;
} }
ID3v1::Tag *APE::File::ID3v1Tag(bool create) ID3v1::Tag *APE::File::ID3v1Tag(bool create) {
{
return d->tag.access<ID3v1::Tag>(ApeID3v1Index, create); return d->tag.access<ID3v1::Tag>(ApeID3v1Index, create);
} }
APE::Tag *APE::File::APETag(bool create) APE::Tag *APE::File::APETag(bool create) {
{
return d->tag.access<APE::Tag>(ApeAPEIndex, create); return d->tag.access<APE::Tag>(ApeAPEIndex, create);
} }
void APE::File::strip(int tags) void APE::File::strip(int tags) {
{
if (tags & ID3v1) if (tags & ID3v1)
d->tag.set(ApeID3v1Index, 0); d->tag.set(ApeID3v1Index, nullptr);
if (tags & APE) if (tags & APE)
d->tag.set(ApeAPEIndex, 0); d->tag.set(ApeAPEIndex, nullptr);
if (!ID3v1Tag()) if (!ID3v1Tag())
APETag(true); APETag(true);
} }
bool APE::File::hasAPETag() const bool APE::File::hasAPETag() const {
{
return (d->APELocation >= 0); return (d->APELocation >= 0);
} }
bool APE::File::hasID3v1Tag() const bool APE::File::hasID3v1Tag() const {
{
return (d->ID3v1Location >= 0); return (d->ID3v1Location >= 0);
} }
@@ -256,15 +232,15 @@ bool APE::File::hasID3v1Tag() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void APE::File::read(bool readProperties) void APE::File::read(bool readProperties) {
{
// Look for an ID3v2 tag // Look for an ID3v2 tag
d->ID3v2Location = Utils::findID3v2(this); d->ID3v2Location = Utils::findID3v2(this);
if (d->ID3v2Location >= 0) { if (d->ID3v2Location >= 0) {
seek(d->ID3v2Location); seek(d->ID3v2Location);
d->ID3v2Header = new ID3v2::Header(readBlock(ID3v2::Header::size())); d->ID3v2Header.reset(new ID3v2::Header(readBlock(ID3v2::Header::size())));
d->ID3v2Size = d->ID3v2Header->completeTagSize(); d->ID3v2Size = d->ID3v2Header->completeTagSize();
} }
@@ -292,7 +268,7 @@ void APE::File::read(bool readProperties)
if (readProperties) { if (readProperties) {
long streamLength; long long streamLength;
if (d->APELocation >= 0) if (d->APELocation >= 0)
streamLength = d->APELocation; streamLength = d->APELocation;
@@ -309,6 +285,7 @@ void APE::File::read(bool readProperties)
seek(0); seek(0);
} }
d->properties = new Properties(this, streamLength); d->properties.reset(new AudioProperties(this, streamLength));
} }
} }

View File

@@ -43,16 +43,20 @@ namespace TagLib {
class Tag; class Tag;
namespace ID3v1 { class Tag; } namespace ID3v1 {
namespace APE { class Tag; } class Tag;
}
namespace APE {
class Tag;
}
//! An implementation of APE metadata //! An implementation of APE metadata
/*! /*!
* This is implementation of APE metadata. * This is implementation of APE metadata.
* *
* This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream * This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream properties from the file.
* properties from the file. *
*/ */
namespace APE { namespace APE {
@@ -62,16 +66,14 @@ namespace TagLib {
/*! /*!
* This implements and provides an interface for APE files to the * This implements and provides an interface for APE files to the
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing * TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional * the abstract TagLib::File API as well as providing some additional information specific to APE files.
* information specific to APE files. *
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* This set of flags is used for various operations and is suitable for * This set of flags is used for various operations and is suitable for being OR-ed together.
* being OR-ed together.
*/ */
enum TagTypes { enum TagTypes {
//! Empty set. Matches no tag types. //! Empty set. Matches no tag types.
@@ -85,62 +87,45 @@ namespace TagLib {
}; };
/*! /*!
* Constructs an APE file from \a file. If \a readProperties is true the * Constructs an APE file from \a file.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an APE file from \a stream. If \a readProperties is true the * Constructs an APE file from \a stream.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* responsible for deleting it after the File object.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns the Tag for this file. This will be an APE tag, an ID3v1 tag * Returns the Tag for this file. This will be an APE tag, an ID3v1 tag or a combination of the two.
* or a combination of the two.
*/ */
virtual Strawberry_TagLib::TagLib::Tag *tag() const; Strawberry_TagLib::TagLib::Tag *tag() const override;
/*!
* Implements the unified property interface -- export function.
* If the file contains both an APE and an ID3v1 tag, only APE
* will be converted to the PropertyMap.
*/
PropertyMap properties() const;
/*!
* Removes unsupported properties. Forwards to the actual Tag's
* removeUnsupportedProperties() function.
*/
void removeUnsupportedProperties(const StringList &properties);
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* Creates an APEv2 tag if necessary. A potentially existing ID3v1 * Creates an APEv2 tag if necessary.
* tag will be updated as well. * A potentially existing ID3v1 tag will be updated as well.
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap&) override;
/*! /*!
* Returns the APE::Properties for this file. If no audio properties * Returns the APE::AudioProperties for this file.
* were read then this will return a null pointer. * If no audio properties were read then this will return a null pointer.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Saves the file. * Saves the file.
@@ -148,22 +133,19 @@ namespace TagLib {
* \note According to the official Monkey's Audio SDK, an APE file * \note According to the official Monkey's Audio SDK, an APE file
* can only have either ID3V1 or APE tags, so a parameter is used here. * can only have either ID3V1 or APE tags, so a parameter is used here.
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Returns a pointer to the ID3v1 tag of the file. * Returns a pointer to the ID3v1 tag of the file.
* *
* If \a create is false (the default) this may return a null pointer * If \a create is false (the default) this may return a null pointer if there is no valid ID3v1 tag.
* if there is no valid ID3v1 tag. If \a create is true it will create * If \a create is true it will create an ID3v1 tag if one does not exist and returns a valid pointer.
* an ID3v1 tag if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an ID3v1 tag.
* file on disk has an ID3v1 tag. Use hasID3v1Tag() to check if the file * Use hasID3v1Tag() to check if the file on disk actually has an ID3v1 tag.
* on disk actually has an ID3v1 tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasID3v1Tag() * \see hasID3v1Tag()
*/ */
@@ -172,28 +154,24 @@ namespace TagLib {
/*! /*!
* Returns a pointer to the APE tag of the file. * Returns a pointer to the APE tag of the file.
* *
* If \a create is false (the default) this may return a null pointer * If \a create is false (the default) this may return a null pointer if there is no valid APE tag.
* if there is no valid APE tag. If \a create is true it will create * If \a create is true it will create an APE tag if one does not exist and returns a valid pointer.
* an APE tag if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an APE tag.
* file on disk has an APE tag. Use hasAPETag() to check if the file * Use hasAPETag() to check if the file on disk actually has an APE tag.
* on disk actually has an APE tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasAPETag() * \see hasAPETag()
*/ */
APE::Tag *APETag(bool create = false); APE::Tag *APETag(bool create = false);
/*! /*!
* This will remove the tags that match the OR-ed together TagTypes from the * This will remove the tags that match the OR-ed together TagTypes from the file.
* file. By default it removes all tags. * By default it removes all tags.
* *
* \note This will also invalidate pointers to the tags * \note This will also invalidate pointers to the tags as their memory will be freed.
* as their memory will be freed.
* \note In order to make the removal permanent save() still needs to be called * \note In order to make the removal permanent save() still needs to be called
*/ */
void strip(int tags = AllTags); void strip(int tags = AllTags);
@@ -213,11 +191,10 @@ namespace TagLib {
bool hasID3v1Tag() const; bool hasID3v1Tag() const;
/*! /*!
* Returns whether or not the given \a stream can be opened as an APE * Returns whether or not the given \a stream can be opened as an APE file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check.
* not necessarily be correct. * The result may not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -230,8 +207,8 @@ namespace TagLib {
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace APE
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -27,19 +27,17 @@
#include <iostream> #include <iostream>
#include <bitset> #include <bitset>
#include <tstring.h> #include "tstring.h"
#include <tdebug.h> #include "tdebug.h"
#include "apefooter.h" #include "apefooter.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace APE; using namespace APE;
class APE::Footer::FooterPrivate class APE::Footer::FooterPrivate {
{
public: public:
FooterPrivate() : FooterPrivate() : version(0),
version(0),
footerPresent(true), footerPresent(true),
headerPresent(false), headerPresent(false),
isHeader(false), isHeader(false),
@@ -61,13 +59,11 @@ public:
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
unsigned int APE::Footer::size() unsigned int APE::Footer::size() {
{
return 32; return 32;
} }
ByteVector APE::Footer::fileIdentifier() ByteVector APE::Footer::fileIdentifier() {
{
return ByteVector("APETAGEX"); return ByteVector("APETAGEX");
} }
@@ -75,99 +71,83 @@ ByteVector APE::Footer::fileIdentifier()
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
APE::Footer::Footer() : APE::Footer::Footer() : d(new FooterPrivate()) {
d(new FooterPrivate())
{
} }
APE::Footer::Footer(const ByteVector &data) : APE::Footer::Footer(const ByteVector &data) : d(new FooterPrivate()) {
d(new FooterPrivate())
{
parse(data); parse(data);
} }
APE::Footer::~Footer() APE::Footer::~Footer() {
{
delete d; delete d;
} }
unsigned int APE::Footer::version() const unsigned int APE::Footer::version() const {
{
return d->version; return d->version;
} }
bool APE::Footer::headerPresent() const bool APE::Footer::headerPresent() const {
{
return d->headerPresent; return d->headerPresent;
} }
bool APE::Footer::footerPresent() const bool APE::Footer::footerPresent() const {
{
return d->footerPresent; return d->footerPresent;
} }
bool APE::Footer::isHeader() const bool APE::Footer::isHeader() const {
{
return d->isHeader; return d->isHeader;
} }
void APE::Footer::setHeaderPresent(bool b) const void APE::Footer::setHeaderPresent(bool b) const {
{
d->headerPresent = b; d->headerPresent = b;
} }
unsigned int APE::Footer::itemCount() const unsigned int APE::Footer::itemCount() const {
{
return d->itemCount; return d->itemCount;
} }
void APE::Footer::setItemCount(unsigned int s) void APE::Footer::setItemCount(unsigned int s) {
{
d->itemCount = s; d->itemCount = s;
} }
unsigned int APE::Footer::tagSize() const unsigned int APE::Footer::tagSize() const {
{
return d->tagSize; return d->tagSize;
} }
unsigned int APE::Footer::completeTagSize() const unsigned int APE::Footer::completeTagSize() const {
{
if (d->headerPresent) if (d->headerPresent)
return d->tagSize + size(); return d->tagSize + size();
else else
return d->tagSize; return d->tagSize;
} }
void APE::Footer::setTagSize(unsigned int s) void APE::Footer::setTagSize(unsigned int s) {
{
d->tagSize = s; d->tagSize = s;
} }
void APE::Footer::setData(const ByteVector &data) void APE::Footer::setData(const ByteVector &data) {
{
parse(data); parse(data);
} }
ByteVector APE::Footer::renderFooter() const ByteVector APE::Footer::renderFooter() const {
{
return render(false); return render(false);
} }
ByteVector APE::Footer::renderHeader() const ByteVector APE::Footer::renderHeader() const {
{
if (!d->headerPresent) if (!d->headerPresent)
return ByteVector(); return ByteVector();
else else
return render(true); return render(true);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// protected members // protected members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void APE::Footer::parse(const ByteVector &data) void APE::Footer::parse(const ByteVector &data) {
{
if (data.size() < size()) if (data.size() < size())
return; return;
@@ -175,19 +155,19 @@ void APE::Footer::parse(const ByteVector &data)
// Read the version number // Read the version number
d->version = data.toUInt(8, false); d->version = data.toUInt32LE(8);
// Read the tag size // Read the tag size
d->tagSize = data.toUInt(12, false); d->tagSize = data.toUInt32LE(12);
// Read the item count // Read the item count
d->itemCount = data.toUInt(16, false); d->itemCount = data.toUInt32LE(16);
// Read the flags // Read the flags
std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt(20, false))); std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt32LE(20)));
d->headerPresent = flags[31]; d->headerPresent = flags[31];
d->footerPresent = !flags[30]; d->footerPresent = !flags[30];
@@ -195,8 +175,8 @@ void APE::Footer::parse(const ByteVector &data)
} }
ByteVector APE::Footer::render(bool isHeader) const ByteVector APE::Footer::render(bool isHeader) const {
{
ByteVector v; ByteVector v;
// add the file identifier -- "APETAGEX" // add the file identifier -- "APETAGEX"
@@ -206,15 +186,15 @@ ByteVector APE::Footer::render(bool isHeader) const
// add the version number -- we always render a 2.000 tag regardless of what // add the version number -- we always render a 2.000 tag regardless of what
// the tag originally was. // the tag originally was.
v.append(ByteVector::fromUInt(2000, false)); v.append(ByteVector::fromUInt32LE(2000));
// add the tag size // add the tag size
v.append(ByteVector::fromUInt(d->tagSize, false)); v.append(ByteVector::fromUInt32LE(d->tagSize));
// add the item count // add the item count
v.append(ByteVector::fromUInt(d->itemCount, false)); v.append(ByteVector::fromUInt32LE(d->itemCount));
// render and add the flags // render and add the flags
@@ -224,11 +204,12 @@ ByteVector APE::Footer::render(bool isHeader) const
flags[30] = false; // footer is always present flags[30] = false; // footer is always present
flags[29] = isHeader; flags[29] = isHeader;
v.append(ByteVector::fromUInt(flags.to_ulong(), false)); v.append(ByteVector::fromUInt32LE(flags.to_ulong()));
// add the reserved 64bit // add the reserved 64bit
v.append(ByteVector::fromLongLong(0)); v.append(ByteVector::fromUInt64BE(0));
return v; return v;
} }

View File

@@ -37,25 +37,24 @@ namespace TagLib {
//! An implementation of APE footers //! An implementation of APE footers
/*! /*!
* This class implements APE footers (and headers). It attempts to follow, both * This class implements APE footers (and headers).
* semantically and programmatically, the structure specified in * It attempts to follow, both semantically and programmatically,
* the APE v2.0 standard. The API is based on the properties of APE footer and * the structure specified in the APE v2.0 standard.
* headers specified there. * The API is based on the properties of APE footer and headers specified there.
*
*/ */
class TAGLIB_EXPORT Footer class TAGLIB_EXPORT Footer {
{
public: public:
/*! /*!
* Constructs an empty APE footer. * Constructs an empty APE footer.
*/ */
Footer(); explicit Footer();
/*! /*!
* Constructs an APE footer based on \a data. parse() is called * Constructs an APE footer based on \a data. parse() is called immediately.
* immediately.
*/ */
Footer(const ByteVector &data); explicit Footer(const ByteVector &data);
/*! /*!
* Destroys the footer. * Destroys the footer.
@@ -99,7 +98,8 @@ namespace TagLib {
void setItemCount(unsigned int s); void setItemCount(unsigned int s);
/*! /*!
* Returns the tag size in bytes. This is the size of the frame content and footer. * Returns the tag size in bytes.
* This is the size of the frame content and footer.
* The size of the \e entire tag will be this plus the header size, if present. * The size of the \e entire tag will be this plus the header size, if present.
* *
* \see completeTagSize() * \see completeTagSize()
@@ -143,15 +143,15 @@ namespace TagLib {
ByteVector renderFooter() const; ByteVector renderFooter() const;
/*! /*!
* Renders the header corresponding to the footer. If headerPresent is * Renders the header corresponding to the footer.
* set to false, it returns an empty ByteVector. * If headerPresent is set to false, it returns an empty ByteVector.
*/ */
ByteVector renderHeader() const; ByteVector renderHeader() const;
protected: protected:
/*! /*!
* Called by setData() to parse the footer data. It makes this information * Called by setData() to parse the footer data.
* available through the public API. * It makes this information available through the public API.
*/ */
void parse(const ByteVector &data); void parse(const ByteVector &data);
@@ -168,8 +168,8 @@ namespace TagLib {
FooterPrivate *d; FooterPrivate *d;
}; };
} } // namespace APE
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,20 +23,18 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevectorlist.h> #include <memory>
#include <tdebug.h>
#include "tbytevectorlist.h"
#include "tdebug.h"
#include "apeitem.h" #include "apeitem.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace APE; using namespace APE;
class APE::Item::ItemPrivate struct ItemData {
{ ItemData() : type(Item::Text), readOnly(false) {}
public:
ItemPrivate() :
type(Text),
readOnly(false) {}
Item::ItemTypes type; Item::ItemTypes type;
String key; String key;
@@ -45,203 +43,174 @@ public:
bool readOnly; bool readOnly;
}; };
class APE::Item::ItemPrivate {
public:
ItemPrivate() : data(new ItemData()) {}
std::shared_ptr<ItemData> data;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
APE::Item::Item() : APE::Item::Item() : d(new ItemPrivate()) {}
d(new ItemPrivate())
{ APE::Item::Item(const String &key, const String &value) : d(new ItemPrivate()) {
d->data->key = key;
d->data->text.append(value);
} }
APE::Item::Item(const String &key, const String &value) : APE::Item::Item(const String &key, const StringList &values) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->key = key;
{ d->data->text = values;
d->key = key;
d->text.append(value);
} }
APE::Item::Item(const String &key, const StringList &values) : APE::Item::Item(const String &key, const ByteVector &value, bool binary) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->key = key;
{
d->key = key;
d->text = values;
}
APE::Item::Item(const String &key, const ByteVector &value, bool binary) :
d(new ItemPrivate())
{
d->key = key;
if (binary) { if (binary) {
d->type = Binary; d->data->type = Binary;
d->value = value; d->data->value = value;
} }
else { else {
d->text.append(value); d->data->text.append(value);
}
} }
APE::Item::Item(const Item &item) :
d(new ItemPrivate(*item.d))
{
} }
APE::Item::~Item() APE::Item::Item(const Item &item) : d(new ItemPrivate(*item.d)) {}
{
APE::Item::~Item() {
delete d; delete d;
} }
Item &APE::Item::operator=(const Item &item) Item &APE::Item::operator=(const Item &item) {
{
Item(item).swap(*this); Item(item).swap(*this);
return *this; return *this;
} }
void APE::Item::swap(Item &item) void APE::Item::swap(Item &item) {
{
using std::swap; using std::swap;
swap(d, item.d); swap(d, item.d);
} }
void APE::Item::setReadOnly(bool readOnly) void APE::Item::setReadOnly(bool readOnly) {
{ d->data->readOnly = readOnly;
d->readOnly = readOnly;
} }
bool APE::Item::isReadOnly() const bool APE::Item::isReadOnly() const {
{ return d->data->readOnly;
return d->readOnly;
} }
void APE::Item::setType(APE::Item::ItemTypes val) void APE::Item::setType(APE::Item::ItemTypes val) {
{ d->data->type = val;
d->type = val;
} }
APE::Item::ItemTypes APE::Item::type() const APE::Item::ItemTypes APE::Item::type() const {
{ return d->data->type;
return d->type;
} }
String APE::Item::key() const String APE::Item::key() const {
{ return d->data->key;
return d->key;
} }
ByteVector APE::Item::binaryData() const ByteVector APE::Item::binaryData() const {
{ return d->data->value;
return d->value;
} }
void APE::Item::setBinaryData(const ByteVector &value) void APE::Item::setBinaryData(const ByteVector &value) {
{ d->data->type = Binary;
d->type = Binary; d->data->value = value;
d->value = value; d->data->text.clear();
d->text.clear();
} }
ByteVector APE::Item::value() const void APE::Item::setKey(const String &key) {
{ d->data->key = key;
// This seems incorrect as it won't be actually rendering the value to keep it
// up to date.
return d->value;
} }
void APE::Item::setKey(const String &key) void APE::Item::setValue(const String &value) {
{ d->data->type = Text;
d->key = key; d->data->text = value;
d->data->value.clear();
} }
void APE::Item::setValue(const String &value) void APE::Item::setValues(const StringList &value) {
{ d->data->type = Text;
d->type = Text; d->data->text = value;
d->text = value; d->data->value.clear();
d->value.clear();
} }
void APE::Item::setValues(const StringList &value) void APE::Item::appendValue(const String &value) {
{ d->data->type = Text;
d->type = Text; d->data->text.append(value);
d->text = value; d->data->value.clear();
d->value.clear();
} }
void APE::Item::appendValue(const String &value) void APE::Item::appendValues(const StringList &values) {
{ d->data->type = Text;
d->type = Text; d->data->text.append(values);
d->text.append(value); d->data->value.clear();
d->value.clear();
} }
void APE::Item::appendValues(const StringList &values) int APE::Item::size() const {
{ size_t result = 8 + d->data->key.size() + 1;
d->type = Text; switch (d->data->type) {
d->text.append(values);
d->value.clear();
}
int APE::Item::size() const
{
int result = 8 + d->key.size() + 1;
switch(d->type) {
case Text: case Text:
if(!d->text.isEmpty()) { if (!d->data->text.isEmpty()) {
StringList::ConstIterator it = d->text.begin(); StringList::ConstIterator it = d->data->text.begin();
result += it->data(String::UTF8).size(); result += it->data(String::UTF8).size();
it++; it++;
for(; it != d->text.end(); ++it) for (; it != d->data->text.end(); ++it)
result += 1 + it->data(String::UTF8).size(); result += 1 + it->data(String::UTF8).size();
} }
break; break;
case Binary: case Binary:
case Locator: case Locator:
result += d->value.size(); result += d->data->value.size();
break; break;
} }
return result; return result;
} }
StringList APE::Item::toStringList() const StringList APE::Item::values() const {
{ return d->data->text;
return d->text;
} }
StringList APE::Item::values() const String APE::Item::toString() const {
{ if (d->data->type == Text && !isEmpty())
return d->text; return d->data->text.front();
}
String APE::Item::toString() const
{
if(d->type == Text && !isEmpty())
return d->text.front();
else else
return String(); return String();
} }
bool APE::Item::isEmpty() const bool APE::Item::isEmpty() const {
{ switch (d->data->type) {
switch(d->type) {
case Text: case Text:
if(d->text.isEmpty()) if (d->data->text.isEmpty())
return true; return true;
if(d->text.size() == 1 && d->text.front().isEmpty()) if (d->data->text.size() == 1 && d->data->text.front().isEmpty())
return true; return true;
return false; return false;
case Binary: case Binary:
case Locator: case Locator:
return d->value.isEmpty(); return d->data->value.isEmpty();
default: default:
return false; return false;
} }
} }
void APE::Item::parse(const ByteVector &data) void APE::Item::parse(const ByteVector &data) {
{
// 11 bytes is the minimum size for an APE item // 11 bytes is the minimum size for an APE item
if (data.size() < 11) { if (data.size() < 11) {
@@ -249,53 +218,54 @@ void APE::Item::parse(const ByteVector &data)
return; return;
} }
const unsigned int valueLength = data.toUInt(0, false); const unsigned int valueLength = data.toUInt32LE(0);
const unsigned int flags = data.toUInt(4, false); const unsigned int flags = data.toUInt32LE(4);
// An item key can contain ASCII characters from 0x20 up to 0x7E, not UTF-8. // An item key can contain ASCII characters from 0x20 up to 0x7E, not UTF-8.
// We assume that the validity of the given key has been checked. // We assume that the validity of the given key has been checked.
d->key = String(&data[8], String::Latin1); d->data->key = String(&data[8], String::Latin1);
const ByteVector value = data.mid(8 + d->key.size() + 1, valueLength); const ByteVector value = data.mid(8 + d->data->key.size() + 1, valueLength);
setReadOnly(flags & 1); setReadOnly(flags & 1);
setType(ItemTypes((flags >> 1) & 3)); setType(ItemTypes((flags >> 1) & 3));
if(Text == d->type) if (Text == d->data->type)
d->text = StringList(ByteVectorList::split(value, '\0'), String::UTF8); d->data->text = StringList(ByteVectorList::split(value, '\0'), String::UTF8);
else else
d->value = value; d->data->value = value;
} }
ByteVector APE::Item::render() const ByteVector APE::Item::render() const {
{
ByteVector data; ByteVector data;
unsigned int flags = ((d->readOnly) ? 1 : 0) | (d->type << 1); unsigned int flags = ((d->data->readOnly) ? 1 : 0) | (d->data->type << 1);
ByteVector value; ByteVector value;
if (isEmpty()) if (isEmpty())
return data; return data;
if(d->type == Text) { if (d->data->type == Text) {
StringList::ConstIterator it = d->text.begin(); StringList::ConstIterator it = d->data->text.begin();
value.append(it->data(String::UTF8)); value.append(it->data(String::UTF8));
it++; it++;
for(; it != d->text.end(); ++it) { for (; it != d->data->text.end(); ++it) {
value.append('\0'); value.append('\0');
value.append(it->data(String::UTF8)); value.append(it->data(String::UTF8));
} }
d->value = value; d->data->value = value;
} }
else else
value.append(d->value); value.append(d->data->value);
data.append(ByteVector::fromUInt(value.size(), false)); data.append(ByteVector::fromUInt32LE(value.size()));
data.append(ByteVector::fromUInt(flags, false)); data.append(ByteVector::fromUInt32LE(flags));
data.append(d->key.data(String::Latin1)); data.append(d->data->key.data(String::Latin1));
data.append(ByteVector('\0')); data.append(ByteVector('\0'));
data.append(value); data.append(value);
return data; return data;
} }

View File

@@ -32,7 +32,6 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace APE { namespace APE {
//! An implementation of APE-items //! An implementation of APE-items
@@ -40,8 +39,7 @@ namespace TagLib {
/*! /*!
* This class provides the features of items in the APEv2 standard. * This class provides the features of items in the APEv2 standard.
*/ */
class TAGLIB_EXPORT Item class TAGLIB_EXPORT Item {
{
public: public:
/*! /*!
* Enum of types an Item can have. The value of 3 is reserved. * Enum of types an Item can have. The value of 3 is reserved.
@@ -57,24 +55,23 @@ namespace TagLib {
/*! /*!
* Constructs an empty item. * Constructs an empty item.
*/ */
Item(); explicit Item();
/*!
* Constructs a text item with \a key and \a value.
*/
// BIC: Remove this, StringList has a constructor from a single string
Item(const String &key, const String &value);
/*! /*!
* Constructs a text item with \a key and \a values. * Constructs a text item with \a key and \a values.
*/ */
Item(const String &key, const StringList &values); explicit Item(const String &key, const String &values);
/*!
* Constructs a text item with \a key and \a values.
*/
explicit Item(const String &key, const StringList &values);
/*! /*!
* Constructs an item with \a key and \a value. * Constructs an item with \a key and \a value.
* If \a binary is true a Binary item will be created, otherwise \a value will be interpreted as text * If \a binary is true a Binary item will be created, otherwise \a value will be interpreted as text
*/ */
Item(const String &key, const ByteVector &value, bool binary); explicit Item(const String &key, const ByteVector &value, bool binary);
/*! /*!
* Construct an item as a copy of \a item. * Construct an item as a copy of \a item.
@@ -113,11 +110,6 @@ namespace TagLib {
*/ */
void setBinaryData(const ByteVector &value); void setBinaryData(const ByteVector &value);
#ifndef DO_NOT_DOCUMENT
/* Remove in next binary incompatible release */
ByteVector value() const;
#endif
/*! /*!
* Sets the key for the item to \a key. * Sets the key for the item to \a key.
*/ */
@@ -131,8 +123,7 @@ namespace TagLib {
void setValue(const String &value); void setValue(const String &value);
/*! /*!
* Sets the text value of the item to the list of values in \a value and clears * Sets the text value of the item to the list of values in \a value and clears any previous contents.
* any previous contents.
* *
* \see toStringList() * \see toStringList()
*/ */
@@ -158,20 +149,13 @@ namespace TagLib {
int size() const; int size() const;
/*! /*!
* Returns the value as a single string. In case of multiple strings, * Returns the value as a single string. In case of multiple strings, the first is returned.
* the first is returned. If the data type is not \a Text, always returns * If the data type is not \a Text, always returns an empty String.
* an empty String.
*/ */
String toString() const; String toString() const;
#ifndef DO_NOT_DOCUMENT
/* Remove in next binary incompatible release */
StringList toStringList() const;
#endif
/*! /*!
* Returns the list of text values. If the data type is not \a Text, always * Returns the list of text values. If the data type is not \a Text, always returns an empty StringList.
* returns an empty StringList.
*/ */
StringList values() const; StringList values() const;
@@ -216,11 +200,8 @@ namespace TagLib {
class ItemPrivate; class ItemPrivate;
ItemPrivate *d; ItemPrivate *d;
}; };
} } // namespace APE
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -27,9 +27,9 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tstring.h> #include "tstring.h"
#include <tdebug.h> #include "tdebug.h"
#include <bitset>
#include "id3v2tag.h" #include "id3v2tag.h"
#include "apeproperties.h" #include "apeproperties.h"
#include "apefile.h" #include "apefile.h"
@@ -38,11 +38,9 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class APE::Properties::PropertiesPrivate class APE::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : length(0),
length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
channels(0), channels(0),
@@ -63,67 +61,43 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
APE::Properties::Properties(File *, ReadStyle style) : APE::AudioProperties::AudioProperties(File *file, long long streamLength, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
AudioProperties(style),
d(new PropertiesPrivate())
{
debug("APE::Properties::Properties() -- This constructor is no longer used.");
}
APE::Properties::Properties(File *file, long streamLength, ReadStyle style) :
AudioProperties(style),
d(new PropertiesPrivate())
{
read(file, streamLength); read(file, streamLength);
} }
APE::Properties::~Properties() APE::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int APE::Properties::length() const int APE::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int APE::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int APE::Properties::lengthInMilliseconds() const int APE::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int APE::Properties::bitrate() const int APE::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int APE::Properties::sampleRate() const int APE::AudioProperties::sampleRate() const {
{
return d->sampleRate; return d->sampleRate;
} }
int APE::Properties::channels() const int APE::AudioProperties::channels() const {
{
return d->channels; return d->channels;
} }
int APE::Properties::version() const int APE::AudioProperties::version() const {
{
return d->version; return d->version;
} }
int APE::Properties::bitsPerSample() const int APE::AudioProperties::bitsPerSample() const {
{
return d->bitsPerSample; return d->bitsPerSample;
} }
unsigned int APE::Properties::sampleFrames() const unsigned int APE::AudioProperties::sampleFrames() const {
{
return d->sampleFrames; return d->sampleFrames;
} }
@@ -131,21 +105,19 @@ unsigned int APE::Properties::sampleFrames() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace namespace {
{ int headerVersion(const ByteVector &header) {
int headerVersion(const ByteVector &header)
{
if (header.size() < 6 || !header.startsWith("MAC ")) if (header.size() < 6 || !header.startsWith("MAC "))
return -1; return -1;
return header.toUShort(4, false); return header.toUInt16LE(4);
}
} }
} // namespace
void APE::AudioProperties::read(File *file, long long streamLength) {
void APE::Properties::read(File *file, long streamLength)
{
// First, we assume that the file pointer is set at the first descriptor. // First, we assume that the file pointer is set at the first descriptor.
long offset = file->tell(); long long offset = file->tell();
int version = headerVersion(file->readBlock(6)); int version = headerVersion(file->readBlock(6));
// Next, we look for the descriptor. // Next, we look for the descriptor.
@@ -156,7 +128,7 @@ void APE::Properties::read(File *file, long streamLength)
} }
if (version < 0) { if (version < 0) {
debug("APE::Properties::read() -- APE descriptor not found"); debug("APE::AudioProperties::read() -- APE descriptor not found");
return; return;
} }
@@ -172,19 +144,20 @@ void APE::Properties::read(File *file, long streamLength)
d->length = static_cast<int>(length + 0.5); d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5); d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5);
} }
} }
void APE::Properties::analyzeCurrent(File *file) void APE::AudioProperties::analyzeCurrent(File *file) {
{
// Read the descriptor // Read the descriptor
file->seek(2, File::Current); file->seek(2, File::Current);
const ByteVector descriptor = file->readBlock(44); const ByteVector descriptor = file->readBlock(44);
if (descriptor.size() < 44) { if (descriptor.size() < 44) {
debug("APE::Properties::analyzeCurrent() -- descriptor is too short."); debug("APE::AudioProperties::analyzeCurrent() -- descriptor is too short.");
return; return;
} }
const unsigned int descriptorBytes = descriptor.toUInt(0, false); const unsigned int descriptorBytes = descriptor.toUInt32LE(0);
if ((descriptorBytes - 52) > 0) if ((descriptorBytes - 52) > 0)
file->seek(descriptorBytes - 52, File::Current); file->seek(descriptorBytes - 52, File::Current);
@@ -192,39 +165,40 @@ void APE::Properties::analyzeCurrent(File *file)
// Read the header // Read the header
const ByteVector header = file->readBlock(24); const ByteVector header = file->readBlock(24);
if (header.size() < 24) { if (header.size() < 24) {
debug("APE::Properties::analyzeCurrent() -- MAC header is too short."); debug("APE::AudioProperties::analyzeCurrent() -- MAC header is too short.");
return; return;
} }
// Get the APE info // Get the APE info
d->channels = header.toShort(18, false); d->channels = header.toUInt16LE(18);
d->sampleRate = header.toUInt(20, false); d->sampleRate = header.toUInt32LE(20);
d->bitsPerSample = header.toShort(16, false); d->bitsPerSample = header.toUInt16LE(16);
const unsigned int totalFrames = header.toUInt(12, false); const unsigned int totalFrames = header.toUInt32LE(12);
if (totalFrames == 0) if (totalFrames == 0)
return; return;
const unsigned int blocksPerFrame = header.toUInt(4, false); const unsigned int blocksPerFrame = header.toUInt32LE(4);
const unsigned int finalFrameBlocks = header.toUInt(8, false); const unsigned int finalFrameBlocks = header.toUInt32LE(8);
d->sampleFrames = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks; d->sampleFrames = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks;
} }
void APE::Properties::analyzeOld(File *file) void APE::AudioProperties::analyzeOld(File *file) {
{
const ByteVector header = file->readBlock(26); const ByteVector header = file->readBlock(26);
if (header.size() < 26) { if (header.size() < 26) {
debug("APE::Properties::analyzeOld() -- MAC header is too short."); debug("APE::AudioProperties::analyzeOld() -- MAC header is too short.");
return; return;
} }
const unsigned int totalFrames = header.toUInt(18, false); const unsigned int totalFrames = header.toUInt32LE(18);
// Fail on 0 length APE files (catches non-finalized APE files) // Fail on 0 length APE files (catches non-finalized APE files)
if (totalFrames == 0) if (totalFrames == 0)
return; return;
const short compressionLevel = header.toShort(0, false); const short compressionLevel = header.toUInt32LE(0);
unsigned int blocksPerFrame; unsigned int blocksPerFrame;
if (d->version >= 3950) if (d->version >= 3950)
blocksPerFrame = 73728 * 4; blocksPerFrame = 73728 * 4;
@@ -234,19 +208,20 @@ void APE::Properties::analyzeOld(File *file)
blocksPerFrame = 9216; blocksPerFrame = 9216;
// Get the APE info // Get the APE info
d->channels = header.toShort(4, false); d->channels = header.toUInt16LE(4);
d->sampleRate = header.toUInt(6, false); d->sampleRate = header.toUInt32LE(6);
const unsigned int finalFrameBlocks = header.toUInt(22, false); const unsigned int finalFrameBlocks = header.toUInt32LE(22);
d->sampleFrames = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks; d->sampleFrames = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks;
// Get the bit depth from the RIFF-fmt chunk. // Get the bit depth from the RIFF-fmt chunk.
file->seek(16, File::Current); file->seek(16, File::Current);
const ByteVector fmt = file->readBlock(28); const ByteVector fmt = file->readBlock(28);
if (fmt.size() < 28 || !fmt.startsWith("WAVEfmt ")) { if (fmt.size() < 28 || !fmt.startsWith("WAVEfmt ")) {
debug("APE::Properties::analyzeOld() -- fmt header is too short."); debug("APE::AudioProperties::analyzeOld() -- fmt header is too short.");
return; return;
} }
d->bitsPerSample = fmt.toShort(26, false); d->bitsPerSample = fmt.toUInt16LE(26);
} }

View File

@@ -35,7 +35,6 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace APE { namespace APE {
class File; class File;
@@ -43,73 +42,50 @@ namespace TagLib {
//! An implementation of audio property reading for APE //! An implementation of audio property reading for APE
/*! /*!
* This reads the data from an APE stream found in the AudioProperties * This reads the data from an APE stream found in the AudioProperties API.
* API.
*/ */
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
/*!
* Create an instance of APE::Properties with the data read from the
* APE::File \a file.
*
* \deprecated
*/
TAGLIB_DEPRECATED Properties(File *file, ReadStyle style = Average);
/*! /*!
* Create an instance of APE::Properties with the data read from the * Create an instance of APE::AudioProperties with the data read from the APE::File \a file.
* APE::File \a file.
*/ */
Properties(File *file, long streamLength, ReadStyle style = Average); explicit AudioProperties(File *file, long long streamLength, ReadStyle style = Average);
/*! /*!
* Destroys this APE::Properties instance. * Destroys this APE::AudioProperties instance.
*/ */
virtual ~Properties(); ~AudioProperties() override;
/*! /*!
* Returns the length of the file in seconds. The length is rounded down to * Returns the length of the file in seconds. The length is rounded down to the nearest whole second.
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual int lengthInSeconds() const override;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual int lengthInMilliseconds() const override;
int lengthInMilliseconds() const;
/*! /*!
* Returns the average bit rate of the file in kb/s. * Returns the average bit rate of the file in kb/s.
*/ */
virtual int bitrate() const; int bitrate() const override;
/*! /*!
* Returns the sample rate in Hz. * Returns the sample rate in Hz.
*/ */
virtual int sampleRate() const; int sampleRate() const override;
/*! /*!
* Returns the number of audio channels. * Returns the number of audio channels.
*/ */
virtual int channels() const; int channels() const override;
/*! /*!
* Returns the number of bits per audio sample. * Returns the number of bits per audio sample.
@@ -127,19 +103,16 @@ namespace TagLib {
int version() const; int version() const;
private: private:
Properties(const Properties &); void read(File *file, long long streamLength);
Properties &operator=(const Properties &);
void read(File *file, long streamLength);
void analyzeCurrent(File *file); void analyzeCurrent(File *file);
void analyzeOld(File *file); void analyzeOld(File *file);
class PropertiesPrivate; class AudioPropertiesPrivate;
PropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
} } // namespace APE
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -31,12 +31,13 @@
# define WANT_CLASS_INSTANTIATION_OF_MAP (1) # define WANT_CLASS_INSTANTIATION_OF_MAP (1)
#endif #endif
#include <tfile.h> #include "tfile.h"
#include <tstring.h> #include "tstring.h"
#include <tmap.h> #include "tmap.h"
#include <tpropertymap.h> #include "tpicturemap.h"
#include <tdebug.h> #include "tpropertymap.h"
#include <tutils.h> #include "tdebug.h"
#include "tutils.h"
#include "apetag.h" #include "apetag.h"
#include "apefooter.h" #include "apefooter.h"
@@ -45,14 +46,13 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace APE; using namespace APE;
namespace namespace {
{
const unsigned int MinKeyLength = 2; const unsigned int MinKeyLength = 2;
const unsigned int MaxKeyLength = 255; const unsigned int MaxKeyLength = 255;
bool isKeyValid(const ByteVector &key) bool isKeyValid(const ByteVector &key) {
{
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 }; const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", nullptr };
// only allow printable ASCII including space (32..126) // only allow printable ASCII including space (32..126)
@@ -63,24 +63,21 @@ namespace
} }
const String upperKey = String(key).upper(); const String upperKey = String(key).upper();
for(size_t i = 0; invalidKeys[i] != 0; ++i) { for (size_t i = 0; invalidKeys[i] != nullptr; ++i) {
if (upperKey == invalidKeys[i]) if (upperKey == invalidKeys[i])
return false; return false;
} }
return true; return true;
} }
} } // namespace
class APE::Tag::TagPrivate class APE::Tag::TagPrivate {
{
public: public:
TagPrivate() : TagPrivate() : file(nullptr), footerLocation(0) {}
file(0),
footerLocation(0) {}
File *file; File *file;
long footerLocation; long long footerLocation;
Footer footer; Footer footer;
ItemListMap itemListMap; ItemListMap itemListMap;
@@ -90,124 +87,207 @@ public:
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
APE::Tag::Tag() : APE::Tag::Tag() : d(new TagPrivate()) {}
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate()) APE::Tag::Tag(Strawberry_TagLib::TagLib::File *file, long long footerLocation) : d(new TagPrivate()) {
{
}
APE::Tag::Tag(Strawberry_TagLib::TagLib::File *file, long footerLocation) :
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate())
{
d->file = file; d->file = file;
d->footerLocation = footerLocation; d->footerLocation = footerLocation;
read(); read();
} }
APE::Tag::~Tag() APE::Tag::~Tag() {
{
delete d; delete d;
} }
ByteVector APE::Tag::fileIdentifier() ByteVector APE::Tag::fileIdentifier() {
{
return ByteVector::fromCString("APETAGEX"); return ByteVector::fromCString("APETAGEX");
} }
String APE::Tag::title() const String APE::Tag::title() const {
{
if (d->itemListMap["TITLE"].isEmpty()) if (d->itemListMap["TITLE"].isEmpty())
return String(); return String();
return d->itemListMap["TITLE"].values().toString(); return d->itemListMap["TITLE"].values().toString();
} }
String APE::Tag::artist() const String APE::Tag::artist() const {
{
if (d->itemListMap["ARTIST"].isEmpty()) if (d->itemListMap["ARTIST"].isEmpty())
return String(); return String();
return d->itemListMap["ARTIST"].values().toString(); return d->itemListMap["ARTIST"].values().toString();
} }
String APE::Tag::album() const String APE::Tag::album() const {
{
if (d->itemListMap["ALBUM"].isEmpty()) if (d->itemListMap["ALBUM"].isEmpty())
return String(); return String();
return d->itemListMap["ALBUM"].values().toString(); return d->itemListMap["ALBUM"].values().toString();
} }
String APE::Tag::comment() const String APE::Tag::comment() const {
{
if (d->itemListMap["COMMENT"].isEmpty()) if (d->itemListMap["COMMENT"].isEmpty())
return String(); return String();
return d->itemListMap["COMMENT"].values().toString(); return d->itemListMap["COMMENT"].values().toString();
} }
String APE::Tag::genre() const String APE::Tag::genre() const {
{
if (d->itemListMap["GENRE"].isEmpty()) if (d->itemListMap["GENRE"].isEmpty())
return String(); return String();
return d->itemListMap["GENRE"].values().toString(); return d->itemListMap["GENRE"].values().toString();
} }
unsigned int APE::Tag::year() const unsigned int APE::Tag::year() const {
{
if (d->itemListMap["YEAR"].isEmpty()) if (d->itemListMap["YEAR"].isEmpty())
return 0; return 0;
return d->itemListMap["YEAR"].toString().toInt(); return d->itemListMap["YEAR"].toString().toInt();
} }
unsigned int APE::Tag::track() const unsigned int APE::Tag::track() const {
{
if (d->itemListMap["TRACK"].isEmpty()) if (d->itemListMap["TRACK"].isEmpty())
return 0; return 0;
return d->itemListMap["TRACK"].toString().toInt(); return d->itemListMap["TRACK"].toString().toInt();
} }
void APE::Tag::setTitle(const String &s) Strawberry_TagLib::TagLib::PictureMap APE::Tag::pictures() const {
{
PictureMap map;
if (d->itemListMap.contains(FRONT_COVER)) {
Item front = d->itemListMap[FRONT_COVER];
if (Item::Binary == front.type()) {
ByteVector picture = front.binaryData();
const size_t index = picture.find('\0');
if (index < picture.size()) {
ByteVector desc = picture.mid(0, index + 1);
String mime = "image/jpeg";
ByteVector data = picture.mid(index + 1);
Picture p(data, Picture::FrontCover, mime, desc);
map.insert(p);
}
}
}
if (d->itemListMap.contains(BACK_COVER)) {
Item back = d->itemListMap[BACK_COVER];
if (Item::Binary == back.type()) {
ByteVector picture = back.binaryData();
const size_t index = picture.find('\0');
if (index < picture.size()) {
ByteVector desc = picture.mid(0, index + 1);
String mime = "image/jpeg";
ByteVector data = picture.mid(index + 1);
Picture p(data, Picture::BackCover, mime, desc);
map.insert(p);
}
}
}
return PictureMap(map);
}
void APE::Tag::setTitle(const String &s) {
addValue("TITLE", s, true); addValue("TITLE", s, true);
} }
void APE::Tag::setArtist(const String &s) void APE::Tag::setArtist(const String &s) {
{
addValue("ARTIST", s, true); addValue("ARTIST", s, true);
} }
void APE::Tag::setAlbum(const String &s) void APE::Tag::setAlbum(const String &s) {
{
addValue("ALBUM", s, true); addValue("ALBUM", s, true);
} }
void APE::Tag::setComment(const String &s) void APE::Tag::setComment(const String &s) {
{
addValue("COMMENT", s, true); addValue("COMMENT", s, true);
} }
void APE::Tag::setGenre(const String &s) void APE::Tag::setGenre(const String &s) {
{
addValue("GENRE", s, true); addValue("GENRE", s, true);
} }
void APE::Tag::setYear(unsigned int i) void APE::Tag::setYear(unsigned int i) {
{
if (i == 0) if (i == 0)
removeItem("YEAR"); removeItem("YEAR");
else else
addValue("YEAR", String::number(i), true); addValue("YEAR", String::number(i), true);
} }
void APE::Tag::setTrack(unsigned int i) void APE::Tag::setTrack(unsigned int i) {
{
if (i == 0) if (i == 0)
removeItem("TRACK"); removeItem("TRACK");
else else
addValue("TRACK", String::number(i), true); addValue("TRACK", String::number(i), true);
} }
namespace void APE::Tag::setPictures(const PictureMap &l) {
{
removeItem(FRONT_COVER);
removeItem(BACK_COVER);
for (PictureMap::ConstIterator pictureMapIt = l.begin(); pictureMapIt != l.end(); ++pictureMapIt) {
Picture::Type type = pictureMapIt->first;
if (Picture::FrontCover != type && Picture::BackCover != type) {
std::cout << "APE: Trying to add a picture with wrong type" << std::endl;
continue;
}
const char *id;
switch (type) {
case Picture::FrontCover:
id = FRONT_COVER;
break;
case Picture::BackCover:
id = BACK_COVER;
break;
default:
id = FRONT_COVER;
break;
}
PictureList list = pictureMapIt->second;
for (PictureList::ConstIterator pictureListIt = list.begin(); pictureListIt != list.end(); ++pictureListIt) {
Picture picture = *pictureListIt;
if (d->itemListMap.contains(id)) {
std::cout << "APE: Already added a picture of type "
<< id
<< " '"
<< picture.description()
<< "' "
<< "and next are being ignored"
<< std::endl;
break;
}
ByteVector data = picture.description().data(String::Latin1).append('\0').append(picture.data());
Item item;
item.setKey(id);
item.setType(Item::Binary);
item.setBinaryData(data);
setItem(item.key(), item);
}
}
}
namespace {
// conversions of tag keys between what we use in PropertyMap and what's usual // conversions of tag keys between what we use in PropertyMap and what's usual
// for APE tags // for APE tags
// usual, APE // usual, APE
@@ -217,10 +297,10 @@ namespace
{ "DISCNUMBER", "DISC" }, { "DISCNUMBER", "DISC" },
{ "REMIXER", "MIXARTIST" } }; { "REMIXER", "MIXARTIST" } };
const size_t keyConversionsSize = sizeof(keyConversions) / sizeof(keyConversions[0]); const size_t keyConversionsSize = sizeof(keyConversions) / sizeof(keyConversions[0]);
} } // namespace
PropertyMap APE::Tag::properties() const {
PropertyMap APE::Tag::properties() const
{
PropertyMap properties; PropertyMap properties;
ItemListMap::ConstIterator it = itemListMap().begin(); ItemListMap::ConstIterator it = itemListMap().begin();
for (; it != itemListMap().end(); ++it) { for (; it != itemListMap().end(); ++it) {
@@ -236,21 +316,23 @@ PropertyMap APE::Tag::properties() const
if (tagName == keyConversions[i][1]) if (tagName == keyConversions[i][1])
tagName = keyConversions[i][0]; tagName = keyConversions[i][0];
} }
properties[tagName].append(it->second.toStringList()); properties[tagName].append(it->second.values());
} }
} }
return properties; return properties;
} }
void APE::Tag::removeUnsupportedProperties(const StringList &properties) void APE::Tag::removeUnsupportedProperties(const StringList &properties) {
{
StringList::ConstIterator it = properties.begin(); StringList::ConstIterator it = properties.begin();
for (; it != properties.end(); ++it) for (; it != properties.end(); ++it)
removeItem(*it); removeItem(*it);
} }
PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) {
{
PropertyMap properties(origProps); // make a local copy that can be modified PropertyMap properties(origProps); // make a local copy that can be modified
// see comment in properties() // see comment in properties()
@@ -295,31 +377,29 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps)
return invalid; return invalid;
} }
bool APE::Tag::checkKey(const String &key) bool APE::Tag::checkKey(const String &key) {
{
if (key.size() < MinKeyLength || key.size() > MaxKeyLength) if (key.size() < MinKeyLength || key.size() > MaxKeyLength)
return false; return false;
return isKeyValid(key.data(String::UTF8)); return isKeyValid(key.data(String::UTF8));
} }
APE::Footer *APE::Tag::footer() const APE::Footer *APE::Tag::footer() const {
{
return &d->footer; return &d->footer;
} }
const APE::ItemListMap& APE::Tag::itemListMap() const const APE::ItemListMap &APE::Tag::itemListMap() const {
{
return d->itemListMap; return d->itemListMap;
} }
void APE::Tag::removeItem(const String &key) void APE::Tag::removeItem(const String &key) {
{
d->itemListMap.erase(key.upper()); d->itemListMap.erase(key.upper());
} }
void APE::Tag::addValue(const String &key, const String &value, bool replace) void APE::Tag::addValue(const String &key, const String &value, bool replace) {
{
if (replace) if (replace)
removeItem(key); removeItem(key);
@@ -335,30 +415,32 @@ void APE::Tag::addValue(const String &key, const String &value, bool replace)
it->second.appendValue(value); it->second.appendValue(value);
else else
setItem(key, Item(key, value)); setItem(key, Item(key, value));
} }
void APE::Tag::setData(const String &key, const ByteVector &value) void APE::Tag::setData(const String &key, const ByteVector &value) {
{
removeItem(key); removeItem(key);
if (value.isEmpty()) if (value.isEmpty())
return; return;
setItem(key, Item(key, value, true)); setItem(key, Item(key, value, true));
} }
void APE::Tag::setItem(const String &key, const Item &item) void APE::Tag::setItem(const String &key, const Item &item) {
{
if (!checkKey(key)) { if (!checkKey(key)) {
debug("APE::Tag::setItem() - Couldn't set an item due to an invalid key."); debug("APE::Tag::setItem() - Couldn't set an item due to an invalid key.");
return; return;
} }
d->itemListMap[key.upper()] = item; d->itemListMap[key.upper()] = item;
} }
bool APE::Tag::isEmpty() const bool APE::Tag::isEmpty() const {
{
return d->itemListMap.isEmpty(); return d->itemListMap.isEmpty();
} }
@@ -366,8 +448,8 @@ bool APE::Tag::isEmpty() const
// protected methods // protected methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void APE::Tag::read() void APE::Tag::read() {
{
if (d->file && d->file->isValid()) { if (d->file && d->file->isValid()) {
d->file->seek(d->footerLocation); d->file->seek(d->footerLocation);
@@ -380,10 +462,11 @@ void APE::Tag::read()
d->file->seek(d->footerLocation + Footer::size() - d->footer.tagSize()); d->file->seek(d->footerLocation + Footer::size() - d->footer.tagSize());
parse(d->file->readBlock(d->footer.tagSize() - Footer::size())); parse(d->file->readBlock(d->footer.tagSize() - Footer::size()));
} }
} }
ByteVector APE::Tag::render() const ByteVector APE::Tag::render() const {
{
ByteVector data; ByteVector data;
unsigned int itemCount = 0; unsigned int itemCount = 0;
@@ -397,32 +480,30 @@ ByteVector APE::Tag::render() const
d->footer.setHeaderPresent(true); d->footer.setHeaderPresent(true);
return d->footer.renderHeader() + data + d->footer.renderFooter(); return d->footer.renderHeader() + data + d->footer.renderFooter();
} }
void APE::Tag::parse(const ByteVector &data) void APE::Tag::parse(const ByteVector &data) {
{
// 11 bytes is the minimum size for an APE item // 11 bytes is the minimum size for an APE item
if (data.size() < 11) if (data.size() < 11)
return; return;
unsigned int pos = 0; size_t pos = 0;
for (unsigned int i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) { for (unsigned int i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) {
const int nullPos = data.find('\0', pos + 8); const size_t nullPos = data.find('\0', pos + 8);
if(nullPos < 0) { if (nullPos == ByteVector::npos()) {
debug("APE::Tag::parse() - Couldn't find a key/value separator. Stopped parsing."); debug("APE::Tag::parse() - Couldn't find a key/value separator. Stopped parsing.");
return; return;
} }
const unsigned int keyLength = nullPos - pos - 8; const size_t keyLength = nullPos - pos - 8;
const unsigned int valLegnth = data.toUInt(pos, false); const size_t valLegnth = data.toUInt32LE(pos);
if(keyLength >= MinKeyLength if (keyLength >= MinKeyLength && keyLength <= MaxKeyLength && isKeyValid(data.mid(pos + 8, keyLength))) {
&& keyLength <= MaxKeyLength
&& isKeyValid(data.mid(pos + 8, keyLength)))
{
APE::Item item; APE::Item item;
item.parse(data.mid(pos)); item.parse(data.mid(pos));
@@ -434,4 +515,5 @@ void APE::Tag::parse(const ByteVector &data)
pos += keyLength + valLegnth + 9; pos += keyLength + valLegnth + 9;
} }
} }

View File

@@ -34,6 +34,9 @@
#include "apeitem.h" #include "apeitem.h"
#define FRONT_COVER "COVER ART (FRONT)"
#define BACK_COVER "COVER ART (BACK)"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
@@ -50,85 +53,91 @@ namespace TagLib {
* *
* \see APE::Tag::itemListMap() * \see APE::Tag::itemListMap()
*/ */
typedef Map<const String, Item> ItemListMap; typedef Map<String, Item> ItemListMap;
//! An APE tag implementation //! An APE tag implementation
class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
{
public: public:
/*! /*!
* Create an APE tag with default values. * Create an APE tag with default values.
*/ */
Tag(); explicit Tag();
/*! /*!
* Create an APE tag and parse the data in \a file with APE footer at * Create an APE tag and parse the data in \a file with APE footer at
* \a tagOffset. * \a tagOffset.
*/ */
Tag(Strawberry_TagLib::TagLib::File *file, long footerLocation); explicit Tag(Strawberry_TagLib::TagLib::File *file, long long footerLocation);
/*! /*!
* Destroys this Tag instance. * Destroys this Tag instance.
*/ */
virtual ~Tag(); ~Tag() override;
/*! /*!
* Renders the in memory values to a ByteVector suitable for writing to * Renders the in memory values to a ByteVector suitable for writing to the file.
* the file.
*/ */
ByteVector render() const; ByteVector render() const;
/*! /*!
* Returns the string "APETAGEX" suitable for usage in locating the tag in a * Returns the string "APETAGEX" suitable for usage in locating the tag in a file.
* file.
*/ */
static ByteVector fileIdentifier(); static ByteVector fileIdentifier();
// Reimplementations. // Reimplementations.
virtual String title() const; String title() const override;
virtual String artist() const; String artist() const override;
virtual String album() const; String album() const override;
virtual String comment() const; String comment() const override;
virtual String genre() const; String genre() const override;
virtual unsigned int year() const; unsigned int year() const override;
virtual unsigned int track() const; unsigned int track() const override;
virtual void setTitle(const String &s); /**
virtual void setArtist(const String &s); * @brief pictures
virtual void setAlbum(const String &s); * According to :
virtual void setComment(const String &s); * http://www.hydrogenaud.io/forums/index.php?showtopic=40603&st=50&p=504669&#entry504669
virtual void setGenre(const String &s); * http://git.videolan.org/?p=vlc.git;a=blob;f=modules/meta_engine/taglib.cpp
virtual void setYear(unsigned int i); * @return
virtual void setTrack(unsigned int i); */
PictureMap pictures() const override;
void setTitle(const String &s) override;
void setArtist(const String &s) override;
void setAlbum(const String &s) override;
void setComment(const String &s) override;
void setGenre(const String &s) override;
void setYear(unsigned int i) override;
void setTrack(unsigned int i) override;
void setPictures(const PictureMap &l) override;
/*! /*!
* Implements the unified tag dictionary interface -- export function. * Implements the unified tag dictionary interface -- export function.
* APE tags are perfectly compatible with the dictionary interface because they * APE tags are perfectly compatible with the dictionary interface because they
* support both arbitrary tag names and multiple values. Currently only * support both arbitrary tag names and multiple values.
* APE items of type *Text* are handled by the dictionary interface; all *Binary* * Currently only APE items of type *Text* are handled by the dictionary interface; all *Binary*
* and *Locator* items will be put into the unsupportedData list and can be * and *Locator* items will be put into the unsupportedData list and can be
* deleted on request using removeUnsupportedProperties(). The same happens * deleted on request using removeUnsupportedProperties().
* to Text items if their key is invalid for PropertyMap (which should actually * The same happens to Text items if their key is invalid for PropertyMap (which should actually never happen).
* never happen).
* *
* The only conversion done by this export function is to rename the APE tags * The only conversion done by this export function is to rename the APE tags
* TRACK to TRACKNUMBER, YEAR to DATE, and ALBUM ARTIST to ALBUMARTIST, respectively, * TRACK to TRACKNUMBER, YEAR to DATE, and ALBUM ARTIST to ALBUMARTIST,
* in order to be compliant with the names used in other formats. * respectively, in order to be compliant with the names used in other formats.
*/ */
PropertyMap properties() const; PropertyMap properties() const override;
void removeUnsupportedProperties(const StringList &properties); void removeUnsupportedProperties(const StringList &properties) override;
/*! /*!
* Implements the unified tag dictionary interface -- import function. The same * Implements the unified tag dictionary interface -- import function.
* comments as for the export function apply; additionally note that the APE tag * The same comments as for the export function apply; additionally note that the APE tag
* specification requires keys to have between 2 and 16 printable ASCII characters * specification requires keys to have between 2 and 16 printable ASCII characters
* with the exception of the fixed strings "ID3", "TAG", "OGGS", and "MP+". * with the exception of the fixed strings "ID3", "TAG", "OGGS", and "MP+".
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
/*! /*!
* Check if the given String is a valid APE tag key. * Check if the given String is a valid APE tag key.
@@ -141,8 +150,8 @@ namespace TagLib {
Footer *footer() const; Footer *footer() const;
/*! /*!
* Returns a reference to the item list map. This is an ItemListMap of * Returns a reference to the item list map.
* all of the items in the tag. * This is an ItemListMap of all of the items in the tag.
* *
* This is the most powerful structure for accessing the items of the tag. * This is the most powerful structure for accessing the items of the tag.
* *
@@ -160,32 +169,29 @@ namespace TagLib {
void removeItem(const String &key); void removeItem(const String &key);
/*! /*!
* Adds to the text item specified by \a key the data \a value. If \a replace * Adds to the text item specified by \a key the data \a value.
* is true, then all of the other values on the same key will be removed * If \a replace is true, then all of the other values on the same key will be removed first.
* first. If a binary item exists for \a key it will be removed first. * If a binary item exists for \a key it will be removed first.
*/ */
void addValue(const String &key, const String &value, bool replace = true); void addValue(const String &key, const String &value, bool replace = true);
/*! /*!
* Set the binary data for the key specified by \a item to \a value * Set the binary data for the key specified by \a item to \a value
* This will convert the item to type \a Binary if it isn't already and * This will convert the item to type \a Binary if it isn't already and all of the other values on the same key will be removed.
* all of the other values on the same key will be removed.
*/ */
void setData(const String &key, const ByteVector &value); void setData(const String &key, const ByteVector &value);
/*! /*!
* Sets the \a key item to the value of \a item. If an item with the \a key is already * Sets the \a key item to the value of \a item. If an item with the \a key is already present, it will be replaced.
* present, it will be replaced.
*/ */
void setItem(const String &key, const Item &item); void setItem(const String &key, const Item &item);
/*! /*!
* Returns true if the tag does not contain any data. * Returns true if the tag does not contain any data.
*/ */
bool isEmpty() const; bool isEmpty() const override;
protected: protected:
/*! /*!
* Reads from the file specified in the constructor. * Reads from the file specified in the constructor.
*/ */
@@ -203,8 +209,8 @@ namespace TagLib {
class TagPrivate; class TagPrivate;
TagPrivate *d; TagPrivate *d;
}; };
} } // namespace APE
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,9 +23,10 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include <memory>
#include <tdebug.h>
#include <trefcounter.h> #include "taglib.h"
#include "tdebug.h"
#include "asfattribute.h" #include "asfattribute.h"
#include "asffile.h" #include "asffile.h"
@@ -33,15 +34,11 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class ASF::Attribute::AttributePrivate : public RefCounter namespace {
{ struct AttributeData {
public: explicit AttributeData() : numericValue(0), stream(0), language(0) {}
AttributePrivate() :
pictureValue(ASF::Picture::fromInvalid()), ASF::Attribute::AttributeTypes type;
numericValue(0),
stream(0),
language(0) {}
AttributeTypes type;
String stringValue; String stringValue;
ByteVector byteVectorValue; ByteVector byteVectorValue;
ASF::Picture pictureValue; ASF::Picture pictureValue;
@@ -49,143 +46,122 @@ public:
int stream; int stream;
int language; int language;
}; };
} // namespace
class ASF::Attribute::AttributePrivate {
public:
AttributePrivate() : data(new AttributeData()) {
data->pictureValue = ASF::Picture::fromInvalid();
}
std::shared_ptr<AttributeData> data;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ASF::Attribute::Attribute() : ASF::Attribute::Attribute() : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = UnicodeType;
{
d->type = UnicodeType;
} }
ASF::Attribute::Attribute(const ASF::Attribute &other) : ASF::Attribute::Attribute(const ASF::Attribute &other) : d(new AttributePrivate(*other.d)) {}
d(other.d)
{ ASF::Attribute::Attribute(const String &value) : d(new AttributePrivate()) {
d->ref(); d->data->type = UnicodeType;
d->data->stringValue = value;
} }
ASF::Attribute::Attribute(const String &value) : ASF::Attribute::Attribute(const ByteVector &value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = BytesType;
{ d->data->byteVectorValue = value;
d->type = UnicodeType;
d->stringValue = value;
} }
ASF::Attribute::Attribute(const ByteVector &value) : ASF::Attribute::Attribute(const ASF::Picture &value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = BytesType;
{ d->data->pictureValue = value;
d->type = BytesType;
d->byteVectorValue = value;
} }
ASF::Attribute::Attribute(const ASF::Picture &value) : ASF::Attribute::Attribute(unsigned int value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = DWordType;
{ d->data->numericValue = value;
d->type = BytesType;
d->pictureValue = value;
} }
ASF::Attribute::Attribute(unsigned int value) : ASF::Attribute::Attribute(unsigned long long value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = QWordType;
{ d->data->numericValue = value;
d->type = DWordType;
d->numericValue = value;
} }
ASF::Attribute::Attribute(unsigned long long value) : ASF::Attribute::Attribute(unsigned short value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = WordType;
{ d->data->numericValue = value;
d->type = QWordType;
d->numericValue = value;
} }
ASF::Attribute::Attribute(unsigned short value) : ASF::Attribute::Attribute(bool value) : d(new AttributePrivate()) {
d(new AttributePrivate()) d->data->type = BoolType;
{ d->data->numericValue = value;
d->type = WordType;
d->numericValue = value;
} }
ASF::Attribute::Attribute(bool value) : ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other) {
d(new AttributePrivate())
{
d->type = BoolType;
d->numericValue = value;
}
ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
{
Attribute(other).swap(*this); Attribute(other).swap(*this);
return *this; return *this;
} }
void ASF::Attribute::swap(Attribute &other) void ASF::Attribute::swap(Attribute &other) {
{
using std::swap; using std::swap;
swap(d, other.d); swap(d, other.d);
} }
ASF::Attribute::~Attribute() ASF::Attribute::~Attribute() {
{
if(d->deref())
delete d; delete d;
} }
ASF::Attribute::AttributeTypes ASF::Attribute::type() const ASF::Attribute::AttributeTypes ASF::Attribute::type() const {
{ return d->data->type;
return d->type;
} }
String ASF::Attribute::toString() const String ASF::Attribute::toString() const {
{ return d->data->stringValue;
return d->stringValue;
} }
ByteVector ASF::Attribute::toByteVector() const ByteVector ASF::Attribute::toByteVector() const {
{ if (d->data->pictureValue.isValid())
if(d->pictureValue.isValid()) return d->data->pictureValue.render();
return d->pictureValue.render();
return d->byteVectorValue; return d->data->byteVectorValue;
} }
unsigned short ASF::Attribute::toBool() const unsigned short ASF::Attribute::toBool() const {
{ return d->data->numericValue ? 1 : 0;
return d->numericValue ? 1 : 0;
} }
unsigned short ASF::Attribute::toUShort() const unsigned short ASF::Attribute::toUShort() const {
{ return static_cast<unsigned short>(d->data->numericValue);
return static_cast<unsigned short>(d->numericValue);
} }
unsigned int ASF::Attribute::toUInt() const unsigned int ASF::Attribute::toUInt() const {
{ return static_cast<unsigned int>(d->data->numericValue);
return static_cast<unsigned int>(d->numericValue);
} }
unsigned long long ASF::Attribute::toULongLong() const unsigned long long ASF::Attribute::toULongLong() const {
{ return static_cast<unsigned long long>(d->data->numericValue);
return static_cast<unsigned long long>(d->numericValue);
} }
ASF::Picture ASF::Attribute::toPicture() const ASF::Picture ASF::Attribute::toPicture() const {
{ return d->data->pictureValue;
return d->pictureValue;
} }
String ASF::Attribute::parse(ASF::File &f, int kind) String ASF::Attribute::parse(ASF::File &f, int kind) {
{
unsigned int size, nameLength; unsigned int size, nameLength;
String name; String name;
d->pictureValue = Picture::fromInvalid(); d->data->pictureValue = Picture::fromInvalid();
// extended content descriptor // extended content descriptor
if (kind == 0) { if (kind == 0) {
nameLength = readWORD(&f); nameLength = readWORD(&f);
name = readString(&f, nameLength); name = readString(&f, nameLength);
d->type = ASF::Attribute::AttributeTypes(readWORD(&f)); d->data->type = ASF::Attribute::AttributeTypes(readWORD(&f));
size = readWORD(&f); size = readWORD(&f);
} }
// metadata & metadata library // metadata & metadata library
@@ -193,11 +169,11 @@ String ASF::Attribute::parse(ASF::File &f, int kind)
int temp = readWORD(&f); int temp = readWORD(&f);
// metadata library // metadata library
if (kind == 2) { if (kind == 2) {
d->language = temp; d->data->language = temp;
} }
d->stream = readWORD(&f); d->data->stream = readWORD(&f);
nameLength = readWORD(&f); nameLength = readWORD(&f);
d->type = ASF::Attribute::AttributeTypes(readWORD(&f)); d->data->type = ASF::Attribute::AttributeTypes(readWORD(&f));
size = readDWORD(&f); size = readDWORD(&f);
name = readString(&f, nameLength); name = readString(&f, nameLength);
} }
@@ -206,51 +182,52 @@ String ASF::Attribute::parse(ASF::File &f, int kind)
debug("ASF::Attribute::parse() -- Value larger than 64kB"); debug("ASF::Attribute::parse() -- Value larger than 64kB");
} }
switch(d->type) { switch (d->data->type) {
case WordType: case WordType:
d->numericValue = readWORD(&f); d->data->numericValue = readWORD(&f);
break; break;
case BoolType: case BoolType:
if (kind == 0) { if (kind == 0) {
d->numericValue = (readDWORD(&f) != 0); d->data->numericValue = (readDWORD(&f) != 0);
} }
else { else {
d->numericValue = (readWORD(&f) != 0); d->data->numericValue = (readWORD(&f) != 0);
} }
break; break;
case DWordType: case DWordType:
d->numericValue = readDWORD(&f); d->data->numericValue = readDWORD(&f);
break; break;
case QWordType: case QWordType:
d->numericValue = readQWORD(&f); d->data->numericValue = readQWORD(&f);
break; break;
case UnicodeType: case UnicodeType:
d->stringValue = readString(&f, size); d->data->stringValue = readString(&f, size);
break; break;
case BytesType: case BytesType:
case GuidType: case GuidType:
d->byteVectorValue = f.readBlock(size); d->data->byteVectorValue = f.readBlock(size);
break; break;
} }
if(d->type == BytesType && name == "WM/Picture") { if (d->data->type == BytesType && name == "WM/Picture") {
d->pictureValue.parse(d->byteVectorValue); d->data->pictureValue.parse(d->data->byteVectorValue);
if(d->pictureValue.isValid()) { if (d->data->pictureValue.isValid()) {
d->byteVectorValue.clear(); d->data->byteVectorValue.clear();
} }
} }
return name; return name;
} }
int ASF::Attribute::dataSize() const int ASF::Attribute::dataSize() const {
{
switch (d->type) { switch (d->data->type) {
case WordType: case WordType:
return 2; return 2;
case BoolType: case BoolType:
@@ -260,92 +237,92 @@ int ASF::Attribute::dataSize() const
case QWordType: case QWordType:
return 5; return 5;
case UnicodeType: case UnicodeType:
return d->stringValue.size() * 2 + 2; return static_cast<int>(d->data->stringValue.size() * 2 + 2);
case BytesType: case BytesType:
if(d->pictureValue.isValid()) if (d->data->pictureValue.isValid())
return d->pictureValue.dataSize(); return d->data->pictureValue.dataSize();
break;
case GuidType: case GuidType:
return d->byteVectorValue.size(); return static_cast<int>(d->data->byteVectorValue.size());
} }
return 0; return 0;
} }
ByteVector ASF::Attribute::render(const String &name, int kind) const ByteVector ASF::Attribute::render(const String &name, int kind) const {
{
ByteVector data; ByteVector data;
switch (d->type) { switch (d->data->type) {
case WordType: case WordType:
data.append(ByteVector::fromShort(toUShort(), false)); data.append(ByteVector::fromUInt16LE(toUShort()));
break; break;
case BoolType: case BoolType:
if (kind == 0) { if (kind == 0) {
data.append(ByteVector::fromUInt(toBool(), false)); data.append(ByteVector::fromUInt32LE(toBool()));
} }
else { else {
data.append(ByteVector::fromShort(toBool(), false)); data.append(ByteVector::fromUInt16LE(toBool()));
} }
break; break;
case DWordType: case DWordType:
data.append(ByteVector::fromUInt(toUInt(), false)); data.append(ByteVector::fromUInt32LE(toUInt()));
break; break;
case QWordType: case QWordType:
data.append(ByteVector::fromLongLong(toULongLong(), false)); data.append(ByteVector::fromUInt64LE(toULongLong()));
break; break;
case UnicodeType: case UnicodeType:
data.append(renderString(d->stringValue)); data.append(renderString(d->data->stringValue));
break; break;
case BytesType: case BytesType:
if(d->pictureValue.isValid()) { if (d->data->pictureValue.isValid()) {
data.append(d->pictureValue.render()); data.append(d->data->pictureValue.render());
break; break;
} }
break;
case GuidType: case GuidType:
data.append(d->byteVectorValue); data.append(d->data->byteVectorValue);
break; break;
} }
if (kind == 0) { if (kind == 0) {
data = renderString(name, true) + data = renderString(name, true) +
ByteVector::fromShort((int)d->type, false) + ByteVector::fromUInt16LE((int)d->data->type) +
ByteVector::fromShort(data.size(), false) + ByteVector::fromUInt16LE(data.size()) +
data; data;
} }
else { else {
ByteVector nameData = renderString(name); ByteVector nameData = renderString(name);
data = ByteVector::fromShort(kind == 2 ? d->language : 0, false) + data = ByteVector::fromUInt16LE(kind == 2 ? d->data->language : 0) +
ByteVector::fromShort(d->stream, false) + ByteVector::fromUInt16LE(d->data->stream) +
ByteVector::fromShort(nameData.size(), false) + ByteVector::fromUInt16LE(nameData.size()) +
ByteVector::fromShort((int)d->type, false) + ByteVector::fromUInt16LE(static_cast<int>(d->data->type)) +
ByteVector::fromUInt(data.size(), false) + ByteVector::fromUInt32LE(data.size()) +
nameData + nameData +
data; data;
} }
return data; return data;
} }
int ASF::Attribute::language() const int ASF::Attribute::language() const {
{ return d->data->language;
return d->language;
} }
void ASF::Attribute::setLanguage(int value) void ASF::Attribute::setLanguage(int value) {
{ d->data->language = value;
d->language = value;
} }
int ASF::Attribute::stream() const int ASF::Attribute::stream() const {
{ return d->data->stream;
return d->stream;
} }
void ASF::Attribute::setStream(int value) void ASF::Attribute::setStream(int value) {
{ d->data->stream = value;
d->stream = value;
} }

View File

@@ -32,19 +32,14 @@
#include "asfpicture.h" #include "asfpicture.h"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib namespace TagLib {
{ namespace ASF {
namespace ASF
{
class File; class File;
class Picture; class Picture;
class TAGLIB_EXPORT Attribute class TAGLIB_EXPORT Attribute {
{
public: public:
/*! /*!
* Enum of types an Attribute can have. * Enum of types an Attribute can have.
*/ */
@@ -109,7 +104,7 @@ namespace TagLib
/*! /*!
* Construct an attribute as a copy of \a other. * Construct an attribute as a copy of \a other.
*/ */
Attribute(const Attribute &item); Attribute(const Attribute &other);
/*! /*!
* Copies the contents of \a other into this item. * Copies the contents of \a other into this item.
@@ -186,25 +181,20 @@ namespace TagLib
*/ */
void setStream(int value); void setStream(int value);
#ifndef DO_NOT_DOCUMENT
/* THIS IS PRIVATE, DON'T TOUCH IT! */
String parse(ASF::File &file, int kind = 0);
#endif
//! Returns the size of the stored data //! Returns the size of the stored data
int dataSize() const; int dataSize() const;
private: private:
friend class File; friend class File;
String parse(ASF::File &file, int kind = 0);
ByteVector render(const String &name, int kind = 0) const; ByteVector render(const String &name, int kind = 0) const;
class AttributePrivate; class AttributePrivate;
AttributePrivate *d; AttributePrivate *d;
}; };
} } // namespace ASF
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,11 +23,13 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include <memory>
#include <tbytevectorlist.h>
#include <tpropertymap.h> #include "tdebug.h"
#include <tstring.h> #include "tbytevectorlist.h"
#include <tagutils.h> #include "tpropertymap.h"
#include "tstring.h"
#include "tagutils.h"
#include "asffile.h" #include "asffile.h"
#include "asftag.h" #include "asftag.h"
@@ -36,8 +38,7 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class ASF::File::FilePrivate class ASF::File::FilePrivate {
{
public: public:
class BaseObject; class BaseObject;
class UnknownObject; class UnknownObject;
@@ -50,41 +51,26 @@ public:
class MetadataObject; class MetadataObject;
class MetadataLibraryObject; class MetadataLibraryObject;
FilePrivate(): typedef List<std::shared_ptr<BaseObject>> ObjectList;
headerSize(0), typedef ObjectList::ConstIterator ObjectConstIterator;
tag(0),
properties(0),
contentDescriptionObject(0),
extendedContentDescriptionObject(0),
headerExtensionObject(0),
metadataObject(0),
metadataLibraryObject(0)
{
objects.setAutoDelete(true);
}
~FilePrivate() FilePrivate() : headerSize(0) {}
{
delete tag;
delete properties;
}
unsigned long long headerSize; unsigned long long headerSize;
ASF::Tag *tag; std::unique_ptr<ASF::Tag> tag;
ASF::Properties *properties; std::unique_ptr<ASF::AudioProperties> properties;
List<BaseObject *> objects; ObjectList objects;
ContentDescriptionObject *contentDescriptionObject; std::shared_ptr<ContentDescriptionObject> contentDescriptionObject;
ExtendedContentDescriptionObject *extendedContentDescriptionObject; std::shared_ptr<ExtendedContentDescriptionObject> extendedContentDescriptionObject;
HeaderExtensionObject *headerExtensionObject; std::shared_ptr<HeaderExtensionObject> headerExtensionObject;
MetadataObject *metadataObject; std::shared_ptr<MetadataObject> metadataObject;
MetadataLibraryObject *metadataLibraryObject; std::shared_ptr<MetadataLibraryObject> metadataLibraryObject;
}; };
namespace namespace {
{
const ByteVector headerGuid("\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C", 16); const ByteVector headerGuid("\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C", 16);
const ByteVector filePropertiesGuid("\xA1\xDC\xAB\x8C\x47\xA9\xCF\x11\x8E\xE4\x00\xC0\x0C\x20\x53\x65", 16); const ByteVector filePropertiesGuid("\xA1\xDC\xAB\x8C\x47\xA9\xCF\x11\x8E\xE4\x00\xC0\x0C\x20\x53\x65", 16);
const ByteVector streamPropertiesGuid("\x91\x07\xDC\xB7\xB7\xA9\xCF\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65", 16); const ByteVector streamPropertiesGuid("\x91\x07\xDC\xB7\xB7\xA9\xCF\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65", 16);
@@ -97,10 +83,9 @@ namespace
const ByteVector contentEncryptionGuid("\xFB\xB3\x11\x22\x23\xBD\xD2\x11\xB4\xB7\x00\xA0\xC9\x55\xFC\x6E", 16); const ByteVector contentEncryptionGuid("\xFB\xB3\x11\x22\x23\xBD\xD2\x11\xB4\xB7\x00\xA0\xC9\x55\xFC\x6E", 16);
const ByteVector extendedContentEncryptionGuid("\x14\xE6\x8A\x29\x22\x26 \x17\x4C\xB9\x35\xDA\xE0\x7E\xE9\x28\x9C", 16); const ByteVector extendedContentEncryptionGuid("\x14\xE6\x8A\x29\x22\x26 \x17\x4C\xB9\x35\xDA\xE0\x7E\xE9\x28\x9C", 16);
const ByteVector advancedContentEncryptionGuid("\xB6\x9B\x07\x7A\xA4\xDA\x12\x4E\xA5\xCA\x91\xD3\x8D\xC1\x1A\x8D", 16); const ByteVector advancedContentEncryptionGuid("\xB6\x9B\x07\x7A\xA4\xDA\x12\x4E\xA5\xCA\x91\xD3\x8D\xC1\x1A\x8D", 16);
} } // namespace
class ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVector data; ByteVector data;
virtual ~BaseObject() {} virtual ~BaseObject() {}
@@ -109,156 +94,143 @@ public:
virtual ByteVector render(ASF::File *file); virtual ByteVector render(ASF::File *file);
}; };
class ASF::File::FilePrivate::UnknownObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::UnknownObject : public ASF::File::FilePrivate::BaseObject {
{
ByteVector myGuid; ByteVector myGuid;
public: public:
explicit UnknownObject(const ByteVector &guid); explicit UnknownObject(const ByteVector &guid);
ByteVector guid() const; ByteVector guid() const override;
}; };
class ASF::File::FilePrivate::FilePropertiesObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::FilePropertiesObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
}; };
class ASF::File::FilePrivate::StreamPropertiesObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::StreamPropertiesObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
}; };
class ASF::File::FilePrivate::ContentDescriptionObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::ContentDescriptionObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
ByteVector render(ASF::File *file); ByteVector render(ASF::File *file) override;
}; };
class ASF::File::FilePrivate::ExtendedContentDescriptionObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::ExtendedContentDescriptionObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVectorList attributeData; ByteVectorList attributeData;
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
ByteVector render(ASF::File *file); ByteVector render(ASF::File *file) override;
}; };
class ASF::File::FilePrivate::MetadataObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::MetadataObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVectorList attributeData; ByteVectorList attributeData;
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
ByteVector render(ASF::File *file); ByteVector render(ASF::File *file) override;
}; };
class ASF::File::FilePrivate::MetadataLibraryObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::MetadataLibraryObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVectorList attributeData; ByteVectorList attributeData;
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
ByteVector render(ASF::File *file); ByteVector render(ASF::File *file) override;
}; };
class ASF::File::FilePrivate::HeaderExtensionObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::HeaderExtensionObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
List<ASF::File::FilePrivate::BaseObject *> objects; ObjectList objects;
HeaderExtensionObject(); HeaderExtensionObject();
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
ByteVector render(ASF::File *file); ByteVector render(ASF::File *file) override;
}; };
class ASF::File::FilePrivate::CodecListObject : public ASF::File::FilePrivate::BaseObject class ASF::File::FilePrivate::CodecListObject : public ASF::File::FilePrivate::BaseObject {
{
public: public:
ByteVector guid() const; ByteVector guid() const override;
void parse(ASF::File *file, unsigned int size); void parse(ASF::File *file, unsigned int size) override;
private: private:
enum CodecType enum CodecType {
{
Video = 0x0001, Video = 0x0001,
Audio = 0x0002, Audio = 0x0002,
Unknown = 0xFFFF Unknown = 0xFFFF
}; };
}; };
void ASF::File::FilePrivate::BaseObject::parse(ASF::File *file, unsigned int size) void ASF::File::FilePrivate::BaseObject::parse(ASF::File *file, unsigned int size) {
{
data.clear(); data.clear();
if(size > 24 && size <= (unsigned int)(file->length())) if (size > 24 && static_cast<long long>(size) <= file->length())
data = file->readBlock(size - 24); data = file->readBlock(size - 24);
else else
data = ByteVector(); data = ByteVector();
} }
ByteVector ASF::File::FilePrivate::BaseObject::render(ASF::File * /*file*/) ByteVector ASF::File::FilePrivate::BaseObject::render(ASF::File * /*file*/) {
{ return guid() + ByteVector::fromUInt64LE(data.size() + 24) + data;
return guid() + ByteVector::fromLongLong(data.size() + 24, false) + data;
} }
ASF::File::FilePrivate::UnknownObject::UnknownObject(const ByteVector &guid) : myGuid(guid) ASF::File::FilePrivate::UnknownObject::UnknownObject(const ByteVector &guid) : myGuid(guid) {}
{
}
ByteVector ASF::File::FilePrivate::UnknownObject::guid() const ByteVector ASF::File::FilePrivate::UnknownObject::guid() const {
{
return myGuid; return myGuid;
} }
ByteVector ASF::File::FilePrivate::FilePropertiesObject::guid() const ByteVector ASF::File::FilePrivate::FilePropertiesObject::guid() const {
{
return filePropertiesGuid; return filePropertiesGuid;
} }
void ASF::File::FilePrivate::FilePropertiesObject::parse(ASF::File *file, unsigned int size) void ASF::File::FilePrivate::FilePropertiesObject::parse(ASF::File *file, unsigned int size) {
{
BaseObject::parse(file, size); BaseObject::parse(file, size);
if (data.size() < 64) { if (data.size() < 64) {
debug("ASF::File::FilePrivate::FilePropertiesObject::parse() -- data is too short."); debug("ASF::File::FilePrivate::FilePropertiesObject::parse() -- data is too short.");
return; return;
} }
const long long duration = data.toLongLong(40, false); const long long duration = data.toInt64LE(40);
const long long preroll = data.toLongLong(56, false); const long long preroll = data.toInt64LE(56);
file->d->properties->setLengthInMilliseconds(static_cast<int>(duration / 10000.0 - preroll + 0.5)); file->d->properties->setLengthInMilliseconds(static_cast<int>(duration / 10000.0 - preroll + 0.5));
} }
ByteVector ASF::File::FilePrivate::StreamPropertiesObject::guid() const ByteVector ASF::File::FilePrivate::StreamPropertiesObject::guid() const {
{
return streamPropertiesGuid; return streamPropertiesGuid;
} }
void ASF::File::FilePrivate::StreamPropertiesObject::parse(ASF::File *file, unsigned int size) void ASF::File::FilePrivate::StreamPropertiesObject::parse(ASF::File *file, unsigned int size) {
{
BaseObject::parse(file, size); BaseObject::parse(file, size);
if (data.size() < 70) { if (data.size() < 70) {
debug("ASF::File::FilePrivate::StreamPropertiesObject::parse() -- data is too short."); debug("ASF::File::FilePrivate::StreamPropertiesObject::parse() -- data is too short.");
return; return;
} }
file->d->properties->setCodec(data.toUShort(54, false)); file->d->properties->setCodec(data.toUInt16LE(54));
file->d->properties->setChannels(data.toUShort(56, false)); file->d->properties->setChannels(data.toUInt16LE(56));
file->d->properties->setSampleRate(data.toUInt(58, false)); file->d->properties->setSampleRate(data.toUInt32LE(58));
file->d->properties->setBitrate(static_cast<int>(data.toUInt(62, false) * 8.0 / 1000.0 + 0.5)); file->d->properties->setBitrate(static_cast<int>(data.toUInt32LE(62) * 8.0 / 1000.0 + 0.5));
file->d->properties->setBitsPerSample(data.toUShort(68, false)); file->d->properties->setBitsPerSample(data.toUInt16LE(68));
} }
ByteVector ASF::File::FilePrivate::ContentDescriptionObject::guid() const ByteVector ASF::File::FilePrivate::ContentDescriptionObject::guid() const {
{
return contentDescriptionGuid; return contentDescriptionGuid;
} }
void ASF::File::FilePrivate::ContentDescriptionObject::parse(ASF::File *file, unsigned int /*size*/) void ASF::File::FilePrivate::ContentDescriptionObject::parse(ASF::File *file, unsigned int /*size*/) {
{
const int titleLength = readWORD(file); const int titleLength = readWORD(file);
const int artistLength = readWORD(file); const int artistLength = readWORD(file);
const int copyrightLength = readWORD(file); const int copyrightLength = readWORD(file);
@@ -269,110 +241,113 @@ void ASF::File::FilePrivate::ContentDescriptionObject::parse(ASF::File *file, un
file->d->tag->setCopyright(readString(file, copyrightLength)); file->d->tag->setCopyright(readString(file, copyrightLength));
file->d->tag->setComment(readString(file, commentLength)); file->d->tag->setComment(readString(file, commentLength));
file->d->tag->setRating(readString(file, ratingLength)); file->d->tag->setRating(readString(file, ratingLength));
} }
ByteVector ASF::File::FilePrivate::ContentDescriptionObject::render(ASF::File *file) ByteVector ASF::File::FilePrivate::ContentDescriptionObject::render(ASF::File *file) {
{
const ByteVector v1 = renderString(file->d->tag->title()); const ByteVector v1 = renderString(file->d->tag->title());
const ByteVector v2 = renderString(file->d->tag->artist()); const ByteVector v2 = renderString(file->d->tag->artist());
const ByteVector v3 = renderString(file->d->tag->copyright()); const ByteVector v3 = renderString(file->d->tag->copyright());
const ByteVector v4 = renderString(file->d->tag->comment()); const ByteVector v4 = renderString(file->d->tag->comment());
const ByteVector v5 = renderString(file->d->tag->rating()); const ByteVector v5 = renderString(file->d->tag->rating());
data.clear(); data.clear();
data.append(ByteVector::fromShort(v1.size(), false)); data.append(ByteVector::fromUInt16LE(v1.size()));
data.append(ByteVector::fromShort(v2.size(), false)); data.append(ByteVector::fromUInt16LE(v2.size()));
data.append(ByteVector::fromShort(v3.size(), false)); data.append(ByteVector::fromUInt16LE(v3.size()));
data.append(ByteVector::fromShort(v4.size(), false)); data.append(ByteVector::fromUInt16LE(v4.size()));
data.append(ByteVector::fromShort(v5.size(), false)); data.append(ByteVector::fromUInt16LE(v5.size()));
data.append(v1); data.append(v1);
data.append(v2); data.append(v2);
data.append(v3); data.append(v3);
data.append(v4); data.append(v4);
data.append(v5); data.append(v5);
return BaseObject::render(file); return BaseObject::render(file);
} }
ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::guid() const ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::guid() const {
{
return extendedContentDescriptionGuid; return extendedContentDescriptionGuid;
} }
void ASF::File::FilePrivate::ExtendedContentDescriptionObject::parse(ASF::File *file, unsigned int /*size*/) void ASF::File::FilePrivate::ExtendedContentDescriptionObject::parse(ASF::File *file, unsigned int /*size*/) {
{
int count = readWORD(file); int count = readWORD(file);
while (count--) { while (count--) {
ASF::Attribute attribute; ASF::Attribute attribute;
String name = attribute.parse(*file); String name = attribute.parse(*file);
file->d->tag->addAttribute(name, attribute); file->d->tag->addAttribute(name, attribute);
} }
} }
ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::render(ASF::File *file) ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::render(ASF::File *file) {
{
data.clear(); data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false)); data.append(ByteVector::fromUInt16LE(attributeData.size()));
data.append(attributeData.toByteVector("")); data.append(attributeData.toByteVector(""));
return BaseObject::render(file); return BaseObject::render(file);
} }
ByteVector ASF::File::FilePrivate::MetadataObject::guid() const ByteVector ASF::File::FilePrivate::MetadataObject::guid() const {
{
return metadataGuid; return metadataGuid;
} }
void ASF::File::FilePrivate::MetadataObject::parse(ASF::File *file, unsigned int /*size*/) void ASF::File::FilePrivate::MetadataObject::parse(ASF::File *file, unsigned int /*size*/) {
{
int count = readWORD(file); int count = readWORD(file);
while (count--) { while (count--) {
ASF::Attribute attribute; ASF::Attribute attribute;
String name = attribute.parse(*file, 1); String name = attribute.parse(*file, 1);
file->d->tag->addAttribute(name, attribute); file->d->tag->addAttribute(name, attribute);
} }
} }
ByteVector ASF::File::FilePrivate::MetadataObject::render(ASF::File *file) ByteVector ASF::File::FilePrivate::MetadataObject::render(ASF::File *file) {
{
data.clear(); data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false)); data.append(ByteVector::fromUInt16LE(attributeData.size()));
data.append(attributeData.toByteVector("")); data.append(attributeData.toByteVector(""));
return BaseObject::render(file); return BaseObject::render(file);
} }
ByteVector ASF::File::FilePrivate::MetadataLibraryObject::guid() const ByteVector ASF::File::FilePrivate::MetadataLibraryObject::guid() const {
{
return metadataLibraryGuid; return metadataLibraryGuid;
} }
void ASF::File::FilePrivate::MetadataLibraryObject::parse(ASF::File *file, unsigned int /*size*/) void ASF::File::FilePrivate::MetadataLibraryObject::parse(ASF::File *file, unsigned int /*size*/) {
{
int count = readWORD(file); int count = readWORD(file);
while (count--) { while (count--) {
ASF::Attribute attribute; ASF::Attribute attribute;
String name = attribute.parse(*file, 2); String name = attribute.parse(*file, 2);
file->d->tag->addAttribute(name, attribute); file->d->tag->addAttribute(name, attribute);
} }
} }
ByteVector ASF::File::FilePrivate::MetadataLibraryObject::render(ASF::File *file) ByteVector ASF::File::FilePrivate::MetadataLibraryObject::render(ASF::File *file) {
{
data.clear(); data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false)); data.append(ByteVector::fromUInt16LE(attributeData.size()));
data.append(attributeData.toByteVector("")); data.append(attributeData.toByteVector(""));
return BaseObject::render(file); return BaseObject::render(file);
} }
ASF::File::FilePrivate::HeaderExtensionObject::HeaderExtensionObject() ASF::File::FilePrivate::HeaderExtensionObject::HeaderExtensionObject() {
{
objects.setAutoDelete(true); objects.setAutoDelete(true);
} }
ByteVector ASF::File::FilePrivate::HeaderExtensionObject::guid() const ByteVector ASF::File::FilePrivate::HeaderExtensionObject::guid() const {
{
return headerExtensionGuid; return headerExtensionGuid;
} }
void ASF::File::FilePrivate::HeaderExtensionObject::parse(ASF::File *file, unsigned int /*size*/) void ASF::File::FilePrivate::HeaderExtensionObject::parse(ASF::File *file, unsigned int /*size*/) {
{
file->seek(18, File::Current); file->seek(18, File::Current);
long long dataSize = readDWORD(file); long long dataSize = readDWORD(file);
long long dataPos = 0; long long dataPos = 0;
@@ -388,41 +363,42 @@ void ASF::File::FilePrivate::HeaderExtensionObject::parse(ASF::File *file, unsig
file->setValid(false); file->setValid(false);
break; break;
} }
BaseObject *obj; std::shared_ptr<BaseObject> obj;
if (guid == metadataGuid) { if (guid == metadataGuid) {
file->d->metadataObject = new MetadataObject(); file->d->metadataObject.reset(new MetadataObject());
obj = file->d->metadataObject; obj = file->d->metadataObject;
} }
else if (guid == metadataLibraryGuid) { else if (guid == metadataLibraryGuid) {
file->d->metadataLibraryObject = new MetadataLibraryObject(); file->d->metadataLibraryObject.reset(new MetadataLibraryObject());
obj = file->d->metadataLibraryObject; obj = file->d->metadataLibraryObject;
} }
else { else {
obj = new UnknownObject(guid); obj.reset(new UnknownObject(guid));
} }
obj->parse(file, (unsigned int)size); obj->parse(file, static_cast<unsigned int>(size));
objects.append(obj); objects.append(obj);
dataPos += size; dataPos += size;
} }
} }
ByteVector ASF::File::FilePrivate::HeaderExtensionObject::render(ASF::File *file) ByteVector ASF::File::FilePrivate::HeaderExtensionObject::render(ASF::File *file) {
{
data.clear(); data.clear();
for(List<BaseObject *>::ConstIterator it = objects.begin(); it != objects.end(); ++it) { for (ObjectConstIterator it = objects.begin(); it != objects.end(); ++it) {
data.append((*it)->render(file)); data.append((*it)->render(file));
} }
data = ByteVector("\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65\x06\x00", 18) + ByteVector::fromUInt(data.size(), false) + data; data = ByteVector("\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65\x06\x00", 18) + ByteVector::fromUInt32LE(data.size()) + data;
return BaseObject::render(file); return BaseObject::render(file);
} }
ByteVector ASF::File::FilePrivate::CodecListObject::guid() const ByteVector ASF::File::FilePrivate::CodecListObject::guid() const {
{
return codecListGuid; return codecListGuid;
} }
void ASF::File::FilePrivate::CodecListObject::parse(ASF::File *file, unsigned int size) void ASF::File::FilePrivate::CodecListObject::parse(ASF::File *file, unsigned int size) {
{
BaseObject::parse(file, size); BaseObject::parse(file, size);
if (data.size() <= 20) { if (data.size() <= 20) {
debug("ASF::File::FilePrivate::CodecListObject::parse() -- data is too short."); debug("ASF::File::FilePrivate::CodecListObject::parse() -- data is too short.");
@@ -431,7 +407,7 @@ void ASF::File::FilePrivate::CodecListObject::parse(ASF::File *file, unsigned in
unsigned int pos = 16; unsigned int pos = 16;
const int count = data.toUInt(pos, false); const int count = data.toUInt32LE(pos);
pos += 4; pos += 4;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
@@ -439,22 +415,22 @@ void ASF::File::FilePrivate::CodecListObject::parse(ASF::File *file, unsigned in
if (pos >= data.size()) if (pos >= data.size())
break; break;
const CodecType type = static_cast<CodecType>(data.toUShort(pos, false)); const CodecType type = static_cast<CodecType>(data.toUInt16LE(pos));
pos += 2; pos += 2;
int nameLength = data.toUShort(pos, false); int nameLength = data.toUInt16LE(pos);
pos += 2; pos += 2;
const unsigned int namePos = pos; const unsigned int namePos = pos;
pos += nameLength * 2; pos += nameLength * 2;
const int descLength = data.toUShort(pos, false); const int descLength = data.toUInt16LE(pos);
pos += 2; pos += 2;
const unsigned int descPos = pos; const unsigned int descPos = pos;
pos += descLength * 2; pos += descLength * 2;
const int infoLength = data.toUShort(pos, false); const int infoLength = data.toUInt16LE(pos);
pos += 2 + infoLength * 2; pos += 2 + infoLength * 2;
if (type == CodecListObject::Audio) { if (type == CodecListObject::Audio) {
@@ -469,72 +445,50 @@ void ASF::File::FilePrivate::CodecListObject::parse(ASF::File *file, unsigned in
break; break;
} }
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool ASF::File::isSupported(IOStream *stream) bool ASF::File::isSupported(IOStream *stream) {
{
// An ASF file has to start with the designated GUID. // An ASF file has to start with the designated GUID.
const ByteVector id = Utils::readHeader(stream, 16, false); const ByteVector id = Utils::readHeader(stream, 16, false);
return (id == headerGuid); return (id == headerGuid);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ASF::File::File(FileName file, bool, Properties::ReadStyle) : ASF::File::File(FileName file, bool, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(); read();
} }
ASF::File::File(IOStream *stream, bool, Properties::ReadStyle) : ASF::File::File(IOStream *stream, bool, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(); read();
} }
ASF::File::~File() ASF::File::~File() {
{
delete d; delete d;
} }
ASF::Tag *ASF::File::tag() const ASF::Tag *ASF::File::tag() const {
{ return d->tag.get();
return d->tag;
} }
PropertyMap ASF::File::properties() const ASF::AudioProperties *ASF::File::audioProperties() const {
{ return d->properties.get();
return d->tag->properties();
} }
void ASF::File::removeUnsupportedProperties(const StringList &properties) bool ASF::File::save() {
{
d->tag->removeUnsupportedProperties(properties);
}
PropertyMap ASF::File::setProperties(const PropertyMap &properties)
{
return d->tag->setProperties(properties);
}
ASF::Properties *ASF::File::audioProperties() const
{
return d->properties;
}
bool ASF::File::save()
{
if (readOnly()) { if (readOnly()) {
debug("ASF::File::save() -- File is read only."); debug("ASF::File::save() -- File is read only.");
return false; return false;
@@ -546,23 +500,23 @@ bool ASF::File::save()
} }
if (!d->contentDescriptionObject) { if (!d->contentDescriptionObject) {
d->contentDescriptionObject = new FilePrivate::ContentDescriptionObject(); d->contentDescriptionObject.reset(new FilePrivate::ContentDescriptionObject());
d->objects.append(d->contentDescriptionObject); d->objects.append(d->contentDescriptionObject);
} }
if (!d->extendedContentDescriptionObject) { if (!d->extendedContentDescriptionObject) {
d->extendedContentDescriptionObject = new FilePrivate::ExtendedContentDescriptionObject(); d->extendedContentDescriptionObject.reset(new FilePrivate::ExtendedContentDescriptionObject());
d->objects.append(d->extendedContentDescriptionObject); d->objects.append(d->extendedContentDescriptionObject);
} }
if (!d->headerExtensionObject) { if (!d->headerExtensionObject) {
d->headerExtensionObject = new FilePrivate::HeaderExtensionObject(); d->headerExtensionObject.reset(new FilePrivate::HeaderExtensionObject());
d->objects.append(d->headerExtensionObject); d->objects.append(d->headerExtensionObject);
} }
if (!d->metadataObject) { if (!d->metadataObject) {
d->metadataObject = new FilePrivate::MetadataObject(); d->metadataObject.reset(new FilePrivate::MetadataObject());
d->headerExtensionObject->objects.append(d->metadataObject); d->headerExtensionObject->objects.append(d->metadataObject);
} }
if (!d->metadataLibraryObject) { if (!d->metadataLibraryObject) {
d->metadataLibraryObject = new FilePrivate::MetadataLibraryObject(); d->metadataLibraryObject.reset(new FilePrivate::MetadataLibraryObject());
d->headerExtensionObject->objects.append(d->metadataLibraryObject); d->headerExtensionObject->objects.append(d->metadataLibraryObject);
} }
@@ -601,28 +555,29 @@ bool ASF::File::save()
} }
ByteVector data; ByteVector data;
for(List<FilePrivate::BaseObject *>::ConstIterator it = d->objects.begin(); it != d->objects.end(); ++it) { for (FilePrivate::ObjectConstIterator it = d->objects.begin(); it != d->objects.end(); ++it) {
data.append((*it)->render(this)); data.append((*it)->render(this));
} }
seek(16); seek(16);
writeBlock(ByteVector::fromLongLong(data.size() + 30, false)); writeBlock(ByteVector::fromUInt64LE(data.size() + 30));
writeBlock(ByteVector::fromUInt(d->objects.size(), false)); writeBlock(ByteVector::fromUInt32LE(d->objects.size()));
writeBlock(ByteVector("\x01\x02", 2)); writeBlock(ByteVector("\x01\x02", 2));
insert(data, 30, static_cast<unsigned long>(d->headerSize - 30)); insert(data, 30, static_cast<size_t>(d->headerSize - 30));
d->headerSize = data.size() + 30; d->headerSize = data.size() + 30;
return true; return true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ASF::File::read() void ASF::File::read() {
{
if (!isValid()) if (!isValid())
return; return;
@@ -632,8 +587,8 @@ void ASF::File::read()
return; return;
} }
d->tag = new ASF::Tag(); d->tag.reset(new ASF::Tag());
d->properties = new ASF::Properties(); d->properties.reset(new ASF::AudioProperties());
bool ok; bool ok;
d->headerSize = readQWORD(this, &ok); d->headerSize = readQWORD(this, &ok);
@@ -648,42 +603,42 @@ void ASF::File::read()
} }
seek(2, Current); seek(2, Current);
FilePrivate::FilePropertiesObject *filePropertiesObject = 0; std::shared_ptr<FilePrivate::FilePropertiesObject> filePropertiesObject;
FilePrivate::StreamPropertiesObject *streamPropertiesObject = 0; std::shared_ptr<FilePrivate::StreamPropertiesObject> streamPropertiesObject;
for (int i = 0; i < numObjects; i++) { for (int i = 0; i < numObjects; i++) {
const ByteVector guid = readBlock(16); const ByteVector guid = readBlock(16);
if (guid.size() != 16) { if (guid.size() != 16) {
setValid(false); setValid(false);
break; break;
} }
long size = (long)readQWORD(this, &ok); long size = static_cast<long>(readQWORD(this, &ok));
if (!ok) { if (!ok) {
setValid(false); setValid(false);
break; break;
} }
FilePrivate::BaseObject *obj; std::shared_ptr<FilePrivate::BaseObject> obj;
if (guid == filePropertiesGuid) { if (guid == filePropertiesGuid) {
filePropertiesObject = new FilePrivate::FilePropertiesObject(); filePropertiesObject.reset(new FilePrivate::FilePropertiesObject());
obj = filePropertiesObject; obj = filePropertiesObject;
} }
else if (guid == streamPropertiesGuid) { else if (guid == streamPropertiesGuid) {
streamPropertiesObject = new FilePrivate::StreamPropertiesObject(); streamPropertiesObject.reset(new FilePrivate::StreamPropertiesObject());
obj = streamPropertiesObject; obj = streamPropertiesObject;
} }
else if (guid == contentDescriptionGuid) { else if (guid == contentDescriptionGuid) {
d->contentDescriptionObject = new FilePrivate::ContentDescriptionObject(); d->contentDescriptionObject.reset(new FilePrivate::ContentDescriptionObject());
obj = d->contentDescriptionObject; obj = d->contentDescriptionObject;
} }
else if (guid == extendedContentDescriptionGuid) { else if (guid == extendedContentDescriptionGuid) {
d->extendedContentDescriptionObject = new FilePrivate::ExtendedContentDescriptionObject(); d->extendedContentDescriptionObject.reset(new FilePrivate::ExtendedContentDescriptionObject());
obj = d->extendedContentDescriptionObject; obj = d->extendedContentDescriptionObject;
} }
else if (guid == headerExtensionGuid) { else if (guid == headerExtensionGuid) {
d->headerExtensionObject = new FilePrivate::HeaderExtensionObject(); d->headerExtensionObject.reset(new FilePrivate::HeaderExtensionObject());
obj = d->headerExtensionObject; obj = d->headerExtensionObject;
} }
else if (guid == codecListGuid) { else if (guid == codecListGuid) {
obj = new FilePrivate::CodecListObject(); obj.reset(new FilePrivate::CodecListObject());
} }
else { else {
if (guid == contentEncryptionGuid || if (guid == contentEncryptionGuid ||
@@ -691,7 +646,7 @@ void ASF::File::read()
guid == advancedContentEncryptionGuid) { guid == advancedContentEncryptionGuid) {
d->properties->setEncrypted(true); d->properties->setEncrypted(true);
} }
obj = new FilePrivate::UnknownObject(guid); obj.reset(new FilePrivate::UnknownObject(guid));
} }
obj->parse(this, size); obj->parse(this, size);
d->objects.append(obj); d->objects.append(obj);
@@ -702,4 +657,5 @@ void ASF::File::read()
setValid(false); setValid(false);
return; return;
} }
} }

View File

@@ -44,10 +44,8 @@ namespace TagLib {
* the abstract TagLib::File API as well as providing some additional * the abstract TagLib::File API as well as providing some additional
* information specific to ASF files. * information specific to ASF files.
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* Constructs an ASF file from \a file. * Constructs an ASF file from \a file.
* *
@@ -55,8 +53,7 @@ namespace TagLib {
* \a propertiesStyle are ignored. The audio properties are always * \a propertiesStyle are ignored. The audio properties are always
* read. * read.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an ASF file from \a stream. * Constructs an ASF file from \a stream.
@@ -68,13 +65,12 @@ namespace TagLib {
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object. * responsible for deleting it after the File object.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns a pointer to the ASF tag of the file. * Returns a pointer to the ASF tag of the file.
@@ -86,42 +82,24 @@ namespace TagLib {
* deleted by the user. It will be deleted when the file (object) is * deleted by the user. It will be deleted when the file (object) is
* destroyed. * destroyed.
*/ */
virtual Tag *tag() const; Tag *tag() const override;
/*!
* Implements the unified property interface -- export function.
*/
PropertyMap properties() const;
/*!
* Removes unsupported properties. Forwards to the actual Tag's
* removeUnsupportedProperties() function.
*/
void removeUnsupportedProperties(const StringList &properties);
/*!
* Implements the unified property interface -- import function.
*/
PropertyMap setProperties(const PropertyMap &);
/*! /*!
* Returns the ASF audio properties for this file. * Returns the ASF audio properties for this file.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Save the file. * Save the file.
* *
* This returns true if the save was successful. * This returns true if the save was successful.
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Returns whether or not the given \a stream can be opened as an ASF * Returns whether or not the given \a stream can be opened as an ASF file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check. The result may not necessarily be correct.
* not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -132,9 +110,9 @@ namespace TagLib {
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace ASF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,9 +23,10 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include <memory>
#include <tdebug.h>
#include <trefcounter.h> #include "taglib.h"
#include "tdebug.h"
#include "asfattribute.h" #include "asfattribute.h"
#include "asffile.h" #include "asffile.h"
@@ -34,150 +35,134 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class ASF::Picture::PicturePrivate : public RefCounter namespace {
{ struct PictureData {
public:
bool valid; bool valid;
Type type; ASF::Picture::Type type;
String mimeType; String mimeType;
String description; String description;
ByteVector picture; ByteVector picture;
}; };
} // namespace
class ASF::Picture::PicturePrivate {
public:
explicit PicturePrivate() : data(new PictureData()) {}
std::shared_ptr<PictureData> data;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Picture class members // Picture class members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ASF::Picture::Picture() : ASF::Picture::Picture() : d(new PicturePrivate()) {
d(new PicturePrivate()) d->data->valid = true;
{
d->valid = true;
} }
ASF::Picture::Picture(const Picture& other) : ASF::Picture::Picture(const Picture& other) : d(new PicturePrivate(*other.d)) {}
d(other.d)
{
d->ref();
}
ASF::Picture::~Picture() ASF::Picture::~Picture() {
{
if(d->deref())
delete d; delete d;
} }
bool ASF::Picture::isValid() const bool ASF::Picture::isValid() const {
{ return d->data->valid;
return d->valid;
} }
String ASF::Picture::mimeType() const String ASF::Picture::mimeType() const {
{ return d->data->mimeType;
return d->mimeType;
} }
void ASF::Picture::setMimeType(const String &value) void ASF::Picture::setMimeType(const String& value) {
{ d->data->mimeType = value;
d->mimeType = value;
} }
ASF::Picture::Type ASF::Picture::type() const ASF::Picture::Type ASF::Picture::type() const {
{ return d->data->type;
return d->type;
} }
void ASF::Picture::setType(const ASF::Picture::Type& t) void ASF::Picture::setType(const ASF::Picture::Type &t) {
{ d->data->type = t;
d->type = t;
} }
String ASF::Picture::description() const String ASF::Picture::description() const {
{ return d->data->description;
return d->description;
} }
void ASF::Picture::setDescription(const String &desc) void ASF::Picture::setDescription(const String& desc) {
{ d->data->description = desc;
d->description = desc;
} }
ByteVector ASF::Picture::picture() const ByteVector ASF::Picture::picture() const {
{ return d->data->picture;
return d->picture;
} }
void ASF::Picture::setPicture(const ByteVector &p) void ASF::Picture::setPicture(const ByteVector &p) {
{ d->data->picture = p;
d->picture = p;
} }
int ASF::Picture::dataSize() const int ASF::Picture::dataSize() const {
{ return 9 + (d->data->mimeType.length() + d->data->description.length()) * 2 + d->data->picture.size();
return
9 + (d->mimeType.length() + d->description.length()) * 2 +
d->picture.size();
} }
ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other) ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other) {
{
Picture(other).swap(*this); Picture(other).swap(*this);
return *this; return *this;
} }
void ASF::Picture::swap(Picture &other) void ASF::Picture::swap(Picture& other) {
{
using std::swap; using std::swap;
swap(d, other.d); swap(d, other.d);
} }
ByteVector ASF::Picture::render() const ByteVector ASF::Picture::render() const {
{
if (!isValid()) if (!isValid())
return ByteVector(); return ByteVector();
return return ByteVector(static_cast<char>(d->data->type)) + ByteVector::fromUInt32LE(d->data->picture.size()) + renderString(d->data->mimeType) + renderString(d->data->description) + d->data->picture;
ByteVector((char)d->type) +
ByteVector::fromUInt(d->picture.size(), false) +
renderString(d->mimeType) +
renderString(d->description) +
d->picture;
} }
void ASF::Picture::parse(const ByteVector& bytes) void ASF::Picture::parse(const ByteVector &bytes) {
{
d->valid = false; d->data->valid = false;
if (bytes.size() < 9) if (bytes.size() < 9)
return; return;
int pos = 0; size_t pos = 0;
d->type = (Type)bytes[0]; ++pos; d->data->type = static_cast<Type>(bytes[0]);
const unsigned int dataLen = bytes.toUInt(pos, false); pos+=4; ++pos;
const unsigned int dataLen = bytes.toUInt32LE(pos);
pos += 4;
const ByteVector nullStringTerminator(2, 0); const ByteVector nullStringTerminator(2, 0);
int endPos = bytes.find(nullStringTerminator, pos, 2); size_t endPos = bytes.find(nullStringTerminator, pos, 2);
if(endPos < 0) if (endPos == ByteVector::npos())
return; return;
d->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE); d->data->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
pos = endPos + 2; pos = endPos + 2;
endPos = bytes.find(nullStringTerminator, pos, 2); endPos = bytes.find(nullStringTerminator, pos, 2);
if(endPos < 0) if (endPos == ByteVector::npos())
return; return;
d->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE); d->data->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE);
pos = endPos + 2; pos = endPos + 2;
if (dataLen + pos != bytes.size()) if (dataLen + pos != bytes.size())
return; return;
d->picture = bytes.mid(pos, dataLen); d->data->picture = bytes.mid(pos, dataLen);
d->valid = true; d->data->valid = true;
return;
} }
ASF::Picture ASF::Picture::fromInvalid() ASF::Picture ASF::Picture::fromInvalid() {
{
Picture ret; Picture ret;
ret.d->valid = false; ret.d->data->valid = false;
return ret; return ret;
} }

View File

@@ -32,24 +32,21 @@
#include "attachedpictureframe.h" #include "attachedpictureframe.h"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib namespace TagLib {
{ namespace ASF {
namespace ASF class Attribute;
{
//! An ASF attached picture interface implementation //! An ASF attached picture interface implementation
/*! /*!
* This is an implementation of ASF attached pictures interface. Pictures may be * This is an implementation of ASF attached pictures interface.
* included in attributes, one per WM/Picture attribute (but there may be multiple WM/Picture * Pictures may be included in attributes, one per WM/Picture attribute (but there may be multiple WM/Picture attribute in a single tag).
* attribute in a single tag). These pictures are usually in either JPEG or * These pictures are usually in either JPEG or PNG format.
* PNG format.
* \see Attribute::toPicture() * \see Attribute::toPicture()
* \see Attribute::Attribute(const Picture& picture) * \see Attribute::Attribute(const Picture& picture)
*/ */
class TAGLIB_EXPORT Picture { class TAGLIB_EXPORT Picture {
public: public:
/*! /*!
* This describes the function or content of the picture. * This describes the function or content of the picture.
*/ */
@@ -101,7 +98,7 @@ namespace TagLib
/*! /*!
* Constructs an empty picture. * Constructs an empty picture.
*/ */
Picture(); explicit Picture();
/*! /*!
* Construct an picture as a copy of \a other. * Construct an picture as a copy of \a other.
@@ -129,8 +126,7 @@ namespace TagLib
bool isValid() const; bool isValid() const;
/*! /*!
* Returns the mime type of the image. This should in most cases be * Returns the mime type of the image. This should in most cases be "image/png" or "image/jpeg".
* "image/png" or "image/jpeg".
* \see setMimeType(const String &) * \see setMimeType(const String &)
* \see picture() * \see picture()
* \see setPicture(const ByteArray&) * \see setPicture(const ByteArray&)
@@ -138,8 +134,7 @@ namespace TagLib
String mimeType() const; String mimeType() const;
/*! /*!
* Sets the mime type of the image. This should in most cases be * Sets the mime type of the image. This should in most cases be "image/png" or "image/jpeg".
* "image/png" or "image/jpeg".
* \see setMimeType(const String &) * \see setMimeType(const String &)
* \see picture() * \see picture()
* \see setPicture(const ByteArray&) * \see setPicture(const ByteArray&)
@@ -179,8 +174,7 @@ namespace TagLib
/*! /*!
* Returns the image data as a ByteVector. * Returns the image data as a ByteVector.
* *
* \note ByteVector has a data() method that returns a const char * which * \note ByteVector has a data() method that returns a const char * which should make it easy to export this data to external programs.
* should make it easy to export this data to external programs.
* *
* \see setPicture() * \see setPicture()
* \see mimeType() * \see mimeType()
@@ -188,8 +182,8 @@ namespace TagLib
ByteVector picture() const; ByteVector picture() const;
/*! /*!
* Sets the image data to \a p. \a p should be of the type specified in * Sets the image data to \a p.
* this frame's mime-type specification. * \a p should be of the type specified in this frame's mime-type specification.
* *
* \see picture() * \see picture()
* \see mimeType() * \see mimeType()
@@ -207,18 +201,18 @@ namespace TagLib
*/ */
int dataSize() const; int dataSize() const;
#ifndef DO_NOT_DOCUMENT private:
/* THIS IS PRIVATE, DON'T TOUCH IT! */ friend class Attribute;
void parse(const ByteVector&); void parse(const ByteVector&);
static Picture fromInvalid(); static Picture fromInvalid();
#endif
private: private:
class PicturePrivate; class PicturePrivate;
PicturePrivate* d; PicturePrivate* d;
}; };
} } // namespace ASF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif // ASFPICTURE_H #endif // ASFPICTURE_H

View File

@@ -23,22 +23,20 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include "asfproperties.h" #include "asfproperties.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class ASF::Properties::PropertiesPrivate class ASF::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : length(0),
length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
channels(0), channels(0),
bitsPerSample(0), bitsPerSample(0),
codec(ASF::Properties::Unknown), codec(ASF::AudioProperties::Unknown),
encrypted(false) {} encrypted(false) {}
int length; int length;
@@ -46,7 +44,7 @@ public:
int sampleRate; int sampleRate;
int channels; int channels;
int bitsPerSample; int bitsPerSample;
ASF::Properties::Codec codec; ASF::AudioProperties::Codec codec;
String codecName; String codecName;
String codecDescription; String codecDescription;
bool encrypted; bool encrypted;
@@ -56,69 +54,50 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ASF::Properties::Properties() : ASF::AudioProperties::AudioProperties() : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
AudioProperties(AudioProperties::Average),
d(new PropertiesPrivate())
{
} }
ASF::Properties::~Properties() ASF::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int ASF::Properties::length() const int ASF::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int ASF::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int ASF::Properties::lengthInMilliseconds() const int ASF::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int ASF::Properties::bitrate() const int ASF::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int ASF::Properties::sampleRate() const int ASF::AudioProperties::sampleRate() const {
{
return d->sampleRate; return d->sampleRate;
} }
int ASF::Properties::channels() const int ASF::AudioProperties::channels() const {
{
return d->channels; return d->channels;
} }
int ASF::Properties::bitsPerSample() const int ASF::AudioProperties::bitsPerSample() const {
{
return d->bitsPerSample; return d->bitsPerSample;
} }
ASF::Properties::Codec ASF::Properties::codec() const ASF::AudioProperties::Codec ASF::AudioProperties::codec() const {
{
return d->codec; return d->codec;
} }
String ASF::Properties::codecName() const String ASF::AudioProperties::codecName() const {
{
return d->codecName; return d->codecName;
} }
String ASF::Properties::codecDescription() const String ASF::AudioProperties::codecDescription() const {
{
return d->codecDescription; return d->codecDescription;
} }
bool ASF::Properties::isEncrypted() const bool ASF::AudioProperties::isEncrypted() const {
{
return d->encrypted; return d->encrypted;
} }
@@ -126,40 +105,29 @@ bool ASF::Properties::isEncrypted() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ASF::Properties::setLength(int /*length*/) void ASF::AudioProperties::setLengthInMilliseconds(int value) {
{
debug("ASF::Properties::setLength() -- This method is deprecated. Do not use.");
}
void ASF::Properties::setLengthInMilliseconds(int value)
{
d->length = value; d->length = value;
} }
void ASF::Properties::setBitrate(int value) void ASF::AudioProperties::setBitrate(int value) {
{
d->bitrate = value; d->bitrate = value;
} }
void ASF::Properties::setSampleRate(int value) void ASF::AudioProperties::setSampleRate(int value) {
{
d->sampleRate = value; d->sampleRate = value;
} }
void ASF::Properties::setChannels(int value) void ASF::AudioProperties::setChannels(int value) {
{
d->channels = value; d->channels = value;
} }
void ASF::Properties::setBitsPerSample(int value) void ASF::AudioProperties::setBitsPerSample(int value) {
{
d->bitsPerSample = value; d->bitsPerSample = value;
} }
void ASF::Properties::setCodec(int value) void ASF::AudioProperties::setCodec(int value) {
{
switch(value) switch (value) {
{
case 0x0160: case 0x0160:
d->codec = WMA1; d->codec = WMA1;
break; break;
@@ -176,19 +144,17 @@ void ASF::Properties::setCodec(int value)
d->codec = Unknown; d->codec = Unknown;
break; break;
} }
} }
void ASF::Properties::setCodecName(const String &value) void ASF::AudioProperties::setCodecName(const String &value) {
{
d->codecName = value; d->codecName = value;
} }
void ASF::Properties::setCodecDescription(const String &value) void ASF::AudioProperties::setCodecDescription(const String &value) {
{
d->codecDescription = value; d->codecDescription = value;
} }
void ASF::Properties::setEncrypted(bool value) void ASF::AudioProperties::setEncrypted(bool value) {
{
d->encrypted = value; d->encrypted = value;
} }

View File

@@ -32,19 +32,17 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace ASF { namespace ASF {
//! An implementation of ASF audio properties //! An implementation of ASF audio properties
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{ friend class File;
public:
public:
/*! /*!
* Audio codec types can be used in ASF file. * Audio codec types can be used in ASF file.
*/ */
enum Codec enum Codec {
{
/*! /*!
* Couldn't detect the codec. * Couldn't detect the codec.
*/ */
@@ -74,22 +72,12 @@ namespace TagLib {
/*! /*!
* Creates an instance of ASF::Properties. * Creates an instance of ASF::Properties.
*/ */
Properties(); explicit AudioProperties();
/*! /*!
* Destroys this ASF::Properties instance. * Destroys this ASF::AudioProperties instance.
*/ */
virtual ~Properties(); ~AudioProperties() override;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
virtual int length() const;
/*! /*!
* Returns the length of the file in seconds. The length is rounded down to * Returns the length of the file in seconds. The length is rounded down to
@@ -97,31 +85,29 @@ namespace TagLib {
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual int lengthInSeconds() const override;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual int lengthInMilliseconds() const override;
int lengthInMilliseconds() const;
/*! /*!
* Returns the average bit rate of the file in kb/s. * Returns the average bit rate of the file in kb/s.
*/ */
virtual int bitrate() const; int bitrate() const override;
/*! /*!
* Returns the sample rate in Hz. * Returns the sample rate in Hz.
*/ */
virtual int sampleRate() const; int sampleRate() const override;
/*! /*!
* Returns the number of audio channels. * Returns the number of audio channels.
*/ */
virtual int channels() const; int channels() const override;
/*! /*!
* Returns the number of bits per audio sample. * Returns the number of bits per audio sample.
@@ -137,8 +123,7 @@ namespace TagLib {
Codec codec() const; Codec codec() const;
/*! /*!
* Returns the concrete codec name, for example "Windows Media Audio 9.1" * Returns the concrete codec name, for example "Windows Media Audio 9.1" used in the file if available, otherwise an empty string.
* used in the file if available, otherwise an empty string.
* *
* \see codec() * \see codec()
* \see codecDescription() * \see codecDescription()
@@ -147,8 +132,7 @@ namespace TagLib {
/*! /*!
* Returns the codec description, typically contains the encoder settings, * Returns the codec description, typically contains the encoder settings,
* for example "VBR Quality 50, 44kHz, stereo 1-pass VBR" if available, * for example "VBR Quality 50, 44kHz, stereo 1-pass VBR" if available, otherwise an empty string.
* otherwise an empty string.
* *
* \see codec() * \see codec()
* \see codecName() * \see codecName()
@@ -160,10 +144,7 @@ namespace TagLib {
*/ */
bool isEncrypted() const; bool isEncrypted() const;
#ifndef DO_NOT_DOCUMENT private:
// deprecated
void setLength(int value);
void setLengthInMilliseconds(int value); void setLengthInMilliseconds(int value);
void setBitrate(int value); void setBitrate(int value);
void setSampleRate(int value); void setSampleRate(int value);
@@ -173,16 +154,15 @@ namespace TagLib {
void setCodecName(const String &value); void setCodecName(const String &value);
void setCodecDescription(const String &value); void setCodecDescription(const String &value);
void setEncrypted(bool value); void setEncrypted(bool value);
#endif
private: private:
class PropertiesPrivate; class AudioPropertiesPrivate;
PropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
} } // namespace ASF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,13 +23,13 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tpropertymap.h> #include "tpicturemap.h"
#include "tpropertymap.h"
#include "asftag.h" #include "asftag.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class ASF::Tag::TagPrivate class ASF::Tag::TagPrivate {
{
public: public:
String title; String title;
String artist; String artist;
@@ -39,58 +39,50 @@ public:
AttributeListMap attributeListMap; AttributeListMap attributeListMap;
}; };
ASF::Tag::Tag() : ASF::Tag::Tag() : d(new TagPrivate()) {}
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate())
{
}
ASF::Tag::~Tag() ASF::Tag::~Tag() {
{
delete d; delete d;
} }
String ASF::Tag::title() const String ASF::Tag::title() const {
{
return d->title; return d->title;
} }
String ASF::Tag::artist() const String ASF::Tag::artist() const {
{
return d->artist; return d->artist;
} }
String ASF::Tag::album() const String ASF::Tag::album() const {
{
if (d->attributeListMap.contains("WM/AlbumTitle")) if (d->attributeListMap.contains("WM/AlbumTitle"))
return d->attributeListMap["WM/AlbumTitle"][0].toString(); return d->attributeListMap["WM/AlbumTitle"][0].toString();
return String(); return String();
} }
String ASF::Tag::copyright() const String ASF::Tag::copyright() const {
{
return d->copyright; return d->copyright;
} }
String ASF::Tag::comment() const String ASF::Tag::comment() const {
{
return d->comment; return d->comment;
} }
String ASF::Tag::rating() const String ASF::Tag::rating() const {
{
return d->rating; return d->rating;
} }
unsigned int ASF::Tag::year() const unsigned int ASF::Tag::year() const {
{
if (d->attributeListMap.contains("WM/Year")) if (d->attributeListMap.contains("WM/Year"))
return d->attributeListMap["WM/Year"][0].toString().toInt(); return d->attributeListMap["WM/Year"][0].toString().toInt();
return 0; return 0;
} }
unsigned int ASF::Tag::track() const unsigned int ASF::Tag::track() const {
{
if (d->attributeListMap.contains("WM/TrackNumber")) { if (d->attributeListMap.contains("WM/TrackNumber")) {
const ASF::Attribute attr = d->attributeListMap["WM/TrackNumber"][0]; const ASF::Attribute attr = d->attributeListMap["WM/TrackNumber"][0];
if (attr.type() == ASF::Attribute::DWordType) if (attr.type() == ASF::Attribute::DWordType)
@@ -101,117 +93,265 @@ unsigned int ASF::Tag::track() const
if (d->attributeListMap.contains("WM/Track")) if (d->attributeListMap.contains("WM/Track"))
return d->attributeListMap["WM/Track"][0].toUInt(); return d->attributeListMap["WM/Track"][0].toUInt();
return 0; return 0;
} }
String ASF::Tag::genre() const String ASF::Tag::genre() const {
{
if (d->attributeListMap.contains("WM/Genre")) if (d->attributeListMap.contains("WM/Genre"))
return d->attributeListMap["WM/Genre"][0].toString(); return d->attributeListMap["WM/Genre"][0].toString();
return String(); return String();
} }
void ASF::Tag::setTitle(const String &value) PictureMap ASF::Tag::pictures() const {
{
PictureMap map;
if (d->attributeListMap.contains("WM/Picture")) {
AttributeList list = d->attributeListMap["WM/Picture"];
for (AttributeList::ConstIterator it = list.begin(); it != list.end(); ++it) {
ASF::Picture asfPicture = (*it).toPicture();
TagLib::Picture::Type type;
switch (asfPicture.type()) {
case ASF::Picture::FileIcon:
type = TagLib::Picture::FileIcon;
break;
case ASF::Picture::OtherFileIcon:
type = TagLib::Picture::OtherFileIcon;
break;
case ASF::Picture::FrontCover:
type = TagLib::Picture::FrontCover;
break;
case ASF::Picture::BackCover:
type = TagLib::Picture::BackCover;
break;
case ASF::Picture::LeafletPage:
type = TagLib::Picture::LeafletPage;
break;
case ASF::Picture::Media:
type = TagLib::Picture::Media;
break;
case ASF::Picture::LeadArtist:
type = TagLib::Picture::LeadArtist;
break;
case ASF::Picture::Artist:
type = TagLib::Picture::Artist;
break;
case ASF::Picture::Conductor:
type = TagLib::Picture::Conductor;
break;
case ASF::Picture::Band:
type = TagLib::Picture::Band;
break;
case ASF::Picture::Composer:
type = TagLib::Picture::Composer;
break;
case ASF::Picture::Lyricist:
type = TagLib::Picture::Lyricist;
break;
case ASF::Picture::RecordingLocation:
type = TagLib::Picture::RecordingLocation;
break;
case ASF::Picture::DuringRecording:
type = TagLib::Picture::DuringRecording;
break;
case ASF::Picture::DuringPerformance:
type = TagLib::Picture::DuringPerformance;
break;
case ASF::Picture::MovieScreenCapture:
type = TagLib::Picture::MovieScreenCapture;
break;
case ASF::Picture::ColouredFish:
type = TagLib::Picture::ColouredFish;
break;
case ASF::Picture::Illustration:
type = TagLib::Picture::Illustration;
break;
case ASF::Picture::BandLogo:
type = TagLib::Picture::BandLogo;
break;
case ASF::Picture::PublisherLogo:
type = TagLib::Picture::PublisherLogo;
break;
default:
type = TagLib::Picture::Other;
break;
}
TagLib::Picture picture(asfPicture.picture(), type, asfPicture.mimeType(), asfPicture.description());
map.insert(picture);
}
}
return PictureMap(map);
}
void ASF::Tag::setTitle(const String &value) {
d->title = value; d->title = value;
} }
void ASF::Tag::setArtist(const String &value) void ASF::Tag::setArtist(const String &value) {
{
d->artist = value; d->artist = value;
} }
void ASF::Tag::setCopyright(const String &value) void ASF::Tag::setCopyright(const String &value) {
{
d->copyright = value; d->copyright = value;
} }
void ASF::Tag::setComment(const String &value) void ASF::Tag::setComment(const String &value) {
{
d->comment = value; d->comment = value;
} }
void ASF::Tag::setRating(const String &value) void ASF::Tag::setRating(const String &value) {
{
d->rating = value; d->rating = value;
} }
void ASF::Tag::setAlbum(const String &value) void ASF::Tag::setAlbum(const String &value) {
{
setAttribute("WM/AlbumTitle", value); setAttribute("WM/AlbumTitle", value);
} }
void ASF::Tag::setGenre(const String &value) void ASF::Tag::setGenre(const String &value) {
{
setAttribute("WM/Genre", value); setAttribute("WM/Genre", value);
} }
void ASF::Tag::setYear(unsigned int value) void ASF::Tag::setYear(unsigned int value) {
{
setAttribute("WM/Year", String::number(value)); setAttribute("WM/Year", String::number(value));
} }
void ASF::Tag::setTrack(unsigned int value) void ASF::Tag::setTrack(unsigned int value) {
{
setAttribute("WM/TrackNumber", String::number(value)); setAttribute("WM/TrackNumber", String::number(value));
} }
ASF::AttributeListMap& ASF::Tag::attributeListMap() void ASF::Tag::setPictures(const PictureMap &l) {
{
removeItem("WM/Picture");
for (PictureMap::ConstIterator pictureMapIt = l.begin(); pictureMapIt != l.end(); ++pictureMapIt) {
PictureList list = pictureMapIt->second;
for (PictureList::ConstIterator pictureListIt = list.begin(); pictureListIt != list.end(); ++pictureListIt) {
const TagLib::Picture picture = (*pictureListIt);
ASF::Picture asfPicture;
asfPicture.setPicture(picture.data());
asfPicture.setMimeType(picture.mime());
asfPicture.setDescription(picture.description());
switch (picture.type()) {
case TagLib::Picture::Other:
asfPicture.setType(ASF::Picture::Other);
break;
case TagLib::Picture::FileIcon:
asfPicture.setType(ASF::Picture::FileIcon);
break;
case TagLib::Picture::OtherFileIcon:
asfPicture.setType(ASF::Picture::OtherFileIcon);
break;
case TagLib::Picture::FrontCover:
asfPicture.setType(ASF::Picture::FrontCover);
break;
case TagLib::Picture::BackCover:
asfPicture.setType(ASF::Picture::BackCover);
break;
case TagLib::Picture::LeafletPage:
asfPicture.setType(ASF::Picture::LeafletPage);
break;
case TagLib::Picture::Media:
asfPicture.setType(ASF::Picture::Media);
break;
case TagLib::Picture::LeadArtist:
asfPicture.setType(ASF::Picture::LeadArtist);
break;
case TagLib::Picture::Artist:
asfPicture.setType(ASF::Picture::Artist);
break;
case TagLib::Picture::Conductor:
asfPicture.setType(ASF::Picture::Conductor);
break;
case TagLib::Picture::Band:
asfPicture.setType(ASF::Picture::Band);
break;
case TagLib::Picture::Composer:
asfPicture.setType(ASF::Picture::Composer);
break;
case TagLib::Picture::Lyricist:
asfPicture.setType(ASF::Picture::Lyricist);
break;
case TagLib::Picture::RecordingLocation:
asfPicture.setType(ASF::Picture::RecordingLocation);
break;
case TagLib::Picture::DuringRecording:
asfPicture.setType(ASF::Picture::DuringRecording);
break;
case TagLib::Picture::DuringPerformance:
asfPicture.setType(ASF::Picture::DuringPerformance);
break;
case TagLib::Picture::MovieScreenCapture:
asfPicture.setType(ASF::Picture::MovieScreenCapture);
break;
case TagLib::Picture::ColouredFish:
asfPicture.setType(ASF::Picture::ColouredFish);
break;
case TagLib::Picture::Illustration:
asfPicture.setType(ASF::Picture::Illustration);
break;
case TagLib::Picture::BandLogo:
asfPicture.setType(ASF::Picture::BandLogo);
break;
case TagLib::Picture::PublisherLogo:
asfPicture.setType(ASF::Picture::PublisherLogo);
break;
}
addAttribute("WM/Picture", Attribute(asfPicture));
}
}
}
const ASF::AttributeListMap &ASF::Tag::attributeListMap() const {
return d->attributeListMap; return d->attributeListMap;
} }
const ASF::AttributeListMap &ASF::Tag::attributeListMap() const bool ASF::Tag::contains(const String &key) const {
{
return d->attributeListMap;
}
bool ASF::Tag::contains(const String &key) const
{
return d->attributeListMap.contains(key); return d->attributeListMap.contains(key);
} }
void ASF::Tag::removeItem(const String &key) void ASF::Tag::removeItem(const String &key) {
{
d->attributeListMap.erase(key); d->attributeListMap.erase(key);
} }
ASF::AttributeList ASF::Tag::attribute(const String &name) const ASF::AttributeList ASF::Tag::attribute(const String &name) const {
{
return d->attributeListMap[name]; return d->attributeListMap[name];
} }
void ASF::Tag::setAttribute(const String &name, const Attribute &attribute) void ASF::Tag::setAttribute(const String &name, const Attribute &attribute) {
{
AttributeList value; AttributeList value;
value.append(attribute); value.append(attribute);
d->attributeListMap.insert(name, value); d->attributeListMap.insert(name, value);
} }
void ASF::Tag::setAttribute(const String &name, const AttributeList &values) void ASF::Tag::setAttribute(const String &name, const AttributeList &values) {
{
d->attributeListMap.insert(name, values); d->attributeListMap.insert(name, values);
} }
void ASF::Tag::addAttribute(const String &name, const Attribute &attribute) void ASF::Tag::addAttribute(const String &name, const Attribute &attribute) {
{
if (d->attributeListMap.contains(name)) { if (d->attributeListMap.contains(name)) {
d->attributeListMap[name].append(attribute); d->attributeListMap[name].append(attribute);
} }
else { else {
setAttribute(name, attribute); setAttribute(name, attribute);
} }
} }
bool ASF::Tag::isEmpty() const bool ASF::Tag::isEmpty() const {
{
return Strawberry_TagLib::TagLib::Tag::isEmpty() && return Strawberry_TagLib::TagLib::Tag::isEmpty() &&
copyright().isEmpty() && copyright().isEmpty() &&
rating().isEmpty() && rating().isEmpty() &&
d->attributeListMap.isEmpty(); d->attributeListMap.isEmpty();
} }
namespace namespace {
{
const char *keyTranslation[][2] = { const char *keyTranslation[][2] = {
{ "WM/AlbumTitle", "ALBUM" }, { "WM/AlbumTitle", "ALBUM" },
{ "WM/AlbumArtist", "ALBUMARTIST" }, { "WM/AlbumArtist", "ALBUMARTIST" },
@@ -255,19 +395,20 @@ namespace
}; };
const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]); const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
String translateKey(const String &key) String translateKey(const String &key) {
{
for (size_t i = 0; i < keyTranslationSize; ++i) { for (size_t i = 0; i < keyTranslationSize; ++i) {
if (key == keyTranslation[i][0]) if (key == keyTranslation[i][0])
return keyTranslation[i][1]; return keyTranslation[i][1];
} }
return String(); return String();
}
}
PropertyMap ASF::Tag::properties() const }
{ } // namespace
PropertyMap ASF::Tag::properties() const {
PropertyMap props; PropertyMap props;
if (!d->title.isEmpty()) { if (!d->title.isEmpty()) {
@@ -305,17 +446,19 @@ PropertyMap ASF::Tag::properties() const
} }
} }
return props; return props;
} }
void ASF::Tag::removeUnsupportedProperties(const StringList &props) void ASF::Tag::removeUnsupportedProperties(const StringList &props) {
{
StringList::ConstIterator it = props.begin(); StringList::ConstIterator it = props.begin();
for (; it != props.end(); ++it) for (; it != props.end(); ++it)
d->attributeListMap.erase(*it); d->attributeListMap.erase(*it);
} }
PropertyMap ASF::Tag::setProperties(const PropertyMap &props) PropertyMap ASF::Tag::setProperties(const PropertyMap &props) {
{
static Map<String, String> reverseKeyMap; static Map<String, String> reverseKeyMap;
if (reverseKeyMap.isEmpty()) { if (reverseKeyMap.isEmpty()) {
int numKeys = sizeof(keyTranslation) / sizeof(keyTranslation[0]); int numKeys = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
@@ -375,4 +518,5 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
} }
return ignoredProps; return ignoredProps;
} }

View File

@@ -45,37 +45,34 @@ namespace TagLib {
friend class File; friend class File;
public: public:
explicit Tag();
Tag(); ~Tag() override;
virtual ~Tag();
/*! /*!
* Returns the track name. * Returns the track name.
*/ */
virtual String title() const; String title() const override;
/*! /*!
* Returns the artist name. * Returns the artist name.
*/ */
virtual String artist() const; String artist() const override;
/*! /*!
* Returns the album name; if no album name is present in the tag * Returns the album name; if no album name is present in the tag String::null will be returned.
* String::null will be returned.
*/ */
virtual String album() const; String album() const override;
/*! /*!
* Returns the track comment. * Returns the track comment.
*/ */
virtual String comment() const; String comment() const override;
/*! /*!
* Returns the genre name; if no genre is present in the tag String::null * Returns the genre name; if no genre is present in the tag String::null will be returned.
* will be returned.
*/ */
virtual String genre() const; String genre() const override;
/*! /*!
* Returns the rating. * Returns the rating.
@@ -83,106 +80,97 @@ namespace TagLib {
virtual String rating() const; virtual String rating() const;
/*! /*!
* Returns the genre name; if no genre is present in the tag String::null * Returns the genre name; if no genre is present in the tag String::null will be returned.
* will be returned.
*/ */
virtual String copyright() const; virtual String copyright() const;
/*! /*!
* Returns the year; if there is no year set, this will return 0. * Returns the year; if there is no year set, this will return 0.
*/ */
virtual unsigned int year() const; unsigned int year() const override;
/*! /*!
* Returns the track number; if there is no track number set, this will * Returns the track number; if there is no track number set, this will return 0.
* return 0.
*/ */
virtual unsigned int track() const; unsigned int track() const override;
PictureMap pictures() const override;
/*! /*!
* Sets the title to \a s. * Sets the title to \a s.
*/ */
virtual void setTitle(const String &s); void setTitle(const String &value) override;
/*! /*!
* Sets the artist to \a s. * Sets the artist to \a s.
*/ */
virtual void setArtist(const String &s); void setArtist(const String &value) override;
/*! /*!
* Sets the album to \a s. If \a s is String::null then this value will be * Sets the album to \a s. If \a s is String::null then this value will be cleared.
* cleared.
*/ */
virtual void setAlbum(const String &s); void setAlbum(const String &value) override;
/*! /*!
* Sets the comment to \a s. * Sets the comment to \a s.
*/ */
virtual void setComment(const String &s); void setComment(const String &value) override;
/*! /*!
* Sets the rating to \a s. * Sets the rating to \a s.
*/ */
virtual void setRating(const String &s); virtual void setRating(const String &value);
/*! /*!
* Sets the copyright to \a s. * Sets the copyright to \a s.
*/ */
virtual void setCopyright(const String &s); virtual void setCopyright(const String &value);
/*! /*!
* Sets the genre to \a s. * Sets the genre to \a s.
*/ */
virtual void setGenre(const String &s); void setGenre(const String &value) override;
/*! /*!
* Sets the year to \a i. If \a s is 0 then this value will be cleared. * Sets the year to \a i. If \a s is 0 then this value will be cleared.
*/ */
virtual void setYear(unsigned int i); void setYear(unsigned int value) override;
/*! /*!
* Sets the track to \a i. If \a s is 0 then this value will be cleared. * Sets the track to \a i. If \a s is 0 then this value will be cleared.
*/ */
virtual void setTrack(unsigned int i); void setTrack(unsigned int value) override;
void setPictures(const PictureMap&) override;
/*! /*!
* Returns true if the tag does not contain any data. This should be * Returns true if the tag does not contain any data.
* reimplemented in subclasses that provide more than the basic tagging * This should be reimplemented in subclasses that provide more than the basic tagging abilities in this class.
* abilities in this class.
*/ */
virtual bool isEmpty() const; bool isEmpty() const override;
/*! /*!
* \deprecated * Returns a reference to the item list map. This is an AttributeListMap of all of the items in the tag.
*/ */
AttributeListMap &attributeListMap();
/*!
* Returns a reference to the item list map. This is an AttributeListMap of
* all of the items in the tag.
*/
// BIC: return by value
const AttributeListMap &attributeListMap() const; const AttributeListMap &attributeListMap() const;
/*! /*!
* \return True if a value for \a attribute is currently set. * \return True if a value for \a attribute is currently set.
*/ */
bool contains(const String &name) const; bool contains(const String &key) const;
/*! /*!
* Removes the \a key attribute from the tag * Removes the \a key attribute from the tag
*/ */
void removeItem(const String &name); void removeItem(const String &key);
/*! /*!
* \return The list of values for the key \a name, or an empty list if no * \return The list of values for the key \a name, or an empty list if no values have been set.
* values have been set.
*/ */
AttributeList attribute(const String &name) const; AttributeList attribute(const String &name) const;
/*! /*!
* Sets the \a key attribute to the value of \a attribute. If an attribute * Sets the \a key attribute to the value of \a attribute. If an attribute with the \a key is already present, it will be replaced.
* with the \a key is already present, it will be replaced.
*/ */
void setAttribute(const String &name, const Attribute &attribute); void setAttribute(const String &name, const Attribute &attribute);
@@ -197,16 +185,17 @@ namespace TagLib {
*/ */
void addAttribute(const String &name, const Attribute &attribute); void addAttribute(const String &name, const Attribute &attribute);
PropertyMap properties() const; PropertyMap properties() const override;
void removeUnsupportedProperties(const StringList& properties); void removeUnsupportedProperties(const StringList &props) override;
PropertyMap setProperties(const PropertyMap &properties); PropertyMap setProperties(const PropertyMap &props) override;
private: private:
class TagPrivate; class TagPrivate;
TagPrivate *d; TagPrivate *d;
}; };
}
} } // namespace ASF
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

View File

@@ -31,50 +31,44 @@
#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header #ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib namespace TagLib {
{ namespace ASF {
namespace ASF namespace {
{
namespace
{
inline unsigned short readWORD(File *file, bool *ok = 0) inline unsigned short readWORD(File *file, bool *ok = nullptr) {
{
const ByteVector v = file->readBlock(2); const ByteVector v = file->readBlock(2);
if (v.size() != 2) { if (v.size() != 2) {
if (ok) *ok = false; if (ok) *ok = false;
return 0; return 0;
} }
if (ok) *ok = true; if (ok) *ok = true;
return v.toUShort(false); return v.toUInt16LE(0);
} }
inline unsigned int readDWORD(File *file, bool *ok = 0) inline unsigned int readDWORD(File *file, bool *ok = nullptr) {
{
const ByteVector v = file->readBlock(4); const ByteVector v = file->readBlock(4);
if (v.size() != 4) { if (v.size() != 4) {
if (ok) *ok = false; if (ok) *ok = false;
return 0; return 0;
} }
if (ok) *ok = true; if (ok) *ok = true;
return v.toUInt(false); return v.toUInt32LE(0);
} }
inline long long readQWORD(File *file, bool *ok = 0) inline long long readQWORD(File *file, bool *ok = nullptr) {
{
const ByteVector v = file->readBlock(8); const ByteVector v = file->readBlock(8);
if (v.size() != 8) { if (v.size() != 8) {
if (ok) *ok = false; if (ok) *ok = false;
return 0; return 0;
} }
if (ok) *ok = true; if (ok) *ok = true;
return v.toLongLong(false); return v.toInt64LE(0);
} }
inline String readString(File *file, int length) inline String readString(File *file, int length) {
{
ByteVector data = file->readBlock(length); ByteVector data = file->readBlock(length);
unsigned int size = data.size(); size_t size = data.size();
while (size >= 2) { while (size >= 2) {
if (data[size - 1] != '\0' || data[size - 2] != '\0') { if (data[size - 1] != '\0' || data[size - 2] != '\0') {
break; break;
@@ -85,21 +79,21 @@ namespace TagLib
data.resize(size); data.resize(size);
} }
return String(data, String::UTF16LE); return String(data, String::UTF16LE);
} }
inline ByteVector renderString(const String &str, bool includeLength = false) inline ByteVector renderString(const String &str, bool includeLength = false) {
{ ByteVector data = str.data(String::UTF16LE) + ByteVector::fromUInt16LE(0);
ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false);
if (includeLength) { if (includeLength) {
data = ByteVector::fromShort(data.size(), false) + data; data = ByteVector::fromUInt16LE(data.size()) + data;
} }
return data; return data;
} }
} } // namespace
} } // namespace ASF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,95 +23,31 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include "tstringlist.h"
#include "aiffproperties.h"
#include "apeproperties.h"
#include "asfproperties.h"
#include "flacproperties.h"
#include "mp4properties.h"
#include "mpcproperties.h"
#include "mpegproperties.h"
#include "opusproperties.h"
#include "speexproperties.h"
#include "trueaudioproperties.h"
#include "vorbisproperties.h"
#include "wavproperties.h"
#include "wavpackproperties.h"
#include "dsfproperties.h"
#include "dsdiffproperties.h"
#include "audioproperties.h" #include "audioproperties.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
// This macro is a workaround for the fact that we can't add virtual functions.
// Should be true virtual functions in taglib2.
#define VIRTUAL_FUNCTION_WORKAROUND(function_name, default_value) \
if(dynamic_cast<const APE::Properties*>(this)) \
return dynamic_cast<const APE::Properties*>(this)->function_name(); \
else if(dynamic_cast<const ASF::Properties*>(this)) \
return dynamic_cast<const ASF::Properties*>(this)->function_name(); \
else if(dynamic_cast<const FLAC::Properties*>(this)) \
return dynamic_cast<const FLAC::Properties*>(this)->function_name(); \
else if(dynamic_cast<const MP4::Properties*>(this)) \
return dynamic_cast<const MP4::Properties*>(this)->function_name(); \
else if(dynamic_cast<const MPC::Properties*>(this)) \
return dynamic_cast<const MPC::Properties*>(this)->function_name(); \
else if(dynamic_cast<const MPEG::Properties*>(this)) \
return dynamic_cast<const MPEG::Properties*>(this)->function_name(); \
else if(dynamic_cast<const Ogg::Opus::Properties*>(this)) \
return dynamic_cast<const Ogg::Opus::Properties*>(this)->function_name(); \
else if(dynamic_cast<const Ogg::Speex::Properties*>(this)) \
return dynamic_cast<const Ogg::Speex::Properties*>(this)->function_name(); \
else if(dynamic_cast<const TrueAudio::Properties*>(this)) \
return dynamic_cast<const TrueAudio::Properties*>(this)->function_name(); \
else if(dynamic_cast<const RIFF::AIFF::Properties*>(this)) \
return dynamic_cast<const RIFF::AIFF::Properties*>(this)->function_name(); \
else if(dynamic_cast<const RIFF::WAV::Properties*>(this)) \
return dynamic_cast<const RIFF::WAV::Properties*>(this)->function_name(); \
else if(dynamic_cast<const Vorbis::Properties*>(this)) \
return dynamic_cast<const Vorbis::Properties*>(this)->function_name(); \
else if(dynamic_cast<const WavPack::Properties*>(this)) \
return dynamic_cast<const WavPack::Properties*>(this)->function_name(); \
else if(dynamic_cast<const DSF::Properties*>(this)) \
return dynamic_cast<const DSF::Properties*>(this)->function_name(); \
else if(dynamic_cast<const DSDIFF::Properties*>(this)) \
return dynamic_cast<const DSDIFF::Properties*>(this)->function_name(); \
else \
return (default_value);
class AudioProperties::AudioPropertiesPrivate
{
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AudioProperties::~AudioProperties() AudioProperties::~AudioProperties() {}
{
}
int AudioProperties::lengthInSeconds() const String AudioProperties::toString() const {
{
VIRTUAL_FUNCTION_WORKAROUND(lengthInSeconds, 0) StringList desc;
} desc.append("Audio");
desc.append(String::number(lengthInSeconds()) + " seconds");
desc.append(String::number(bitrate()) + " kbps");
return desc.toString(", ");
int AudioProperties::lengthInMilliseconds() const
{
VIRTUAL_FUNCTION_WORKAROUND(lengthInMilliseconds, 0)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// protected methods // protected methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AudioProperties::AudioProperties(ReadStyle) : AudioProperties::AudioProperties() : d(nullptr) {}
d(0)
{
}

View File

@@ -27,6 +27,7 @@
#define TAGLIB_AUDIOPROPERTIES_H #define TAGLIB_AUDIOPROPERTIES_H
#include "taglib_export.h" #include "taglib_export.h"
#include "tstring.h"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
@@ -34,22 +35,19 @@ namespace TagLib {
//! A simple, abstract interface to common audio properties //! A simple, abstract interface to common audio properties
/*! /*!
* The values here are common to most audio formats. For more specific, codec * The values here are common to most audio formats.
* dependent values, please see see the subclasses APIs. This is meant to * For more specific, codec dependent values, please see see the subclasses APIs.
* compliment the TagLib::File and TagLib::Tag APIs in providing a simple * This is meant to compliment the TagLib::File and TagLib::Tag APIs in providing a simple
* interface that is sufficient for most applications. * interface that is sufficient for most applications.
*/ */
class TAGLIB_EXPORT AudioProperties class TAGLIB_EXPORT AudioProperties {
{
public: public:
/*! /*!
* Reading audio properties from a file can sometimes be very time consuming * Reading audio properties from a file can sometimes be very time consuming
* and for the most accurate results can often involve reading the entire * and for the most accurate results can often involve reading the entire file.
* file. Because in many situations speed is critical or the accuracy of the * Because in many situations speed is critical or the accuracy of the values
* values is not particularly important this allows the level of desired * is not particularly important this allows the level of desired accuracy to be set.
* accuracy to be set.
*/ */
enum ReadStyle { enum ReadStyle {
//! Read as little of the file as possible //! Read as little of the file as possible
@@ -66,31 +64,22 @@ namespace TagLib {
virtual ~AudioProperties(); virtual ~AudioProperties();
/*! /*!
* Returns the length of the file in seconds. * Returns the length of the file in seconds. The length is rounded down to the nearest whole second.
*/
virtual int length() const = 0;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual virtual int lengthInSeconds() const = 0;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual virtual int lengthInMilliseconds() const = 0;
int lengthInMilliseconds() const;
/*! /*!
* Returns the most appropriate bit rate for the file in kb/s. For constant * Returns the most appropriate bit rate for the file in kb/s. For constant bitrate formats this is simply the bitrate of the file.
* bitrate formats this is simply the bitrate of the file. For variable * For variable bitrate formats this is either the average or nominal bitrate.
* bitrate formats this is either the average or nominal bitrate.
*/ */
virtual int bitrate() const = 0; virtual int bitrate() const = 0;
@@ -104,16 +93,18 @@ namespace TagLib {
*/ */
virtual int channels() const = 0; virtual int channels() const = 0;
protected:
/*! /*!
* Construct an audio properties instance. This is protected as this class * Returns description of the audio file.
* should not be instantiated directly, but should be instantiated via its
* subclasses and can be fetched from the FileRef or File APIs.
*
* \see ReadStyle
*/ */
AudioProperties(ReadStyle style); virtual String toString() const;
protected:
/*!
* Construct an audio properties instance.
* This is protected as this class should not be instantiated directly,
* but should be instantiated via its subclasses and can be fetched from the FileRef or File APIs.
*/
explicit AudioProperties();
private: private:
AudioProperties(const AudioProperties&); AudioProperties(const AudioProperties&);
@@ -123,7 +114,7 @@ namespace TagLib {
AudioPropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -26,112 +26,95 @@
#include "dsdiffdiintag.h" #include "dsdiffdiintag.h"
#include "tstringlist.h" #include "tstringlist.h"
#include "tpropertymap.h" #include "tpropertymap.h"
#include "tpicturemap.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace DSDIFF::DIIN; using namespace DSDIFF::DIIN;
class DSDIFF::DIIN::Tag::TagPrivate class DSDIFF::DIIN::Tag::TagPrivate {
{
public: public:
TagPrivate() TagPrivate() {
{
} }
String title; String title;
String artist; String artist;
}; };
DSDIFF::DIIN::Tag::Tag() : Strawberry_TagLib::TagLib::Tag() DSDIFF::DIIN::Tag::Tag() {
{
d = new TagPrivate; d = new TagPrivate;
} }
DSDIFF::DIIN::Tag::~Tag() DSDIFF::DIIN::Tag::~Tag() {
{
delete d; delete d;
} }
String DSDIFF::DIIN::Tag::title() const String DSDIFF::DIIN::Tag::title() const {
{
return d->title; return d->title;
} }
String DSDIFF::DIIN::Tag::artist() const String DSDIFF::DIIN::Tag::artist() const {
{
return d->artist; return d->artist;
} }
String DSDIFF::DIIN::Tag::album() const String DSDIFF::DIIN::Tag::album() const {
{
return String(); return String();
} }
String DSDIFF::DIIN::Tag::comment() const String DSDIFF::DIIN::Tag::comment() const {
{
return String(); return String();
} }
String DSDIFF::DIIN::Tag::genre() const String DSDIFF::DIIN::Tag::genre() const {
{
return String(); return String();
} }
unsigned int DSDIFF::DIIN::Tag::year() const unsigned int DSDIFF::DIIN::Tag::year() const {
{
return 0; return 0;
} }
unsigned int DSDIFF::DIIN::Tag::track() const unsigned int DSDIFF::DIIN::Tag::track() const {
{
return 0; return 0;
} }
void DSDIFF::DIIN::Tag::setTitle(const String &title) PictureMap DSDIFF::DIIN::Tag::pictures() const {
{ return PictureMap();
if(title.isNull() || title.isEmpty()) }
d->title = String();
else void DSDIFF::DIIN::Tag::setTitle(const String &title) {
d->title = title; d->title = title;
} }
void DSDIFF::DIIN::Tag::setArtist(const String &artist) void DSDIFF::DIIN::Tag::setArtist(const String &artist) {
{
if(artist.isNull() || artist.isEmpty())
d->artist = String();
else
d->artist = artist; d->artist = artist;
} }
void DSDIFF::DIIN::Tag::setAlbum(const String &) void DSDIFF::DIIN::Tag::setAlbum(const String &) {}
{
}
void DSDIFF::DIIN::Tag::setComment(const String &) void DSDIFF::DIIN::Tag::setComment(const String &) {}
{
}
void DSDIFF::DIIN::Tag::setGenre(const String &) void DSDIFF::DIIN::Tag::setGenre(const String &) {}
{
}
void DSDIFF::DIIN::Tag::setYear(unsigned int) void DSDIFF::DIIN::Tag::setYear(unsigned int) {}
{
}
void DSDIFF::DIIN::Tag::setTrack(unsigned int) void DSDIFF::DIIN::Tag::setTrack(unsigned int) {}
{
} void DSDIFF::DIIN::Tag::setPictures(const PictureMap&) {}
PropertyMap DSDIFF::DIIN::Tag::properties() const {
PropertyMap DSDIFF::DIIN::Tag::properties() const
{
PropertyMap properties; PropertyMap properties;
properties["TITLE"] = d->title; properties["TITLE"] = d->title;
properties["ARTIST"] = d->artist; properties["ARTIST"] = d->artist;
return properties; return properties;
} }
PropertyMap DSDIFF::DIIN::Tag::setProperties(const PropertyMap &origProps) PropertyMap DSDIFF::DIIN::Tag::setProperties(const PropertyMap &origProps) {
{
PropertyMap properties(origProps); PropertyMap properties(origProps);
properties.removeEmpty(); properties.removeEmpty();
StringList oneValueSet; StringList oneValueSet;
@@ -139,13 +122,15 @@ PropertyMap DSDIFF::DIIN::Tag::setProperties(const PropertyMap &origProps)
if (properties.contains("TITLE")) { if (properties.contains("TITLE")) {
d->title = properties["TITLE"].front(); d->title = properties["TITLE"].front();
oneValueSet.append("TITLE"); oneValueSet.append("TITLE");
} else }
else
d->title = String(); d->title = String();
if (properties.contains("ARTIST")) { if (properties.contains("ARTIST")) {
d->artist = properties["ARTIST"].front(); d->artist = properties["ARTIST"].front();
oneValueSet.append("ARTIST"); oneValueSet.append("ARTIST");
} else }
else
d->artist = String(); d->artist = String();
// for each tag that has been set above, remove the first entry in the corresponding // for each tag that has been set above, remove the first entry in the corresponding
@@ -158,5 +143,5 @@ PropertyMap DSDIFF::DIIN::Tag::setProperties(const PropertyMap &origProps)
} }
return properties; return properties;
}
}

View File

@@ -30,9 +30,7 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace DSDIFF { namespace DSDIFF {
namespace DIIN { namespace DIIN {
/*! /*!
@@ -40,101 +38,106 @@ namespace TagLib {
* *
* Only Title and Artist tags are supported * Only Title and Artist tags are supported
*/ */
class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag
{ class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
public: public:
Tag(); explicit Tag();
virtual ~Tag(); ~Tag() override;
/*! /*!
* Returns the track name; if no track name is present in the tag * Returns the track name; if no track name is present in the tag String() will be returned.
* String() will be returned.
*/ */
String title() const; String title() const override;
/*! /*!
* Returns the artist name; if no artist name is present in the tag * Returns the artist name; if no artist name is present in the tag String() will be returned.
* String() will be returned.
*/ */
String artist() const; String artist() const override;
/*! /*!
* Not supported. Therefore always returns String(). * Not supported. Therefore always returns String().
*/ */
String album() const; String album() const override;
/*! /*!
* Not supported. Therefore always returns String(). * Not supported. Therefore always returns String().
*/ */
String comment() const; String comment() const override;
/*! /*!
* Not supported. Therefore always returns String(). * Not supported. Therefore always returns String().
*/ */
String genre() const; String genre() const override;
/*! /*!
* Not supported. Therefore always returns 0. * Not supported. Therefore always returns 0.
*/ */
unsigned int year() const; unsigned int year() const override;
/*! /*!
* Not supported. Therefore always returns 0. * Not supported. Therefore always returns 0.
*/ */
unsigned int track() const; unsigned int track() const override;
/*! /*!
* Sets the title to \a title. If \a title is String() then this * Not supported. Therefore always returns an empty list.
* value will be cleared.
*/ */
void setTitle(const String &title); PictureMap pictures() const override;
/*! /*!
* Sets the artist to \a artist. If \a artist is String() then this * Sets the title to \a title. If \a title is String() then this value will be cleared.
* value will be cleared.
*/ */
void setArtist(const String &artist); void setTitle(const String &title) override;
/*!
* Sets the artist to \a artist. If \a artist is String() then this value will be cleared.
*/
void setArtist(const String &artist) override;
/*! /*!
* Not supported and therefore ignored. * Not supported and therefore ignored.
*/ */
void setAlbum(const String &album); void setAlbum(const String &album) override;
/*! /*!
* Not supported and therefore ignored. * Not supported and therefore ignored.
*/ */
void setComment(const String &comment); void setComment(const String &comment) override;
/*! /*!
* Not supported and therefore ignored. * Not supported and therefore ignored.
*/ */
void setGenre(const String &genre); void setGenre(const String &genre) override;
/*! /*!
* Not supported and therefore ignored. * Not supported and therefore ignored.
*/ */
void setYear(unsigned int year); void setYear(unsigned int year) override;
/*! /*!
* Not supported and therefore ignored. * Not supported and therefore ignored.
*/ */
void setTrack(unsigned int track); void setTrack(unsigned int track) override;
/*!
* Not supported and therefore ignored.
*/
void setPictures(const PictureMap&) override;
/*! /*!
* Implements the unified property interface -- export function. * Implements the unified property interface -- export function.
* Since the DIIN tag is very limited, the exported map is as well. * Since the DIIN tag is very limited, the exported map is as well.
*/ */
PropertyMap properties() const; PropertyMap properties() const override;
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* Because of the limitations of the DIIN file tag, any tags besides * Because of the limitations of the DIIN file tag, any tags besides
* TITLE and ARTIST, will be * TITLE and ARTIST, will be returned.
* returned. Additionally, if the map contains tags with multiple values, * Additionally, if the map contains tags with multiple values,
* all but the first will be contained in the returned map of unsupported * all but the first will be contained in the returned map of unsupported properties.
* properties.
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
private: private:
Tag(const Tag &); Tag(const Tag &);
@@ -143,10 +146,9 @@ namespace TagLib {
class TagPrivate; class TagPrivate;
TagPrivate *d; TagPrivate *d;
}; };
} } // namespace DIIN
} } // namespace DSDIFF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,24 +23,24 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include <memory>
#include <tdebug.h> #include <array>
#include <id3v2tag.h>
#include <tstringlist.h> #include "tstring.h"
#include <tpropertymap.h> #include "tbytevector.h"
#include <tagutils.h> #include "tdebug.h"
#include "id3v2tag.h"
#include "tstringlist.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "tagunion.h" #include "tagunion.h"
#include "dsdifffile.h" #include "dsdifffile.h"
#include <array>
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{ struct Chunk64 {
struct Chunk64
{
ByteVector name; ByteVector name;
unsigned long long offset; unsigned long long offset;
unsigned long long size; unsigned long long size;
@@ -49,27 +49,29 @@ namespace
typedef std::vector<Chunk64> ChunkList; typedef std::vector<Chunk64> ChunkList;
int chunkIndex(const ChunkList &chunks, const ByteVector &id) int chunkIndex(const ChunkList &chunks, const ByteVector &id) {
{
for(int i = 0; i < chunks.size(); i++) { for (unsigned long int i = 0; i < chunks.size(); i++) {
if (chunks[i].name == id) if (chunks[i].name == id)
return i; return i;
} }
return -1; return -1;
} }
bool isValidChunkID(const ByteVector &name) bool isValidChunkID(const ByteVector &name) {
{
if (name.size() != 4) if (name.size() != 4)
return false; return false;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if(name[i] < 32 || name[i] > 127) if (name[i] < 32)
return false; return false;
} }
return true; return true;
} }
enum { enum {
@@ -80,30 +82,21 @@ namespace
PROPChunk = 0, PROPChunk = 0,
DIINChunk = 1 DIINChunk = 1
}; };
} } // namespace
class DSDIFF::File::FilePrivate class DSDIFF::File::FilePrivate {
{
public: public:
FilePrivate() : FilePrivate() : endianness(BigEndian),
endianness(BigEndian),
size(0), size(0),
isID3InPropChunk(false), isID3InPropChunk(false),
duplicateID3V2chunkIndex(-1), duplicateID3V2chunkIndex(-1),
properties(0),
id3v2TagChunkID("ID3 "), id3v2TagChunkID("ID3 "),
hasID3v2(false), hasID3v2(false),
hasDiin(false) hasDiin(false) {
{
childChunkIndex[ID3v2Index] = -1; childChunkIndex[ID3v2Index] = -1;
childChunkIndex[DIINIndex] = -1; childChunkIndex[DIINIndex] = -1;
} }
~FilePrivate()
{
delete properties;
}
Endianness endianness; Endianness endianness;
ByteVector type; ByteVector type;
unsigned long long size; unsigned long long size;
@@ -121,9 +114,9 @@ public:
*/ */
int duplicateID3V2chunkIndex; int duplicateID3V2chunkIndex;
Properties *properties; std::unique_ptr<AudioProperties> properties;
TagUnion tag; DoubleTagUnion tag;
ByteVector id3v2TagChunkID; ByteVector id3v2TagChunkID;
@@ -135,100 +128,94 @@ public:
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool DSDIFF::File::isSupported(IOStream *stream) bool DSDIFF::File::isSupported(IOStream *stream) {
{
// A DSDIFF file has to start with "FRM8????????DSD ". // A DSDIFF file has to start with "FRM8????????DSD ".
const ByteVector id = Utils::readHeader(stream, 16, false); const ByteVector id = Utils::readHeader(stream, 16, false);
return (id.startsWith("FRM8") && id.containsAt("DSD ", 12)); return (id.startsWith("FRM8") && id.containsAt("DSD ", 12));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
DSDIFF::File::File(FileName file, bool readProperties, DSDIFF::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(file) {
Properties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(file)
{
d = new FilePrivate; d = new FilePrivate;
d->endianness = BigEndian; d->endianness = BigEndian;
if (isOpen()) if (isOpen())
read(readProperties, propertiesStyle); read(readProperties, propertiesStyle);
} }
DSDIFF::File::File(IOStream *stream, bool readProperties, DSDIFF::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(stream) {
Properties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(stream)
{
d = new FilePrivate; d = new FilePrivate;
d->endianness = BigEndian; d->endianness = BigEndian;
if (isOpen()) if (isOpen())
read(readProperties, propertiesStyle); read(readProperties, propertiesStyle);
} }
DSDIFF::File::~File() DSDIFF::File::~File() {
{
delete d; delete d;
} }
Strawberry_TagLib::TagLib::Tag *DSDIFF::File::tag() const Strawberry_TagLib::TagLib::Tag *DSDIFF::File::tag() const {
{
return &d->tag; return &d->tag;
} }
ID3v2::Tag *DSDIFF::File::ID3v2Tag(bool create) const ID3v2::Tag *DSDIFF::File::ID3v2Tag(bool create) const {
{
return d->tag.access<ID3v2::Tag>(ID3v2Index, create); return d->tag.access<ID3v2::Tag>(ID3v2Index, create);
} }
bool DSDIFF::File::hasID3v2Tag() const bool DSDIFF::File::hasID3v2Tag() const {
{
return d->hasID3v2; return d->hasID3v2;
} }
DSDIFF::DIIN::Tag *DSDIFF::File::DIINTag(bool create) const DSDIFF::DIIN::Tag *DSDIFF::File::DIINTag(bool create) const {
{
return d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, create); return d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, create);
} }
bool DSDIFF::File::hasDIINTag() const bool DSDIFF::File::hasDIINTag() const {
{
return d->hasDiin; return d->hasDiin;
} }
PropertyMap DSDIFF::File::properties() const PropertyMap DSDIFF::File::properties() const {
{
if (d->hasID3v2) if (d->hasID3v2)
return d->tag.access<ID3v2::Tag>(ID3v2Index, false)->properties(); return d->tag.access<ID3v2::Tag>(ID3v2Index, false)->properties();
return PropertyMap(); return PropertyMap();
} }
void DSDIFF::File::removeUnsupportedProperties(const StringList &unsupported) void DSDIFF::File::removeUnsupportedProperties(const StringList &properties) {
{
if (d->hasID3v2) if (d->hasID3v2)
d->tag.access<ID3v2::Tag>(ID3v2Index, false)->removeUnsupportedProperties(unsupported); d->tag.access<ID3v2::Tag>(ID3v2Index, false)->removeUnsupportedProperties(properties);
if (d->hasDiin) if (d->hasDiin)
d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->removeUnsupportedProperties(unsupported); d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->removeUnsupportedProperties(properties);
} }
PropertyMap DSDIFF::File::setProperties(const PropertyMap &properties) PropertyMap DSDIFF::File::setProperties(const PropertyMap &properties) {
{
return d->tag.access<ID3v2::Tag>(ID3v2Index, true)->setProperties(properties); return d->tag.access<ID3v2::Tag>(ID3v2Index, true)->setProperties(properties);
} }
DSDIFF::Properties *DSDIFF::File::audioProperties() const DSDIFF::AudioProperties *DSDIFF::File::audioProperties() const {
{ return d->properties.get();
return d->properties;
} }
bool DSDIFF::File::save() bool DSDIFF::File::save() {
{
return save(AllTags); return save(AllTags);
} }
bool DSDIFF::File::save(TagTypes tags, StripTags strip, ID3v2::Version version) bool DSDIFF::File::save(TagTypes tags, StripTags, ID3v2::Version version) {
{
if (readOnly()) { if (readOnly()) {
debug("DSDIFF::File::save() -- File is read only."); debug("DSDIFF::File::save() -- File is read only.");
return false; return false;
@@ -278,7 +265,10 @@ bool DSDIFF::File::save(TagTypes tags, StripTags strip, ID3v2::Version version)
if (tags & DIIN && diinTag) { if (tags & DIIN && diinTag) {
if (!diinTag->title().isEmpty()) { if (!diinTag->title().isEmpty()) {
ByteVector diinTitle; ByteVector diinTitle;
diinTitle.append(ByteVector::fromUInt(diinTag->title().size(), d->endianness == BigEndian)); if (d->endianness == BigEndian)
diinTitle.append(ByteVector::fromUInt32BE(diinTag->title().size()));
else
diinTitle.append(ByteVector::fromUInt32LE(diinTag->title().size()));
diinTitle.append(ByteVector::fromCString(diinTag->title().toCString())); diinTitle.append(ByteVector::fromCString(diinTag->title().toCString()));
setChildChunkData("DITI", diinTitle, DIINChunk); setChildChunkData("DITI", diinTitle, DIINChunk);
} }
@@ -287,7 +277,10 @@ bool DSDIFF::File::save(TagTypes tags, StripTags strip, ID3v2::Version version)
if (!diinTag->artist().isEmpty()) { if (!diinTag->artist().isEmpty()) {
ByteVector diinArtist; ByteVector diinArtist;
diinArtist.append(ByteVector::fromUInt(diinTag->artist().size(), d->endianness == BigEndian)); if (d->endianness == BigEndian)
diinArtist.append(ByteVector::fromUInt32BE(diinTag->artist().size()));
else
diinArtist.append(ByteVector::fromUInt32LE(diinTag->artist().size()));
diinArtist.append(ByteVector::fromCString(diinTag->artist().toCString())); diinArtist.append(ByteVector::fromCString(diinTag->artist().toCString()));
setChildChunkData("DIAR", diinArtist, DIINChunk); setChildChunkData("DIAR", diinArtist, DIINChunk);
} }
@@ -302,10 +295,11 @@ bool DSDIFF::File::save(TagTypes tags, StripTags strip, ID3v2::Version version)
} }
return true; return true;
} }
void DSDIFF::File::strip(TagTypes tags) void DSDIFF::File::strip(TagTypes tags) {
{
if (tags & ID3v2) { if (tags & ID3v2) {
removeRootChunk("ID3 "); removeRootChunk("ID3 ");
removeRootChunk("id3 "); removeRootChunk("id3 ");
@@ -320,40 +314,45 @@ void DSDIFF::File::strip(TagTypes tags)
d->hasDiin = false; d->hasDiin = false;
d->tag.set(DIINIndex, new DIIN::Tag); d->tag.set(DIINIndex, new DIIN::Tag);
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void DSDIFF::File::removeRootChunk(unsigned int i) void DSDIFF::File::removeRootChunk(unsigned int i) {
{
unsigned long long chunkSize = d->chunks[i].size + d->chunks[i].padding + 12; unsigned long long chunkSize = d->chunks[i].size + d->chunks[i].padding + 12;
d->size -= chunkSize; d->size -= chunkSize;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
removeBlock(d->chunks[i].offset - 12, chunkSize); removeBlock(d->chunks[i].offset - 12, chunkSize);
// Update the internal offsets // Update the internal offsets
for (unsigned long r = i + 1; r < d->chunks.size(); r++) for (unsigned long r = i + 1; r < d->chunks.size(); r++)
d->chunks[r].offset = d->chunks[r - 1].offset + 12 d->chunks[r].offset = d->chunks[r - 1].offset + 12 + d->chunks[r - 1].size + d->chunks[r - 1].padding;
+ d->chunks[r - 1].size + d->chunks[r - 1].padding;
d->chunks.erase(d->chunks.begin() + i); d->chunks.erase(d->chunks.begin() + i);
} }
void DSDIFF::File::removeRootChunk(const ByteVector &id) void DSDIFF::File::removeRootChunk(const ByteVector &id) {
{
int i = chunkIndex(d->chunks, id); int i = chunkIndex(d->chunks, id);
if (i >= 0) if (i >= 0)
removeRootChunk(i); removeRootChunk(i);
} }
void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data) void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data) {
{
if (data.isEmpty()) { if (data.isEmpty()) {
removeRootChunk(i); removeRootChunk(i);
return; return;
@@ -363,14 +362,14 @@ void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data)
// First we update the global size // First we update the global size
d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding); d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding);
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
// Now update the specific chunk // Now update the specific chunk
writeChunk(d->chunks[i].name, writeChunk(d->chunks[i].name, data, d->chunks[i].offset - 12, d->chunks[i].size + d->chunks[i].padding + 12);
data,
d->chunks[i].offset - 12,
d->chunks[i].size + d->chunks[i].padding + 12);
d->chunks[i].size = data.size(); d->chunks[i].size = data.size();
d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0; d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0;
@@ -378,10 +377,11 @@ void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data)
// Finally update the internal offsets // Finally update the internal offsets
updateRootChunksStructure(i + 1); updateRootChunksStructure(i + 1);
} }
void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &data) void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &data) {
{
if (d->chunks.size() == 0) { if (d->chunks.size() == 0) {
debug("DSDIFF::File::setPropChunkData - No valid chunks found."); debug("DSDIFF::File::setPropChunkData - No valid chunks found.");
return; return;
@@ -400,7 +400,10 @@ void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &da
// First we update the global size // First we update the global size
d->size += (offset & 1) + ((data.size() + 1) & ~1) + 12; d->size += (offset & 1) + ((data.size() + 1) & ~1) + 12;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
// Now add the chunk to the file // Now add the chunk to the file
writeChunk(name, writeChunk(name,
@@ -416,24 +419,29 @@ void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &da
chunk.padding = (data.size() & 0x01) ? 1 : 0; chunk.padding = (data.size() & 0x01) ? 1 : 0;
d->chunks.push_back(chunk); d->chunks.push_back(chunk);
} }
void DSDIFF::File::removeChildChunk(unsigned int i, unsigned int childChunkNum) void DSDIFF::File::removeChildChunk(unsigned int i, unsigned int childChunkNum) {
{
ChunkList &childChunks = d->childChunks[childChunkNum]; ChunkList &childChunks = d->childChunks[childChunkNum];
// Update global size // Update global size
unsigned long long removedChunkTotalSize = childChunks[i].size + childChunks[i].padding + 12; unsigned long long removedChunkTotalSize = childChunks[i].size + childChunks[i].padding + 12;
d->size -= removedChunkTotalSize; d->size -= removedChunkTotalSize;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
// Update child chunk size // Update child chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size -= removedChunkTotalSize; d->chunks[d->childChunkIndex[childChunkNum]].size -= removedChunkTotalSize;
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size, if (d->endianness == BigEndian)
d->endianness == BigEndian), insert(ByteVector::fromUInt64BE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8); else
insert(ByteVector::fromUInt64LE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Remove the chunk // Remove the chunk
removeBlock(childChunks[i].offset - 12, removedChunkTotalSize); removeBlock(childChunks[i].offset - 12, removedChunkTotalSize);
@@ -445,23 +453,20 @@ void DSDIFF::File::removeChildChunk(unsigned int i, unsigned int childChunkNum)
childChunks[i + 1].offset = childChunks[i].offset; childChunks[i + 1].offset = childChunks[i].offset;
i++; i++;
for (i++; i < childChunks.size(); i++) for (i++; i < childChunks.size(); i++)
childChunks[i].offset = childChunks[i - 1].offset + 12 childChunks[i].offset = childChunks[i - 1].offset + 12 + childChunks[i - 1].size + childChunks[i - 1].padding;
+ childChunks[i - 1].size + childChunks[i - 1].padding;
} }
// And for root chunks // And for root chunks
for (i = d->childChunkIndex[childChunkNum] + 1; i < d->chunks.size(); i++) for (i = d->childChunkIndex[childChunkNum] + 1; i < d->chunks.size(); i++)
d->chunks[i].offset = d->chunks[i - 1].offset + 12 d->chunks[i].offset = d->chunks[i - 1].offset + 12 + d->chunks[i - 1].size + d->chunks[i - 1].padding;
+ d->chunks[i - 1].size + d->chunks[i - 1].padding;
childChunks.erase(childChunks.begin() + i); childChunks.erase(childChunks.begin() + i);
} }
void DSDIFF::File::setChildChunkData(unsigned int i, void DSDIFF::File::setChildChunkData(unsigned int i, const ByteVector &data, unsigned int childChunkNum) {
const ByteVector &data,
unsigned int childChunkNum)
{
ChunkList &childChunks = d->childChunks[childChunkNum]; ChunkList &childChunks = d->childChunks[childChunkNum];
if (data.isEmpty()) { if (data.isEmpty()) {
@@ -474,22 +479,23 @@ void DSDIFF::File::setChildChunkData(unsigned int i,
d->size += ((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding); d->size += ((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
// And the PROP chunk size // And the PROP chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size += d->chunks[d->childChunkIndex[childChunkNum]].size += ((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size, if (d->endianness == BigEndian)
d->endianness == BigEndian), insert(ByteVector::fromUInt64BE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8); else
insert(ByteVector::fromUInt64LE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Now update the specific chunk // Now update the specific chunk
writeChunk(childChunks[i].name, writeChunk(childChunks[i].name, data, childChunks[i].offset - 12, childChunks[i].size + childChunks[i].padding + 12);
data,
childChunks[i].offset - 12,
childChunks[i].size + childChunks[i].padding + 12);
childChunks[i].size = data.size(); childChunks[i].size = data.size();
childChunks[i].padding = (data.size() & 0x01) ? 1 : 0; childChunks[i].padding = (data.size() & 0x01) ? 1 : 0;
@@ -497,17 +503,15 @@ void DSDIFF::File::setChildChunkData(unsigned int i,
// Now update the internal offsets // Now update the internal offsets
// For child Chunks // For child Chunks
for (i++; i < childChunks.size(); i++) for (i++; i < childChunks.size(); i++)
childChunks[i].offset = childChunks[i - 1].offset + 12 childChunks[i].offset = childChunks[i - 1].offset + 12 + childChunks[i - 1].size + childChunks[i - 1].padding;
+ childChunks[i - 1].size + childChunks[i - 1].padding;
// And for root chunks // And for root chunks
updateRootChunksStructure(d->childChunkIndex[childChunkNum] + 1); updateRootChunksStructure(d->childChunkIndex[childChunkNum] + 1);
} }
void DSDIFF::File::setChildChunkData(const ByteVector &name, void DSDIFF::File::setChildChunkData(const ByteVector &name, const ByteVector &data, unsigned int childChunkNum) {
const ByteVector &data,
unsigned int childChunkNum)
{
ChunkList &childChunks = d->childChunks[childChunkNum]; ChunkList &childChunks = d->childChunks[childChunkNum];
if (childChunks.size() == 0) { if (childChunks.size() == 0) {
@@ -535,15 +539,18 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
// First we update the global size // First we update the global size
d->size += (offset & 1) + ((data.size() + 1) & ~1) + 12; d->size += (offset & 1) + ((data.size() + 1) & ~1) + 12;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8); if (d->endianness == BigEndian)
insert(ByteVector::fromUInt64BE(d->size), 4, 8);
else
insert(ByteVector::fromUInt64LE(d->size), 4, 8);
// And the child chunk size // And the child chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size += (offset & 1) d->chunks[d->childChunkIndex[childChunkNum]].size += (offset & 1) + ((data.size() + 1) & ~1) + 12;
+ ((data.size() + 1) & ~1) + 12; if (d->endianness == BigEndian)
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size, insert(ByteVector::fromUInt64BE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
d->endianness == BigEndian), else
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8); insert(ByteVector::fromUInt64LE(d->chunks[d->childChunkIndex[childChunkNum]].size), d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Now add the chunk to the file // Now add the chunk to the file
@@ -566,13 +573,13 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
chunk.padding = (data.size() & 0x01) ? 1 : 0; chunk.padding = (data.size() & 0x01) ? 1 : 0;
childChunks.push_back(chunk); childChunks.push_back(chunk);
} }
void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk) void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk) {
{
for (unsigned int i = startingChunk; i < d->chunks.size(); i++) for (unsigned int i = startingChunk; i < d->chunks.size(); i++)
d->chunks[i].offset = d->chunks[i - 1].offset + 12 d->chunks[i].offset = d->chunks[i - 1].offset + 12 + d->chunks[i - 1].size + d->chunks[i - 1].padding;
+ d->chunks[i - 1].size + d->chunks[i - 1].padding;
// Update childchunks structure as well // Update childchunks structure as well
@@ -581,35 +588,33 @@ void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk)
if (childChunksToUpdate.size() > 0) { if (childChunksToUpdate.size() > 0) {
childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[PROPChunk]].offset + 12; childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[PROPChunk]].offset + 12;
for (unsigned int i = 1; i < childChunksToUpdate.size(); i++) for (unsigned int i = 1; i < childChunksToUpdate.size(); i++)
childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 + childChunksToUpdate[i - 1].size + childChunksToUpdate[i - 1].padding;
+ childChunksToUpdate[i - 1].size + childChunksToUpdate[i - 1].padding;
} }
} }
if (d->childChunkIndex[DIINChunk] >= static_cast<int>(startingChunk)) { if (d->childChunkIndex[DIINChunk] >= static_cast<int>(startingChunk)) {
ChunkList &childChunksToUpdate = d->childChunks[DIINChunk]; ChunkList &childChunksToUpdate = d->childChunks[DIINChunk];
if (childChunksToUpdate.size() > 0) { if (childChunksToUpdate.size() > 0) {
childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[DIINChunk]].offset + 12; childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[DIINChunk]].offset + 12;
for (unsigned int i = 1; i < childChunksToUpdate.size(); i++) for (unsigned int i = 1; i < childChunksToUpdate.size(); i++)
childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 + childChunksToUpdate[i - 1].size + childChunksToUpdate[i - 1].padding;
+ childChunksToUpdate[i - 1].size + childChunksToUpdate[i - 1].padding;
}
} }
} }
void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle) }
{
void DSDIFF::File::read(bool readProperties, AudioProperties::ReadStyle propertiesStyle) {
bool bigEndian = (d->endianness == BigEndian); bool bigEndian = (d->endianness == BigEndian);
d->type = readBlock(4); d->type = readBlock(4);
d->size = readBlock(8).toLongLong(bigEndian); d->size = bigEndian ? readBlock(8).toInt64BE(0) : readBlock(8).toInt64LE(0);
d->format = readBlock(4); d->format = readBlock(4);
// + 12: chunk header at least, fix for additional junk bytes // + 12: chunk header at least, fix for additional junk bytes
while (tell() + 12 <= length()) { while (tell() + 12 <= length()) {
ByteVector chunkName = readBlock(4); ByteVector chunkName = readBlock(4);
unsigned long long chunkSize = readBlock(8).toLongLong(bigEndian); unsigned long long chunkSize = bigEndian ? readBlock(8).toInt64BE(0) : readBlock(8).toInt64LE(0);
if (!isValidChunkID(chunkName)) { if (!isValidChunkID(chunkName)) {
debug("DSDIFF::File::read() -- Chunk '" + chunkName + "' has invalid ID"); debug("DSDIFF::File::read() -- Chunk '" + chunkName + "' has invalid ID");
@@ -619,8 +624,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if (static_cast<unsigned long long>(tell()) + chunkSize > if (static_cast<unsigned long long>(tell()) + chunkSize >
static_cast<unsigned long long>(length())) { static_cast<unsigned long long>(length())) {
debug("DSDIFF::File::read() -- Chunk '" + chunkName debug("DSDIFF::File::read() -- Chunk '" + chunkName + "' has invalid size (larger than the file size)");
+ "' has invalid size (larger than the file size)");
setValid(false); setValid(false);
break; break;
} }
@@ -670,7 +674,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
while (tell() + 12 <= dstChunkEnd) { while (tell() + 12 <= dstChunkEnd) {
ByteVector dstChunkName = readBlock(4); ByteVector dstChunkName = readBlock(4);
long long dstChunkSize = readBlock(8).toLongLong(bigEndian); long long dstChunkSize = bigEndian ? readBlock(8).toInt64BE(0) : readBlock(8).toInt64LE(0);
if (!isValidChunkID(dstChunkName)) { if (!isValidChunkID(dstChunkName)) {
debug("DSDIFF::File::read() -- DST Chunk '" + dstChunkName + "' has invalid ID"); debug("DSDIFF::File::read() -- DST Chunk '" + dstChunkName + "' has invalid ID");
@@ -679,16 +683,15 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
} }
if (static_cast<long long>(tell()) + dstChunkSize > dstChunkEnd) { if (static_cast<long long>(tell()) + dstChunkSize > dstChunkEnd) {
debug("DSDIFF::File::read() -- DST Chunk '" + dstChunkName debug("DSDIFF::File::read() -- DST Chunk '" + dstChunkName + "' has invalid size (larger than the DST chunk)");
+ "' has invalid size (larger than the DST chunk)");
setValid(false); setValid(false);
break; break;
} }
if (dstChunkName == "FRTE") { if (dstChunkName == "FRTE") {
// Found the DST frame information chunk // Found the DST frame information chunk
dstNumFrames = readBlock(4).toUInt(bigEndian); dstNumFrames = bigEndian ? readBlock(4).toUInt32BE(0) : readBlock(4).toUInt32LE(0);
dstFrameRate = readBlock(2).toUShort(bigEndian); dstFrameRate = bigEndian ? readBlock(2).toUInt16BE(0) : readBlock(2).toUInt16LE(0);
// Found the wanted one, no need to look at the others // Found the wanted one, no need to look at the others
break; break;
} }
@@ -713,7 +716,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
seek(d->chunks[i].offset + 4); seek(d->chunks[i].offset + 4);
while (tell() + 12 <= propChunkEnd) { while (tell() + 12 <= propChunkEnd) {
ByteVector propChunkName = readBlock(4); ByteVector propChunkName = readBlock(4);
long long propChunkSize = readBlock(8).toLongLong(bigEndian); long long propChunkSize = bigEndian ? readBlock(8).toInt64BE(0) : readBlock(8).toInt64LE(0);
if (!isValidChunkID(propChunkName)) { if (!isValidChunkID(propChunkName)) {
debug("DSDIFF::File::read() -- PROP Chunk '" + propChunkName + "' has invalid ID"); debug("DSDIFF::File::read() -- PROP Chunk '" + propChunkName + "' has invalid ID");
@@ -722,8 +725,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
} }
if (static_cast<long long>(tell()) + propChunkSize > propChunkEnd) { if (static_cast<long long>(tell()) + propChunkSize > propChunkEnd) {
debug("DSDIFF::File::read() -- PROP Chunk '" + propChunkName debug("DSDIFF::File::read() -- PROP Chunk '" + propChunkName + "' has invalid size (larger than the PROP chunk)");
+ "' has invalid size (larger than the PROP chunk)");
setValid(false); setValid(false);
break; break;
} }
@@ -760,7 +762,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
while (tell() + 12 <= diinChunkEnd) { while (tell() + 12 <= diinChunkEnd) {
ByteVector diinChunkName = readBlock(4); ByteVector diinChunkName = readBlock(4);
long long diinChunkSize = readBlock(8).toLongLong(bigEndian); long long diinChunkSize = bigEndian ? readBlock(8).toInt64BE(0) : readBlock(8).toInt64LE(0);
if (!isValidChunkID(diinChunkName)) { if (!isValidChunkID(diinChunkName)) {
debug("DSDIFF::File::read() -- DIIN Chunk '" + diinChunkName + "' has invalid ID"); debug("DSDIFF::File::read() -- DIIN Chunk '" + diinChunkName + "' has invalid ID");
@@ -769,8 +771,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
} }
if (static_cast<long long>(tell()) + diinChunkSize > diinChunkEnd) { if (static_cast<long long>(tell()) + diinChunkSize > diinChunkEnd) {
debug("DSDIFF::File::read() -- DIIN Chunk '" + diinChunkName debug("DSDIFF::File::read() -- DIIN Chunk '" + diinChunkName + "' has invalid size (larger than the DIIN chunk)");
+ "' has invalid size (larger than the DIIN chunk)");
setValid(false); setValid(false);
break; break;
} }
@@ -821,8 +822,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
unsigned short channels = 0; unsigned short channels = 0;
for (unsigned int i = 0; i < d->childChunks[PROPChunk].size(); i++) { for (unsigned int i = 0; i < d->childChunks[PROPChunk].size(); i++) {
if(d->childChunks[PROPChunk][i].name == "ID3 " || if (d->childChunks[PROPChunk][i].name == "ID3 " || d->childChunks[PROPChunk][i].name == "id3 ") {
d->childChunks[PROPChunk][i].name == "id3 ") {
if (d->hasID3v2) { if (d->hasID3v2) {
d->duplicateID3V2chunkIndex = i; d->duplicateID3V2chunkIndex = i;
// ID3V2 tag has already been found at root level // ID3V2 tag has already been found at root level
@@ -836,12 +836,12 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
else if (d->childChunks[PROPChunk][i].name == "FS ") { else if (d->childChunks[PROPChunk][i].name == "FS ") {
// Sample rate // Sample rate
seek(d->childChunks[PROPChunk][i].offset); seek(d->childChunks[PROPChunk][i].offset);
sampleRate = readBlock(4).toUInt(0, 4, bigEndian); sampleRate = bigEndian ? readBlock(4).toUInt32BE(0) : readBlock(4).toUInt32LE(0);
} }
else if (d->childChunks[PROPChunk][i].name == "CHNL") { else if (d->childChunks[PROPChunk][i].name == "CHNL") {
// Channels // Channels
seek(d->childChunks[PROPChunk][i].offset); seek(d->childChunks[PROPChunk][i].offset);
channels = readBlock(2).toShort(0, bigEndian); channels = bigEndian ? readBlock(2).toInt16BE(0) : readBlock(2).toInt16LE(0);
} }
} }
@@ -853,7 +853,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
for (unsigned int i = 0; i < d->childChunks[DIINChunk].size(); i++) { for (unsigned int i = 0; i < d->childChunks[DIINChunk].size(); i++) {
if (d->childChunks[DIINChunk][i].name == "DITI") { if (d->childChunks[DIINChunk][i].name == "DITI") {
seek(d->childChunks[DIINChunk][i].offset); seek(d->childChunks[DIINChunk][i].offset);
unsigned int titleStrLength = readBlock(4).toUInt(0, 4, bigEndian); unsigned int titleStrLength = bigEndian ? readBlock(4).toUInt32BE(0) : readBlock(4).toUInt32LE(0);
if (titleStrLength <= d->childChunks[DIINChunk][i].size) { if (titleStrLength <= d->childChunks[DIINChunk][i].size) {
ByteVector titleStr = readBlock(titleStrLength); ByteVector titleStr = readBlock(titleStrLength);
d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->setTitle(titleStr); d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->setTitle(titleStr);
@@ -861,7 +861,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
} }
else if (d->childChunks[DIINChunk][i].name == "DIAR") { else if (d->childChunks[DIINChunk][i].name == "DIAR") {
seek(d->childChunks[DIINChunk][i].offset); seek(d->childChunks[DIINChunk][i].offset);
unsigned int artistStrLength = readBlock(4).toUInt(0, 4, bigEndian); unsigned int artistStrLength = bigEndian ? readBlock(4).toUInt32BE(0) : readBlock(4).toUInt32LE(0);
if (artistStrLength <= d->childChunks[DIINChunk][i].size) { if (artistStrLength <= d->childChunks[DIINChunk][i].size) {
ByteVector artistStr = readBlock(artistStrLength); ByteVector artistStr = readBlock(artistStrLength);
d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->setArtist(artistStr); d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false)->setArtist(artistStr);
@@ -874,9 +874,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if (lengthDSDSamplesTimeChannels == 0) { if (lengthDSDSamplesTimeChannels == 0) {
// DST compressed signal : need to compute length of DSD uncompressed frames // DST compressed signal : need to compute length of DSD uncompressed frames
if (dstFrameRate > 0) if (dstFrameRate > 0)
lengthDSDSamplesTimeChannels = (unsigned long long) dstNumFrames * lengthDSDSamplesTimeChannels = static_cast<unsigned long long>(dstNumFrames) * static_cast<unsigned long long>(sampleRate) / static_cast<unsigned long long>(dstFrameRate);
(unsigned long long) sampleRate /
(unsigned long long) dstFrameRate;
else else
lengthDSDSamplesTimeChannels = 0; lengthDSDSamplesTimeChannels = 0;
} }
@@ -889,11 +887,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if (lengthDSDSamplesTimeChannels > 0) if (lengthDSDSamplesTimeChannels > 0)
bitrate = (audioDataSizeinBytes * 8 * sampleRate) / lengthDSDSamplesTimeChannels / 1000; bitrate = (audioDataSizeinBytes * 8 * sampleRate) / lengthDSDSamplesTimeChannels / 1000;
d->properties = new Properties(sampleRate, d->properties.reset(new AudioProperties(sampleRate, channels, lengthDSDSamplesTimeChannels, bitrate, propertiesStyle));
channels,
lengthDSDSamplesTimeChannels,
bitrate,
propertiesStyle);
} }
if (!ID3v2Tag()) { if (!ID3v2Tag()) {
@@ -902,22 +896,24 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
d->isID3InPropChunk = false; d->isID3InPropChunk = false;
d->hasID3v2 = false; d->hasID3v2 = false;
} }
} }
void DSDIFF::File::writeChunk(const ByteVector &name, const ByteVector &data, void DSDIFF::File::writeChunk(const ByteVector &name, const ByteVector &data, unsigned long long offset, unsigned long replace, unsigned int leadingPadding) {
unsigned long long offset, unsigned long replace,
unsigned int leadingPadding)
{
ByteVector combined; ByteVector combined;
if (leadingPadding) if (leadingPadding)
combined.append(ByteVector(leadingPadding, '\x00')); combined.append(ByteVector(leadingPadding, '\x00'));
combined.append(name); combined.append(name);
combined.append(ByteVector::fromLongLong(data.size(), d->endianness == BigEndian)); if (d->endianness == BigEndian)
combined.append(ByteVector::fromUInt64BE(data.size()));
else
combined.append(ByteVector::fromUInt64LE(data.size()));
combined.append(data); combined.append(data);
if ((data.size() & 0x01) != 0) if ((data.size() & 0x01) != 0)
combined.append('\x00'); combined.append('\x00');
insert(combined, offset, replace); insert(combined, offset, replace);
}
}

View File

@@ -41,10 +41,9 @@ namespace TagLib {
* *
* This supports an ID3v2 tag as well as reading stream from the ID3 RIFF * This supports an ID3v2 tag as well as reading stream from the ID3 RIFF
* chunk as well as properties from the file. * chunk as well as properties from the file.
* Description of the DSDIFF format is available * Description of the DSDIFF format is available at http://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf
* at http://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf
* DSDIFF standard does not explicitly specify the ID3V2 chunk * DSDIFF standard does not explicitly specify the ID3V2 chunk
* It can be found at the root level, but also sometimes inside the PROP chunk * It can be found at the root level, but also sometimes inside the PROP chunk.
* In addition, title and artist info are stored as part of the standard * In addition, title and artist info are stored as part of the standard
*/ */
@@ -54,15 +53,12 @@ namespace TagLib {
/*! /*!
* This implements and provides an interface for DSDIFF files to the * This implements and provides an interface for DSDIFF files to the
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing * TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing the
* the abstract TagLib::File API as well as providing some additional * abstract TagLib::File API as well as providing some additional information specific to DSDIFF files.
* information specific to DSDIFF files.
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* This set of flags is used for various operations and is suitable for * This set of flags is used for various operations and is suitable for
* being OR-ed together. * being OR-ed together.
@@ -79,55 +75,48 @@ namespace TagLib {
}; };
/*! /*!
* Constructs an DSDIFF file from \a file. If \a readProperties is true * Constructs an DSDIFF file from \a file.
* the file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an DSDIFF file from \a stream. If \a readProperties is true * Constructs an DSDIFF file from \a stream.
* the file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* responsible for deleting it after the File object.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns a pointer to a tag that is the union of the ID3v2 and DIIN * Returns a pointer to a tag that is the union of the ID3v2 and DIIN tags.
* tags. The ID3v2 tag is given priority in reading the information -- if * The ID3v2 tag is given priority in reading the information -- if requested information exists in both the ID3v2 tag and the ID3v1 tag,
* requested information exists in both the ID3v2 tag and the ID3v1 tag,
* the information from the ID3v2 tag will be returned. * the information from the ID3v2 tag will be returned.
* *
* If you would like more granular control over the content of the tags, * If you would like more granular control over the content of the tags, with the concession of generality, use the tag-type specific calls.
* with the concession of generality, use the tag-type specific calls.
* *
* \note As this tag is not implemented as an ID3v2 tag or a DIIN tag, * \note As this tag is not implemented as an ID3v2 tag or a DIIN tag,
* but a union of the two this pointer may not be cast to the specific * but a union of the two this pointer may not be cast to the specific tag types.
* tag types.
* *
* \see ID3v2Tag() * \see ID3v2Tag()
* \see DIINTag() * \see DIINTag()
*/ */
virtual Tag *tag() const; Tag *tag() const override;
/*! /*!
* Returns the ID3V2 Tag for this file. * Returns the ID3V2 Tag for this file.
* *
* \note This always returns a valid pointer regardless of whether or not * \note This always returns a valid pointer regardless of whether or not the file on disk has an ID3v2 tag.
* the file on disk has an ID3v2 tag. Use hasID3v2Tag() to check if the * Use hasID3v2Tag() to check if the file on disk actually has an ID3v2 tag.
* file on disk actually has an ID3v2 tag.
* *
* \see hasID3v2Tag() * \see hasID3v2Tag()
*/ */
@@ -143,29 +132,27 @@ namespace TagLib {
* Implements the unified property interface -- export function. * Implements the unified property interface -- export function.
* This method forwards to ID3v2::Tag::properties(). * This method forwards to ID3v2::Tag::properties().
*/ */
PropertyMap properties() const; PropertyMap properties() const override;
void removeUnsupportedProperties(const StringList &properties); void removeUnsupportedProperties(const StringList &properties) override;
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* This method forwards to ID3v2::Tag::setProperties(). * This method forwards to ID3v2::Tag::setProperties().
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &properties) override;
/*! /*!
* Returns the AIFF::Properties for this file. If no audio properties * Returns the AIFF::AudioProperties for this file.
* were read then this will return a null pointer. * If no audio properties were read then this will return a null pointer.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Save the file. If at least one tag -- ID3v1 or DIIN -- exists this * Save the file. If at least one tag -- ID3v1 or DIIN -- exists this will duplicate its content into the other tag.
* will duplicate its content into the other tag. This returns true * This returns true if saving was successful.
* if saving was successful.
* *
* If neither exists or if both tags are empty, this will strip the tags * If neither exists or if both tags are empty, this will strip the tags from the file.
* from the file.
* *
* This is the same as calling save(AllTags); * This is the same as calling save(AllTags);
* *
@@ -174,20 +161,18 @@ namespace TagLib {
* *
* \see save(int tags) * \see save(int tags)
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Save the file. If \a strip is specified, it is possible to choose if * Save the file. If \a strip is specified,
* tags not specified in \a tags should be stripped from the file or * it is possible to choose if tags not specified in \a tags should be stripped from the file or retained.
* retained. With \a version, it is possible to specify whether ID3v2.4 * With \a version, it is possible to specify whether ID3v2.4 or ID3v2.3 should be used.
* or ID3v2.3 should be used.
*/ */
bool save(TagTypes tags, StripTags strip = StripOthers, ID3v2::Version version = ID3v2::v4); bool save(TagTypes tags, StripTags strip = StripOthers, ID3v2::Version version = ID3v2::v4);
/*! /*!
* This will strip the tags that match the OR-ed together TagTypes from the * This will strip the tags that match the OR-ed together TagTypes from the file.
* file. By default it strips all tags. It returns true if the tags are * By default it strips all tags. It returns true if the tags are successfully stripped.
* successfully stripped.
* *
* \note This will update the file immediately. * \note This will update the file immediately.
*/ */
@@ -201,24 +186,24 @@ namespace TagLib {
bool hasID3v2Tag() const; bool hasID3v2Tag() const;
/*! /*!
* Returns whether or not the file on disk actually has the DSDIFF * Returns whether or not the file on disk actually has the DSDIFF title and artist tags.
* title and artist tags.
* *
* \see DIINTag() * \see DIINTag()
*/ */
bool hasDIINTag() const; bool hasDIINTag() const;
/*! /*!
* Returns whether or not the given \a stream can be opened as a DSDIFF * Returns whether or not the given \a stream can be opened as a DSDIFF file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check. The result may not necessarily be correct.
* not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
protected: protected:
enum Endianness { BigEndian, LittleEndian }; enum Endianness {
BigEndian,
LittleEndian
};
File(FileName file, Endianness endianness); File(FileName file, Endianness endianness);
File(IOStream *stream, Endianness endianness); File(IOStream *stream, Endianness endianness);
@@ -228,8 +213,8 @@ namespace TagLib {
File &operator=(const File &); File &operator=(const File &);
void removeRootChunk(const ByteVector &id); void removeRootChunk(const ByteVector &id);
void removeRootChunk(unsigned int chunk); void removeRootChunk(unsigned int i);
void removeChildChunk(unsigned int i, unsigned int chunk); void removeChildChunk(unsigned int i, unsigned int childChunkNum);
/*! /*!
* Sets the data for the the specified chunk at root level to \a data. * Sets the data for the the specified chunk at root level to \a data.
@@ -240,9 +225,7 @@ namespace TagLib {
/*! /*!
* Sets the data for the root-level chunk \a name to \a data. * Sets the data for the root-level chunk \a name to \a data.
* If a root-level chunk with the given name already exists * If a root-level chunk with the given name already exists it will be overwritten, otherwise it will be created after the existing chunks.
* it will be overwritten, otherwise it will be
* created after the existing chunks.
* *
* \warning This will update the file immediately. * \warning This will update the file immediately.
*/ */
@@ -255,34 +238,28 @@ namespace TagLib {
* *
* \warning This will update the file immediately. * \warning This will update the file immediately.
*/ */
void setChildChunkData(unsigned int i, const ByteVector &data, void setChildChunkData(unsigned int i, const ByteVector &data, unsigned int childChunkNum);
unsigned int childChunkNum);
/*! /*!
* Sets the data for the child chunk \a name to \a data. If a chunk with * Sets the data for the child chunk \a name to \a data.
* the given name already exists it will be overwritten, otherwise it will * If a chunk with the given name already exists it will be overwritten, otherwise it will be created after the existing chunks inside child chunk.
* be created after the existing chunks inside child chunk.
* *
* If data is null, then remove the chunks with \a name name * If data is null, then remove the chunks with \a name name
* *
* \warning This will update the file immediately. * \warning This will update the file immediately.
*/ */
void setChildChunkData(const ByteVector &name, const ByteVector &data, void setChildChunkData(const ByteVector &name, const ByteVector &data, unsigned int childChunkNum);
unsigned int childChunkNum);
void updateRootChunksStructure(unsigned int startingChunk); void updateRootChunksStructure(unsigned int startingChunk);
void read(bool readProperties, Properties::ReadStyle propertiesStyle); void read(bool readProperties, AudioProperties::ReadStyle propertiesStyle);
void writeChunk(const ByteVector &name, const ByteVector &data, void writeChunk(const ByteVector &name, const ByteVector &data, unsigned long long offset, unsigned long replace = 0, unsigned int leadingPadding = 0);
unsigned long long offset, unsigned long replace = 0,
unsigned int leadingPadding = 0);
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace DSDIFF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,24 +23,21 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tstring.h> #include "tstring.h"
#include <tdebug.h> #include "tdebug.h"
#include "dsdiffproperties.h" #include "dsdiffproperties.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class DSDIFF::Properties::PropertiesPrivate class DSDIFF::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : length(0),
length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
channels(0), channels(0),
sampleWidth(0), sampleWidth(0),
sampleCount(0) sampleCount(0) {
{
} }
int length; int length;
@@ -55,66 +52,45 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
DSDIFF::Properties::Properties(const unsigned int sampleRate, DSDIFF::AudioProperties::AudioProperties(const unsigned int sampleRate, const unsigned short channels, const unsigned long long samplesCount, const int bitrate, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate) {
const unsigned short channels,
const unsigned long long samplesCount,
const int bitrate,
ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate;
d->channels = channels; d->channels = channels;
d->sampleCount = samplesCount; d->sampleCount = samplesCount;
d->sampleWidth = 1; d->sampleWidth = 1;
d->sampleRate = sampleRate; d->sampleRate = sampleRate;
d->bitrate = bitrate; d->bitrate = bitrate;
d->length = d->sampleRate > 0 d->length = d->sampleRate > 0 ? static_cast<int>((d->sampleCount * 1000.0) / d->sampleRate + 0.5) : 0;
? static_cast<int>((d->sampleCount * 1000.0) / d->sampleRate + 0.5)
: 0;
} }
DSDIFF::Properties::~Properties() DSDIFF::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int DSDIFF::Properties::length() const int DSDIFF::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int DSDIFF::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int DSDIFF::Properties::lengthInMilliseconds() const int DSDIFF::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int DSDIFF::Properties::bitrate() const int DSDIFF::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int DSDIFF::Properties::sampleRate() const int DSDIFF::AudioProperties::sampleRate() const {
{
return d->sampleRate; return d->sampleRate;
} }
int DSDIFF::Properties::channels() const int DSDIFF::AudioProperties::channels() const {
{
return d->channels; return d->channels;
} }
int DSDIFF::Properties::bitsPerSample() const int DSDIFF::AudioProperties::bitsPerSample() const {
{
return d->sampleWidth; return d->sampleWidth;
} }
long long DSDIFF::Properties::sampleCount() const long long DSDIFF::AudioProperties::sampleCount() const {
{
return d->sampleCount; return d->sampleCount;
} }

View File

@@ -30,7 +30,6 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace DSDIFF { namespace DSDIFF {
class File; class File;
@@ -38,48 +37,42 @@ namespace TagLib {
//! An implementation of audio property reading for DSDIFF //! An implementation of audio property reading for DSDIFF
/*! /*!
* This reads the data from an DSDIFF stream found in the AudioProperties * This reads the data from an DSDIFF stream found in the AudioProperties API.
* API.
*/ */
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
/*! /*!
* Create an instance of DSDIFF::Properties with the data read from the * Create an instance of DSDIFF::AudioProperties with the data read from the ByteVector \a data.
* ByteVector \a data.
*/ */
Properties(const unsigned int sampleRate, const unsigned short channels, explicit AudioProperties(const unsigned int sampleRate, const unsigned short channels, const unsigned long long samplesCount, const int bitrate, ReadStyle);
const unsigned long long samplesCount, const int bitrate,
ReadStyle style);
/*! /*!
* Destroys this DSDIFF::Properties instance. * Destroys this DSDIFF::AudioProperties instance.
*/ */
virtual ~Properties(); ~AudioProperties() override;
// Reimplementations. // Reimplementations.
virtual int length() const; int lengthInSeconds() const override;
virtual int lengthInSeconds() const; int lengthInMilliseconds() const override;
virtual int lengthInMilliseconds() const; int bitrate() const override;
virtual int bitrate() const; int sampleRate() const override;
virtual int sampleRate() const; int channels() const override;
virtual int channels() const;
int bitsPerSample() const; int bitsPerSample() const;
long long sampleCount() const; long long sampleCount() const;
private: private:
Properties(const Properties &); AudioProperties(const AudioProperties &);
Properties &operator=(const Properties &); AudioProperties &operator=(const AudioProperties &);
class PropertiesPrivate; class AudioPropertiesPrivate;
PropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
}
} } // namespace DSDIFF
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,12 +23,14 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include <memory>
#include <tdebug.h>
#include <id3v2tag.h> #include "tbytevector.h"
#include <tstringlist.h> #include "tdebug.h"
#include <tpropertymap.h> #include "id3v2tag.h"
#include <tagutils.h> #include "tstringlist.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "dsffile.h" #include "dsffile.h"
@@ -36,38 +38,28 @@ using namespace Strawberry_TagLib::TagLib;
// The DSF specification is located at http://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf // The DSF specification is located at http://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf
class DSF::File::FilePrivate class DSF::File::FilePrivate {
{
public: public:
FilePrivate() : FilePrivate() : fileSize(0),
fileSize(0), metadataOffset(0) {}
metadataOffset(0),
properties(nullptr),
tag(nullptr)
{
}
~FilePrivate()
{
delete properties;
delete tag;
}
long long fileSize; long long fileSize;
long long metadataOffset; long long metadataOffset;
Properties *properties;
ID3v2::Tag *tag; std::unique_ptr<AudioProperties> properties;
std::unique_ptr<ID3v2::Tag> tag;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool DSF::File::isSupported(IOStream *stream) bool DSF::File::isSupported(IOStream *stream) {
{
// A DSF file has to start with "DSD " // A DSF file has to start with "DSD "
const ByteVector id = Utils::readHeader(stream, 4, false); const ByteVector id = Utils::readHeader(stream, 4, false);
return id.startsWith("DSD "); return id.startsWith("DSD ");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -75,50 +67,42 @@ bool DSF::File::isSupported(IOStream *stream)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
DSF::File::File(FileName file, bool readProperties, DSF::File::File(FileName file, bool readProperties,
Properties::ReadStyle propertiesStyle) : AudioProperties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties, propertiesStyle); read(readProperties, propertiesStyle);
} }
DSF::File::File(IOStream *stream, bool readProperties, DSF::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
Properties::ReadStyle propertiesStyle) :
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties, propertiesStyle); read(readProperties, propertiesStyle);
} }
DSF::File::~File() DSF::File::~File() {
{
delete d; delete d;
} }
ID3v2::Tag *DSF::File::tag() const ID3v2::Tag *DSF::File::tag() const {
{ return d->tag.get();
return d->tag;
} }
PropertyMap DSF::File::properties() const DSF::AudioProperties *DSF::File::audioProperties() const {
{ return d->properties.get();
}
PropertyMap DSF::File::properties() const {
return d->tag->properties(); return d->tag->properties();
} }
PropertyMap DSF::File::setProperties(const PropertyMap &properties) PropertyMap DSF::File::setProperties(const PropertyMap &properties) {
{
return d->tag->setProperties(properties); return d->tag->setProperties(properties);
} }
DSF::Properties *DSF::File::audioProperties() const bool DSF::File::save() {
{
return d->properties;
}
bool DSF::File::save()
{
if (readOnly()) { if (readOnly()) {
debug("DSF::File::save() -- File is read only."); debug("DSF::File::save() -- File is read only.");
return false; return false;
@@ -136,13 +120,13 @@ bool DSF::File::save()
// Update the file size // Update the file size
if (d->fileSize != newFileSize) { if (d->fileSize != newFileSize) {
insert(ByteVector::fromLongLong(newFileSize, false), 12, 8); insert(ByteVector::fromUInt64LE(newFileSize), 12, 8);
d->fileSize = newFileSize; d->fileSize = newFileSize;
} }
// Update the metadata offset to 0 since there is no longer a tag // Update the metadata offset to 0 since there is no longer a tag
if (d->metadataOffset) { if (d->metadataOffset) {
insert(ByteVector::fromLongLong(0ULL, false), 20, 8); insert(ByteVector::fromUInt64LE(0ULL), 20, 8);
d->metadataOffset = 0; d->metadataOffset = 0;
} }
@@ -158,13 +142,13 @@ bool DSF::File::save()
// Update the file size // Update the file size
if (d->fileSize != newFileSize) { if (d->fileSize != newFileSize) {
insert(ByteVector::fromLongLong(newFileSize, false), 12, 8); insert(ByteVector::fromUInt64LE(newFileSize), 12, 8);
d->fileSize = newFileSize; d->fileSize = newFileSize;
} }
// Update the metadata offset // Update the metadata offset
if (d->metadataOffset != newMetadataOffset) { if (d->metadataOffset != newMetadataOffset) {
insert(ByteVector::fromLongLong(newMetadataOffset, false), 20, 8); insert(ByteVector::fromUInt64LE(newMetadataOffset), 20, 8);
d->metadataOffset = newMetadataOffset; d->metadataOffset = newMetadataOffset;
} }
@@ -173,6 +157,7 @@ bool DSF::File::save()
} }
return true; return true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -180,8 +165,8 @@ bool DSF::File::save()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle) void DSF::File::read(bool, AudioProperties::ReadStyle propertiesStyle) {
{
// A DSF file consists of four chunks: DSD chunk, format chunk, data chunk, and metadata chunk // A DSF file consists of four chunks: DSD chunk, format chunk, data chunk, and metadata chunk
// The file format is not chunked in the sense of a RIFF File, though // The file format is not chunked in the sense of a RIFF File, though
@@ -193,7 +178,7 @@ void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
return; return;
} }
long long chunkSize = readBlock(8).toLongLong(false); long long chunkSize = readBlock(8).toInt64LE(0);
// Integrity check // Integrity check
if (28 != chunkSize) { if (28 != chunkSize) {
@@ -202,7 +187,7 @@ void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
return; return;
} }
d->fileSize = readBlock(8).toLongLong(false); d->fileSize = readBlock(8).toInt64LE(0);
// File is malformed or corrupted // File is malformed or corrupted
if (d->fileSize != length()) { if (d->fileSize != length()) {
@@ -211,7 +196,7 @@ void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
return; return;
} }
d->metadataOffset = readBlock(8).toLongLong(false); d->metadataOffset = readBlock(8).toInt64LE(0);
// File is malformed or corrupted // File is malformed or corrupted
if (d->metadataOffset > d->fileSize) { if (d->metadataOffset > d->fileSize) {
@@ -228,16 +213,16 @@ void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
return; return;
} }
chunkSize = readBlock(8).toLongLong(false); chunkSize = readBlock(8).toInt64LE(0);
d->properties = new Properties(readBlock(chunkSize), propertiesStyle); d->properties.reset(new AudioProperties(readBlock(chunkSize), propertiesStyle));
// Skip the data chunk // Skip the data chunk
// A metadata offset of 0 indicates the absence of an ID3v2 tag // A metadata offset of 0 indicates the absence of an ID3v2 tag
if (0 == d->metadataOffset) if (0 == d->metadataOffset)
d->tag = new ID3v2::Tag(); d->tag.reset(new ID3v2::Tag());
else else
d->tag = new ID3v2::Tag(this, d->metadataOffset); d->tag.reset(new ID3v2::Tag(this, d->metadataOffset));
}
}

View File

@@ -48,68 +48,64 @@ namespace TagLib {
/*! /*!
* This implements and provides an interface for DSF files to the * This implements and provides an interface for DSF files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing * Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional * the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional information specific to DSF files.
* information specific to DSF files. *
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* Constructs an DSF file from \a file. If \a readProperties is true the * Constructs an DSF file from \a file.
* file's audio properties will also be read using \a propertiesStyle. If * If \a readProperties is true the file's audio properties will also be read using \a propertiesStyle.
* false, \a propertiesStyle is ignored. * If false, \a propertiesStyle is ignored.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an DSF file from \a file. If \a readProperties is true the * Constructs an DSF file from \a file.
* file's audio properties will also be read using \a propertiesStyle. If * If \a readProperties is true the file's audio properties will also be read using \a propertiesStyle.
* false, \a propertiesStyle is ignored. * If false, \a propertiesStyle is ignored.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns the Tag for this file. * Returns the Tag for this file.
*/ */
ID3v2::Tag *tag() const; ID3v2::Tag *tag() const override;
/*! /*!
* Implements the unified property interface -- export function. * Implements the unified property interface -- export function.
* This method forwards to ID3v2::Tag::properties(). * This method forwards to ID3v2::Tag::properties().
*/ */
PropertyMap properties() const; PropertyMap properties() const override;
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* This method forwards to ID3v2::Tag::setProperties(). * This method forwards to ID3v2::Tag::setProperties().
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
/*! /*!
* Returns the DSF::AudioProperties for this file. If no audio properties * Returns the DSF::AudioProperties for this file.
* were read then this will return a null pointer. * If no audio properties were read then this will return a null pointer.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Saves the file. * Saves the file.
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Returns whether or not the given \a stream can be opened as a DSF * Returns whether or not the given \a stream can be opened as a DSF file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check.
* not necessarily be correct. * The result may not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -117,14 +113,13 @@ namespace TagLib {
File(const File &); File(const File &);
File &operator=(const File &); File &operator=(const File &);
void read(bool readProperties, Properties::ReadStyle propertiesStyle); void read(bool readProperties, AudioProperties::ReadStyle propertiesStyle);
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace DSF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,18 +23,16 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tstring.h> #include "tstring.h"
#include <tdebug.h> #include "tdebug.h"
#include "dsfproperties.h" #include "dsfproperties.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class DSF::Properties::PropertiesPrivate class DSF::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : formatVersion(0),
formatVersion(0),
formatID(0), formatID(0),
channelType(0), channelType(0),
channelNum(0), channelNum(0),
@@ -43,8 +41,7 @@ public:
sampleCount(0), sampleCount(0),
blockSizePerChannel(0), blockSizePerChannel(0),
bitrate(0), bitrate(0),
length(0) length(0) {
{
} }
// Nomenclature is from DSF file format specification // Nomenclature is from DSF file format specification
@@ -58,83 +55,64 @@ public:
unsigned int blockSizePerChannel; unsigned int blockSizePerChannel;
// Computed // Computed
unsigned int bitrate; int bitrate;
unsigned int length; int length;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
DSF::Properties::Properties(const ByteVector &data, ReadStyle style) : Strawberry_TagLib::TagLib::AudioProperties(style) DSF::AudioProperties::AudioProperties(const ByteVector &data, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
{
d = new PropertiesPrivate;
read(data); read(data);
} }
DSF::Properties::~Properties() DSF::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int DSF::Properties::length() const int DSF::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int DSF::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int DSF::Properties::lengthInMilliseconds() const int DSF::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int DSF::Properties::bitrate() const int DSF::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int DSF::Properties::sampleRate() const int DSF::AudioProperties::sampleRate() const {
{
return d->samplingFrequency; return d->samplingFrequency;
} }
int DSF::Properties::channels() const int DSF::AudioProperties::channels() const {
{
return d->channelNum; return d->channelNum;
} }
// DSF specific // DSF specific
int DSF::Properties::formatVersion() const int DSF::AudioProperties::formatVersion() const {
{
return d->formatVersion; return d->formatVersion;
} }
int DSF::Properties::formatID() const int DSF::AudioProperties::formatID() const {
{
return d->formatID; return d->formatID;
} }
int DSF::Properties::channelType() const int DSF::AudioProperties::channelType() const {
{
return d->channelType; return d->channelType;
} }
int DSF::Properties::bitsPerSample() const int DSF::AudioProperties::bitsPerSample() const {
{
return d->bitsPerSample; return d->bitsPerSample;
} }
long long DSF::Properties::sampleCount() const long long DSF::AudioProperties::sampleCount() const {
{
return d->sampleCount; return d->sampleCount;
} }
int DSF::Properties::blockSizePerChannel() const int DSF::AudioProperties::blockSizePerChannel() const {
{
return d->blockSizePerChannel; return d->blockSizePerChannel;
} }
@@ -142,20 +120,16 @@ int DSF::Properties::blockSizePerChannel() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void DSF::Properties::read(const ByteVector &data) void DSF::AudioProperties::read(const ByteVector &data) {
{ d->formatVersion = data.toUInt32LE(0);
d->formatVersion = data.toUInt(0U,false); d->formatID = data.toUInt32LE(4);
d->formatID = data.toUInt(4U,false); d->channelType = data.toUInt32LE(8);
d->channelType = data.toUInt(8U,false); d->channelNum = data.toUInt32LE(12);
d->channelNum = data.toUInt(12U,false); d->samplingFrequency = data.toUInt32LE(16);
d->samplingFrequency = data.toUInt(16U,false); d->bitsPerSample = data.toUInt32LE(20);
d->bitsPerSample = data.toUInt(20U,false); d->sampleCount = data.toInt64LE(24);
d->sampleCount = data.toLongLong(24U,false); d->blockSizePerChannel = data.toUInt32LE(32);
d->blockSizePerChannel = data.toUInt(32U,false);
d->bitrate d->bitrate = static_cast<int>((d->samplingFrequency * d->bitsPerSample * d->channelNum) / 1000.0 + 0.5);
= static_cast<unsigned int>((d->samplingFrequency * d->bitsPerSample * d->channelNum) / 1000.0 + 0.5); d->length = d->samplingFrequency > 0 ? static_cast<int>(d->sampleCount * 1000.0 / d->samplingFrequency + 0.5) : 0;
d->length
= d->samplingFrequency > 0 ? static_cast<unsigned int>(d->sampleCount * 1000.0 / d->samplingFrequency + 0.5) : 0;
} }

View File

@@ -30,7 +30,6 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace DSF { namespace DSF {
class File; class File;
@@ -38,39 +37,41 @@ namespace TagLib {
//! An implementation of audio property reading for DSF //! An implementation of audio property reading for DSF
/*! /*!
* This reads the data from a DSF stream found in the AudioProperties * This reads the data from a DSF stream found in the AudioProperties API.
* API.
*/ */
class TAGLIB_EXPORT Properties : public Strawberry_TagLib::TagLib::AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
/*! /*!
* Create an instance of DSF::AudioProperties with the data read from the * Create an instance of DSF::AudioProperties with the data read from the ByteVector \a data.
* ByteVector \a data.
*/ */
Properties(const ByteVector &data, ReadStyle style); explicit AudioProperties(const ByteVector &data, ReadStyle);
/*! /*!
* Destroys this DSF::AudioProperties instance. * Destroys this DSF::AudioProperties instance.
*/ */
virtual ~Properties(); ~AudioProperties() override;
// Reimplementations. // Reimplementations.
virtual int length() const; int lengthInSeconds() const override;
virtual int lengthInSeconds() const; int lengthInMilliseconds() const override;
virtual int lengthInMilliseconds() const; int bitrate() const override;
virtual int bitrate() const; int sampleRate() const override;
virtual int sampleRate() const; int channels() const override;
virtual int channels() const;
int formatVersion() const; int formatVersion() const;
int formatID() const; int formatID() const;
/*! /*!
* Channel type values: 1 = mono, 2 = stereo, 3 = 3 channels, * Channel type values:
* 4 = quad, 5 = 4 channels, 6 = 5 channels, 7 = 5.1 channels * 1 = mono,
* 2 = stereo,
* 3 = 3 channels,
* 4 = quad,
* 5 = 4 channels,
* 6 = 5 channels,
* 7 = 5.1 channels
*/ */
int channelType() const; int channelType() const;
int bitsPerSample() const; int bitsPerSample() const;
@@ -78,17 +79,16 @@ namespace TagLib {
int blockSizePerChannel() const; int blockSizePerChannel() const;
private: private:
Properties(const Properties &); AudioProperties(const AudioProperties&);
Properties &operator=(const Properties &); AudioProperties &operator=(const AudioProperties&);
void read(const ByteVector &data); void read(const ByteVector &data);
class PropertiesPrivate; class AudioPropertiesPrivate;
PropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
} } // namespace DSF
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -27,11 +27,12 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tfile.h> #include <memory>
#include <tfilestream.h>
#include <tstring.h> #include "tfile.h"
#include <tdebug.h> #include "tfilestream.h"
#include <trefcounter.h> #include "tstring.h"
#include "tdebug.h"
#include "fileref.h" #include "fileref.h"
#include "asffile.h" #include "asffile.h"
@@ -57,16 +58,14 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{
typedef List<const FileRef::FileTypeResolver*> ResolverList; typedef List<const FileRef::FileTypeResolver*> ResolverList;
ResolverList fileTypeResolvers; ResolverList fileTypeResolvers;
// Detect the file type by user-defined resolvers. // Detect the file type by user-defined resolvers.
File *detectByResolvers(FileName fileName, bool readAudioProperties, File *detectByResolvers(FileName fileName, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) {
AudioProperties::ReadStyle audioPropertiesStyle)
{
ResolverList::ConstIterator it = fileTypeResolvers.begin(); ResolverList::ConstIterator it = fileTypeResolvers.begin();
for (; it != fileTypeResolvers.end(); ++it) { for (; it != fileTypeResolvers.end(); ++it) {
File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle); File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle);
@@ -75,22 +74,22 @@ namespace
} }
return nullptr; return nullptr;
} }
// Detect the file type based on the file extension. // Detect the file type based on the file extension.
File* detectByExtension(IOStream *stream, bool readAudioProperties, File *detectByExtension(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) {
AudioProperties::ReadStyle audioPropertiesStyle)
{
#ifdef _WIN32 #ifdef _WIN32
const String s = stream->name().toString(); const String s(stream->name().wstr());
#else #else
const String s(stream->name()); const String s(stream->name());
#endif #endif
String ext; String ext;
const int pos = s.rfind("."); const size_t pos = s.rfind(".");
if(pos != -1) if (pos != String::npos())
ext = s.substr(pos + 1).upper(); ext = s.substr(pos + 1).upper();
// If this list is updated, the method defaultFileExtensions() should also be // If this list is updated, the method defaultFileExtensions() should also be
@@ -107,7 +106,7 @@ namespace
if (ext == "OGG") if (ext == "OGG")
return new Ogg::Vorbis::File(stream, readAudioProperties, audioPropertiesStyle); return new Ogg::Vorbis::File(stream, readAudioProperties, audioPropertiesStyle);
if (ext == "FLAC") if (ext == "FLAC")
return new FLAC::File(stream, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle); return new FLAC::File(stream, readAudioProperties, audioPropertiesStyle);
if (ext == "MPC") if (ext == "MPC")
return new MPC::File(stream, readAudioProperties, audioPropertiesStyle); return new MPC::File(stream, readAudioProperties, audioPropertiesStyle);
if (ext == "WV") if (ext == "WV")
@@ -143,14 +142,14 @@ namespace
return new DSF::File(stream, readAudioProperties, audioPropertiesStyle); return new DSF::File(stream, readAudioProperties, audioPropertiesStyle);
return nullptr; return nullptr;
} }
// Detect the file type based on the actual content of the stream. // Detect the file type based on the actual content of the stream.
File *detectByContent(IOStream *stream, bool readAudioProperties, File *detectByContent(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) {
AudioProperties::ReadStyle audioPropertiesStyle)
{ File *file = nullptr;
File *file = 0;
if (MPEG::File::isSupported(stream)) if (MPEG::File::isSupported(stream))
file = new MPEG::File(stream, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle); file = new MPEG::File(stream, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
@@ -159,7 +158,7 @@ namespace
else if (Ogg::FLAC::File::isSupported(stream)) else if (Ogg::FLAC::File::isSupported(stream))
file = new Ogg::FLAC::File(stream, readAudioProperties, audioPropertiesStyle); file = new Ogg::FLAC::File(stream, readAudioProperties, audioPropertiesStyle);
else if (FLAC::File::isSupported(stream)) else if (FLAC::File::isSupported(stream))
file = new FLAC::File(stream, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle); file = new FLAC::File(stream, readAudioProperties, audioPropertiesStyle);
else if (MPC::File::isSupported(stream)) else if (MPC::File::isSupported(stream))
file = new MPC::File(stream, readAudioProperties, audioPropertiesStyle); file = new MPC::File(stream, readAudioProperties, audioPropertiesStyle);
else if (WavPack::File::isSupported(stream)) else if (WavPack::File::isSupported(stream))
@@ -195,94 +194,13 @@ namespace
} }
return nullptr; return nullptr;
} }
// Internal function that supports FileRef::create(). struct FileRefData {
// This looks redundant, but necessary in order not to change the previous FileRefData() : file(nullptr), stream(nullptr) {}
// behavior of FileRef::create().
File* createInternal(FileName fileName, bool readAudioProperties, ~FileRefData() {
AudioProperties::ReadStyle audioPropertiesStyle)
{
File *file = detectByResolvers(fileName, readAudioProperties, audioPropertiesStyle);
if(file)
return file;
#ifdef _WIN32
const String s = fileName.toString();
#else
const String s(fileName);
#endif
String ext;
const int pos = s.rfind(".");
if(pos != -1)
ext = s.substr(pos + 1).upper();
if(ext.isEmpty())
return nullptr;
if(ext == "MP3")
return new MPEG::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
if(ext == "OGG")
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "OGA") {
/* .oga can be any audio in the Ogg container. First try FLAC, then Vorbis. */
File *file = new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
if(file->isValid())
return file;
delete file;
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
}
if(ext == "FLAC")
return new FLAC::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
if(ext == "MPC")
return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "WV")
return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "SPX")
return new Ogg::Speex::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "OPUS")
return new Ogg::Opus::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "TTA")
return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "M4A" || ext == "M4R" || ext == "M4B" || ext == "M4P" || ext == "MP4" || ext == "3G2" || ext == "M4V")
return new MP4::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "WMA" || ext == "ASF")
return new ASF::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "AIF" || ext == "AIFF" || ext == "AFC" || ext == "AIFC")
return new RIFF::AIFF::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "WAV")
return new RIFF::WAV::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "APE")
return new APE::File(fileName, readAudioProperties, audioPropertiesStyle);
// module, nst and wow are possible but uncommon extensions
if(ext == "MOD" || ext == "MODULE" || ext == "NST" || ext == "WOW")
return new Mod::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "S3M")
return new S3M::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "IT")
return new IT::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "XM")
return new XM::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "DFF" || ext == "DSDIFF")
return new DSDIFF::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "DSF")
return new DSF::File(fileName, readAudioProperties, audioPropertiesStyle);
return nullptr;
}
}
class FileRef::FileRefPrivate : public RefCounter
{
public:
FileRefPrivate() :
RefCounter(),
file(0),
stream(0) {}
~FileRefPrivate() {
delete file; delete file;
delete stream; delete stream;
} }
@@ -291,86 +209,108 @@ public:
IOStream *stream; IOStream *stream;
}; };
} // namespace
class FileRef::FileRefPrivate {
public:
FileRefPrivate() : data(new FileRefData()) {}
std::shared_ptr<FileRefData> data;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FileRef::FileRef() : FileRef::FileRef() : d(new FileRefPrivate()) {}
d(new FileRefPrivate())
{
}
FileRef::FileRef(FileName fileName, bool readAudioProperties, FileRef::FileRef(FileName fileName, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) : d(new FileRefPrivate()) {
AudioProperties::ReadStyle audioPropertiesStyle) :
d(new FileRefPrivate())
{
parse(fileName, readAudioProperties, audioPropertiesStyle); parse(fileName, readAudioProperties, audioPropertiesStyle);
} }
FileRef::FileRef(IOStream* stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) : FileRef::FileRef(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) : d(new FileRefPrivate()) {
d(new FileRefPrivate())
{
parse(stream, readAudioProperties, audioPropertiesStyle); parse(stream, readAudioProperties, audioPropertiesStyle);
} }
FileRef::FileRef(File *file) : FileRef::FileRef(File *file) : d(new FileRefPrivate()) {
d(new FileRefPrivate()) d->data->file = file;
{
d->file = file;
} }
FileRef::FileRef(const FileRef &ref) : FileRef::FileRef(const FileRef &ref) : d(new FileRefPrivate(*ref.d)) {}
d(ref.d)
{
d->ref();
}
FileRef::~FileRef() FileRef::~FileRef() {
{
if(d->deref())
delete d; delete d;
} }
Tag *FileRef::tag() const Tag *FileRef::tag() const {
{
if (isNull()) { if (isNull()) {
debug("FileRef::tag() - Called without a valid file."); debug("FileRef::tag() - Called without a valid file.");
return nullptr; return nullptr;
} }
return d->file->tag(); return d->data->file->tag();
} }
AudioProperties *FileRef::audioProperties() const PropertyMap FileRef::properties() const {
{ if (isNull()) {
debug("FileRef::properties() - Called without a valid file.");
return PropertyMap();
}
return d->data->file->properties();
}
void FileRef::removeUnsupportedProperties(const StringList &properties) {
if (isNull()) {
debug("FileRef::removeUnsupportedProperties() - Called without a valid file.");
return;
}
d->data->file->removeUnsupportedProperties(properties);
}
PropertyMap FileRef::setProperties(const PropertyMap &properties) {
if (isNull()) {
debug("FileRef::setProperties() - Called without a valid file.");
return PropertyMap();
}
return d->data->file->setProperties(properties);
}
AudioProperties *FileRef::audioProperties() const {
if (isNull()) { if (isNull()) {
debug("FileRef::audioProperties() - Called without a valid file."); debug("FileRef::audioProperties() - Called without a valid file.");
return nullptr; return nullptr;
} }
return d->file->audioProperties(); return d->data->file->audioProperties();
} }
File *FileRef::file() const File *FileRef::file() const {
{ return d->data->file;
return d->file;
} }
bool FileRef::save() bool FileRef::save() {
{
if (isNull()) { if (isNull()) {
debug("FileRef::save() - Called without a valid file."); debug("FileRef::save() - Called without a valid file.");
return false; return false;
} }
return d->file->save(); return d->data->file->save();
} }
const FileRef::FileTypeResolver *FileRef::addFileTypeResolver(const FileRef::FileTypeResolver *resolver) // static const FileRef::FileTypeResolver *FileRef::addFileTypeResolver(const FileRef::FileTypeResolver *resolver) { // static
{
fileTypeResolvers.prepend(resolver); fileTypeResolvers.prepend(resolver);
return resolver; return resolver;
} }
StringList FileRef::defaultFileExtensions() StringList FileRef::defaultFileExtensions() {
{
StringList l; StringList l;
l.append("ogg"); l.append("ogg");
@@ -406,86 +346,79 @@ StringList FileRef::defaultFileExtensions()
l.append("dsdiff"); // alias for "dff" l.append("dsdiff"); // alias for "dff"
return l; return l;
} }
bool FileRef::isNull() const bool FileRef::isValid() const {
{ return (d->data->file && d->data->file->isValid());
return (!d->file || !d->file->isValid());
} }
FileRef &FileRef::operator=(const FileRef &ref) bool FileRef::isNull() const {
{ return (!d->data->file || !d->data->file->isValid());
}
FileRef &FileRef::operator=(const FileRef &ref) {
FileRef(ref).swap(*this); FileRef(ref).swap(*this);
return *this; return *this;
} }
void FileRef::swap(FileRef &ref) void FileRef::swap(FileRef &ref) {
{
using std::swap; using std::swap;
swap(d, ref.d); swap(d, ref.d);
} }
bool FileRef::operator==(const FileRef &ref) const bool FileRef::operator==(const FileRef &ref) const {
{ return (ref.d->data == d->data);
return (ref.d->file == d->file);
} }
bool FileRef::operator!=(const FileRef &ref) const bool FileRef::operator!=(const FileRef &ref) const {
{ return (ref.d->data != d->data);
return (ref.d->file != d->file);
}
File *FileRef::create(FileName fileName, bool readAudioProperties,
AudioProperties::ReadStyle audioPropertiesStyle) // static
{
return createInternal(fileName, readAudioProperties, audioPropertiesStyle);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void FileRef::parse(FileName fileName, bool readAudioProperties, void FileRef::parse(FileName fileName, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) {
AudioProperties::ReadStyle audioPropertiesStyle)
{
// Try user-defined resolvers. // Try user-defined resolvers.
d->file = detectByResolvers(fileName, readAudioProperties, audioPropertiesStyle); d->data->file = detectByResolvers(fileName, readAudioProperties, audioPropertiesStyle);
if(d->file) if (d->data->file)
return; return;
// Try to resolve file types based on the file extension. // Try to resolve file types based on the file extension.
d->stream = new FileStream(fileName); d->data->stream = new FileStream(fileName);
d->file = detectByExtension(d->stream, readAudioProperties, audioPropertiesStyle); d->data->file = detectByExtension(d->data->stream, readAudioProperties, audioPropertiesStyle);
if(d->file) if (d->data->file)
return; return;
// At last, try to resolve file types based on the actual content. // At last, try to resolve file types based on the actual content.
d->file = detectByContent(d->stream, readAudioProperties, audioPropertiesStyle); d->data->file = detectByContent(d->data->stream, readAudioProperties, audioPropertiesStyle);
if(d->file) if (d->data->file)
return; return;
// Stream have to be closed here if failed to resolve file types. // Stream have to be closed here if failed to resolve file types.
delete d->stream; delete d->data->stream;
d->stream = 0; d->data->stream = nullptr;
} }
void FileRef::parse(IOStream *stream, bool readAudioProperties, void FileRef::parse(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) {
AudioProperties::ReadStyle audioPropertiesStyle)
{
// User-defined resolvers won't work with a stream. // User-defined resolvers won't work with a stream.
// Try to resolve file types based on the file extension. // Try to resolve file types based on the file extension.
d->file = detectByExtension(stream, readAudioProperties, audioPropertiesStyle); d->data->file = detectByExtension(stream, readAudioProperties, audioPropertiesStyle);
if(d->file) if (d->data->file)
return; return;
// At last, try to resolve file types based on the actual content of the file. // At last, try to resolve file types based on the actual content of the file.
d->file = detectByContent(stream, readAudioProperties, audioPropertiesStyle); d->data->file = detectByContent(stream, readAudioProperties, audioPropertiesStyle);
} }

View File

@@ -30,6 +30,7 @@
#include "tstringlist.h" #include "tstringlist.h"
#include "taglib_export.h" #include "taglib_export.h"
#include "tpropertymap.h"
#include "audioproperties.h" #include "audioproperties.h"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
@@ -40,32 +41,26 @@ namespace TagLib {
//! This class provides a simple abstraction for creating and handling files //! This class provides a simple abstraction for creating and handling files
/*! /*!
* FileRef exists to provide a minimal, generic and value-based wrapper around * FileRef exists to provide a minimal, generic and value-based wrapper around a File.
* a File. It is lightweight and implicitly shared, and as such suitable for * It is lightweight and implicitly shared, and as such suitable for pass-by-value use.
* pass-by-value use. This hides some of the uglier details of TagLib::File * This hides some of the uglier details of TagLib::File and the non-generic portions of the concrete file implementations.
* and the non-generic portions of the concrete file implementations.
* *
* This class is useful in a "simple usage" situation where it is desirable * This class is useful in a "simple usage" situation where it is desirable
* to be able to get and set some of the tag information that is similar * to be able to get and set some of the tag information that is similar across file types.
* across file types.
* *
* Also note that it is probably a good idea to plug this into your mime * Also note that it is probably a good idea to plug this into your mime
* type system rather than using the constructor that accepts a file name using * type system rather than using the constructor that accepts a file name using the FileTypeResolver.
* the FileTypeResolver.
* *
* \see FileTypeResolver * \see FileTypeResolver
* \see addFileTypeResolver() * \see addFileTypeResolver()
*/ */
class TAGLIB_EXPORT FileRef class TAGLIB_EXPORT FileRef {
{
public: public:
//! A class for pluggable file type resolution. //! A class for pluggable file type resolution.
/*! /*!
* This class is used to add extend TagLib's very basic file name based file * This class is used to add extend TagLib's very basic file name based file type resolution.
* type resolution.
* *
* This can be accomplished with: * This can be accomplished with:
* *
@@ -85,69 +80,52 @@ namespace TagLib {
* *
* \endcode * \endcode
* *
* Naturally a less contrived example would be slightly more complex. This * Naturally a less contrived example would be slightly more complex.
* can be used to plug in mime-type detection systems or to add new file types * This can be used to plug in mime-type detection systems or to add new file types to TagLib.
* to TagLib.
*/ */
class TAGLIB_EXPORT FileTypeResolver class TAGLIB_EXPORT FileTypeResolver {
{
TAGLIB_IGNORE_MISSING_DESTRUCTOR
public: public:
virtual ~FileTypeResolver() {}
/*! /*!
* This method must be overridden to provide an additional file type * This method must be overridden to provide an additional file type resolver.
* resolver. If the resolver is able to determine the file type it should * If the resolver is able to determine the file type it should return a valid File object; if not it should return 0.
* return a valid File object; if not it should return 0.
* *
* \note The created file is then owned by the FileRef and should not be * \note The created file is then owned by the FileRef and should not be deleted.
* deleted. Deletion will happen automatically when the FileRef passes * Deletion will happen automatically when the FileRef passes out of scope.
* out of scope.
*/ */
virtual File *createFile(FileName fileName, virtual File *createFile(FileName fileName, bool readAudioProperties = true, AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average) const = 0;
bool readAudioProperties = true,
AudioProperties::ReadStyle
audioPropertiesStyle = AudioProperties::Average) const = 0;
}; };
/*! /*!
* Creates a null FileRef. * Creates a null FileRef.
*/ */
FileRef(); explicit FileRef();
/*! /*!
* Create a FileRef from \a fileName. If \a readAudioProperties is true then * Create a FileRef from \a fileName.
* the audio properties will be read using \a audioPropertiesStyle. If * If \a readAudioProperties is true then the audio properties will be read using \a audioPropertiesStyle.
* \a readAudioProperties is false then \a audioPropertiesStyle will be * If \a readAudioProperties is false then \a audioPropertiesStyle will be ignored.
* ignored.
* *
* Also see the note in the class documentation about why you may not want to * Also see the note in the class documentation about why you may not want to
* use this method in your application. * use this method in your application.
*/ */
explicit FileRef(FileName fileName, explicit FileRef(FileName fileName, bool readAudioProperties = true, AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
bool readAudioProperties = true,
AudioProperties::ReadStyle
audioPropertiesStyle = AudioProperties::Average);
/*! /*!
* Construct a FileRef from an opened \a IOStream. If \a readAudioProperties * Construct a FileRef from an opened \a IOStream.
* is true then the audio properties will be read using \a audioPropertiesStyle. * If \a readAudioProperties is true then the audio properties will be read using \a audioPropertiesStyle.
* If \a readAudioProperties is false then \a audioPropertiesStyle will be * If \a readAudioProperties is false then \a audioPropertiesStyle will be ignored.
* ignored.
* *
* Also see the note in the class documentation about why you may not want to * Also see the note in the class documentation about why you may not want to use this method in your application.
* use this method in your application.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* responsible for deleting it after the File object.
*/ */
explicit FileRef(IOStream* stream, explicit FileRef(IOStream *stream, bool readAudioProperties = true, AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
bool readAudioProperties = true,
AudioProperties::ReadStyle
audioPropertiesStyle = AudioProperties::Average);
/*! /*!
* Construct a FileRef using \a file. The FileRef now takes ownership of the * Construct a FileRef using \a file.
* pointer and will delete the File when it passes out of scope. * The FileRef now takes ownership of the pointer and will delete the File when it passes out of scope.
*/ */
explicit FileRef(File *file); explicit FileRef(File *file);
@@ -175,8 +153,36 @@ namespace TagLib {
Tag *tag() const; Tag *tag() const;
/*! /*!
* Returns the audio properties for this FileRef. If no audio properties * Exports the tags of the file as dictionary mapping (human readable) tag names (uppercase Strings) to StringLists of tag values.
* were read then this will returns a null pointer. * Calls the according specialization in the File subclasses.
* For each metadata object of the file that could not be parsed into the PropertyMap format,
* the returend map's unsupportedData() list will contain one entry identifying that object (e.g. the frame type for ID3v2 tags).
* Use removeUnsupportedProperties() to remove (a subset of) them.
* For files that contain more than one tag (e.g. an MP3 with both an ID3v1 and an ID3v2 tag) only the most "modern" one will be exported (ID3v2 in this case).
*/
PropertyMap properties() const;
/*!
* Removes unsupported properties, or a subset of them, from the file's metadata.
* The parameter \a properties must contain only entries from properties().unsupportedData().
*/
void removeUnsupportedProperties(const StringList &properties);
/*!
* Sets the tags of this File to those specified in \a properties.
* Calls the according specialization method in the subclasses of File to do the translation into the format-specific details.
* If some value(s) could not be written imported to the specific metadata format,
* the returned PropertyMap will contain those value(s). Otherwise it will be empty, indicating that no problems occured.
* With file types that support several tag formats (for instance, MP3 files can have ID3v1, ID3v2, and APEv2 tags),
* this function will create the most appropriate one (ID3v2 for MP3 files). Older formats will be updated as well,
* if they exist, but won't be taken into account for the return value of this function.
* See the documentation of the subclass implementations for detailed descriptions.
*/
PropertyMap setProperties(const PropertyMap &properties);
/*!
* Returns the audio properties for this FileRef.
* If no audio properties were read then this will returns a null pointer.
*/ */
AudioProperties *audioProperties() const; AudioProperties *audioProperties() const;
@@ -203,14 +209,12 @@ namespace TagLib {
bool save(); bool save();
/*! /*!
* Adds a FileTypeResolver to the list of those used by TagLib. Each * Adds a FileTypeResolver to the list of those used by TagLib.
* additional FileTypeResolver is added to the front of a list of resolvers * Each additional FileTypeResolver is added to the front of a list of resolvers that are tried.
* that are tried. If the FileTypeResolver returns zero the next resolver * If the FileTypeResolver returns zero the next resolver is tried.
* is tried.
* *
* Returns a pointer to the added resolver (the same one that's passed in -- * Returns a pointer to the added resolver (the same one that's passed in --
* this is mostly so that static initializers have something to use for * this is mostly so that static initializers have something to use for assignment).
* assignment).
* *
* \see FileTypeResolver * \see FileTypeResolver
*/ */
@@ -218,8 +222,7 @@ namespace TagLib {
/*! /*!
* As is mentioned elsewhere in this class's documentation, the default file * As is mentioned elsewhere in this class's documentation, the default file
* type resolution code provided by TagLib only works by comparing file * type resolution code provided by TagLib only works by comparing file extensions.
* extensions.
* *
* This method returns the list of file extensions that are used by default. * This method returns the list of file extensions that are used by default.
* *
@@ -234,6 +237,13 @@ namespace TagLib {
*/ */
static StringList defaultFileExtensions(); static StringList defaultFileExtensions();
/*!
* Returns true if the file is open and readable.
*
* \note Just a negative of isNull().
*/
bool isValid() const;
/*! /*!
* Returns true if the file (and as such other pointers) are null. * Returns true if the file (and as such other pointers) are null.
*/ */
@@ -255,26 +265,10 @@ namespace TagLib {
bool operator==(const FileRef &ref) const; bool operator==(const FileRef &ref) const;
/*! /*!
* Returns true if this FileRef and \a ref do not point to the same File * Returns true if this FileRef and \a ref do not point to the same File object.
* object.
*/ */
bool operator!=(const FileRef &ref) const; bool operator!=(const FileRef &ref) const;
/*!
* A simple implementation of file type guessing. If \a readAudioProperties
* is true then the audio properties will be read using
* \a audioPropertiesStyle. If \a readAudioProperties is false then
* \a audioPropertiesStyle will be ignored.
*
* \note You generally shouldn't use this method, but instead the constructor
* directly.
*
* \deprecated
*/
static File *create(FileName fileName,
bool readAudioProperties = true,
AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
private: private:
void parse(FileName fileName, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle); void parse(FileName fileName, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle);
void parse(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle); void parse(IOStream *stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle);
@@ -283,7 +277,7 @@ namespace TagLib {
FileRefPrivate *d; FileRefPrivate *d;
}; };
} } // namespace TagLib
} // namespace Strawberry_TagLib::TagLib } // namespace Strawberry_TagLib
#endif #endif // TAGLIB_FILEREF_H

View File

@@ -23,18 +23,20 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include <memory>
#include <tstring.h>
#include <tlist.h>
#include <tdebug.h>
#include <tagunion.h>
#include <tpropertymap.h>
#include <tagutils.h>
#include <id3v2header.h> #include "tbytevector.h"
#include <id3v2tag.h> #include "tstring.h"
#include <id3v1tag.h> #include "tlist.h"
#include <xiphcomment.h> #include "tdebug.h"
#include "tagunion.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "id3v2header.h"
#include "id3v2tag.h"
#include "id3v1tag.h"
#include "xiphcomment.h"
#include "flacpicture.h" #include "flacpicture.h"
#include "flacfile.h" #include "flacfile.h"
@@ -43,55 +45,63 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{ typedef List<std::shared_ptr<FLAC::MetadataBlock>> BlockList;
typedef List<FLAC::MetadataBlock *> BlockList;
typedef BlockList::Iterator BlockIterator; typedef BlockList::Iterator BlockIterator;
typedef BlockList::Iterator BlockConstIterator; typedef BlockList::Iterator BlockConstIterator;
enum { FlacXiphIndex = 0, FlacID3v2Index = 1, FlacID3v1Index = 2 }; enum { FlacXiphIndex = 0,
FlacID3v2Index = 1,
FlacID3v1Index = 2 };
const long MinPaddingLength = 4096; const long long MinPaddingLength = 4096;
const long MaxPaddingLegnth = 1024 * 1024; const long long MaxPaddingLegnth = 1024 * 1024;
const char LastBlockFlag = '\x80'; const char LastBlockFlag = '\x80';
} } // namespace
class FLAC::File::FilePrivate namespace Strawberry_TagLib {
{ namespace TagLib {
namespace FLAC {
// Enables BlockList::find() to take raw pointers.
bool operator==(std::shared_ptr<MetadataBlock> lhs, MetadataBlock *rhs);
bool operator==(std::shared_ptr<MetadataBlock> lhs, MetadataBlock *rhs) {
return lhs.get() == rhs;
}
} // namespace FLAC
} // namespace TagLib
} // namespace Strawberry_TagLib
class FLAC::File::FilePrivate {
public: public:
explicit FilePrivate(const ID3v2::FrameFactory *frameFactory = ID3v2::FrameFactory::instance()) : explicit FilePrivate(const ID3v2::FrameFactory *frameFactory) : ID3v2FrameFactory(ID3v2::FrameFactory::instance()),
ID3v2FrameFactory(frameFactory),
ID3v2Location(-1), ID3v2Location(-1),
ID3v2OriginalSize(0), ID3v2OriginalSize(0),
ID3v1Location(-1), ID3v1Location(-1),
properties(0),
flacStart(0), flacStart(0),
streamStart(0), streamStart(0),
scanned(false) scanned(false) {
{
blocks.setAutoDelete(true); if (frameFactory)
} ID3v2FrameFactory = frameFactory;
~FilePrivate()
{
delete properties;
} }
const ID3v2::FrameFactory *ID3v2FrameFactory; const ID3v2::FrameFactory *ID3v2FrameFactory;
long ID3v2Location; long long ID3v2Location;
long ID3v2OriginalSize; long long ID3v2OriginalSize;
long ID3v1Location; long long ID3v1Location;
TagUnion tag; TripleTagUnion tag;
Properties *properties; std::unique_ptr<AudioProperties> properties;
ByteVector xiphCommentData; ByteVector xiphCommentData;
BlockList blocks; BlockList blocks;
long flacStart; long long flacStart;
long streamStart; long long streamStart;
bool scanned; bool scanned;
}; };
@@ -99,76 +109,51 @@ public:
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool FLAC::File::isSupported(IOStream *stream) bool FLAC::File::isSupported(IOStream *stream) {
{
// A FLAC file has an ID "fLaC" somewhere. An ID3v2 tag may precede. // A FLAC file has an ID "fLaC" somewhere. An ID3v2 tag may precede.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true); const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true);
return (buffer.find("fLaC") >= 0); return (buffer.find("fLaC") != ByteVector::npos());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FLAC::File::File(FileName file, bool readProperties, Properties::ReadStyle) : FLAC::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle, ID3v2::FrameFactory *frameFactory) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate(frameFactory)) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
FLAC::File::File(FileName file, ID3v2::FrameFactory *frameFactory, FLAC::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle, ID3v2::FrameFactory *frameFactory) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate(frameFactory)) {
bool readProperties, Properties::ReadStyle) :
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate(frameFactory))
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
FLAC::File::File(IOStream *stream, ID3v2::FrameFactory *frameFactory, FLAC::File::~File() {
bool readProperties, Properties::ReadStyle) :
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate(frameFactory))
{
if(isOpen())
read(readProperties);
}
FLAC::File::~File()
{
delete d; delete d;
} }
Strawberry_TagLib::TagLib::Tag *FLAC::File::tag() const Strawberry_TagLib::TagLib::Tag *FLAC::File::tag() const {
{
return &d->tag; return &d->tag;
} }
PropertyMap FLAC::File::properties() const PropertyMap FLAC::File::setProperties(const PropertyMap &properties) {
{
return d->tag.properties();
}
void FLAC::File::removeUnsupportedProperties(const StringList &unsupported)
{
d->tag.removeUnsupportedProperties(unsupported);
}
PropertyMap FLAC::File::setProperties(const PropertyMap &properties)
{
return xiphComment(true)->setProperties(properties); return xiphComment(true)->setProperties(properties);
} }
FLAC::Properties *FLAC::File::audioProperties() const FLAC::AudioProperties *FLAC::File::audioProperties() const {
{ return d->properties.get();
return d->properties;
} }
bool FLAC::File::save() bool FLAC::File::save() {
{
if (readOnly()) { if (readOnly()) {
debug("FLAC::File::save() - Cannot save to a read only file."); debug("FLAC::File::save() - Cannot save to a read only file.");
return false; return false;
@@ -190,20 +175,19 @@ bool FLAC::File::save()
for (BlockIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) { for (BlockIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) {
if ((*it)->code() == MetadataBlock::VorbisComment) { if ((*it)->code() == MetadataBlock::VorbisComment) {
// Set the new Vorbis Comment block // Set the new Vorbis Comment block
delete *it;
d->blocks.erase(it); d->blocks.erase(it);
break; break;
} }
} }
d->blocks.append(new UnknownMetadataBlock(MetadataBlock::VorbisComment, d->xiphCommentData)); d->blocks.append(std::shared_ptr<MetadataBlock>(new UnknownMetadataBlock(MetadataBlock::VorbisComment, d->xiphCommentData)));
// Render data for the metadata blocks // Render data for the metadata blocks
ByteVector data; ByteVector data;
for (BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) { for (BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) {
ByteVector blockData = (*it)->render(); ByteVector blockData = (*it)->render();
ByteVector blockHeader = ByteVector::fromUInt(blockData.size()); ByteVector blockHeader = ByteVector::fromUInt32BE(blockData.size());
blockHeader[0] = (*it)->code(); blockHeader[0] = (*it)->code();
data.append(blockHeader); data.append(blockHeader);
data.append(blockData); data.append(blockData);
@@ -211,8 +195,8 @@ bool FLAC::File::save()
// Compute the amount of padding, and append that to data. // Compute the amount of padding, and append that to data.
long originalLength = d->streamStart - d->flacStart; long long originalLength = d->streamStart - d->flacStart;
long paddingLength = originalLength - data.size() - 4; long long paddingLength = originalLength - data.size() - 4;
if (paddingLength <= 0) { if (paddingLength <= 0) {
paddingLength = MinPaddingLength; paddingLength = MinPaddingLength;
@@ -220,7 +204,7 @@ bool FLAC::File::save()
else { else {
// Padding won't increase beyond 1% of the file size or 1MB. // Padding won't increase beyond 1% of the file size or 1MB.
long threshold = length() / 100; long long threshold = length() / 100;
threshold = std::max(threshold, MinPaddingLength); threshold = std::max(threshold, MinPaddingLength);
threshold = std::min(threshold, MaxPaddingLegnth); threshold = std::min(threshold, MaxPaddingLegnth);
@@ -228,10 +212,10 @@ bool FLAC::File::save()
paddingLength = MinPaddingLength; paddingLength = MinPaddingLength;
} }
ByteVector paddingHeader = ByteVector::fromUInt(paddingLength); ByteVector paddingHeader = ByteVector::fromUInt32BE(paddingLength);
paddingHeader[0] = static_cast<char>(MetadataBlock::Padding | LastBlockFlag); paddingHeader[0] = static_cast<char>(MetadataBlock::Padding | LastBlockFlag);
data.append(paddingHeader); data.append(paddingHeader);
data.resize(static_cast<unsigned int>(data.size() + paddingLength)); data.resize(static_cast<size_t>(data.size() + paddingLength));
// Write the data to the file // Write the data to the file
@@ -305,106 +289,83 @@ bool FLAC::File::save()
} }
return true; return true;
} }
ID3v2::Tag *FLAC::File::ID3v2Tag(bool create) ID3v2::Tag *FLAC::File::ID3v2Tag(bool create) {
{
return d->tag.access<ID3v2::Tag>(FlacID3v2Index, create); return d->tag.access<ID3v2::Tag>(FlacID3v2Index, create);
} }
ID3v1::Tag *FLAC::File::ID3v1Tag(bool create) ID3v1::Tag *FLAC::File::ID3v1Tag(bool create) {
{
return d->tag.access<ID3v1::Tag>(FlacID3v1Index, create); return d->tag.access<ID3v1::Tag>(FlacID3v1Index, create);
} }
Ogg::XiphComment *FLAC::File::xiphComment(bool create) Ogg::XiphComment *FLAC::File::xiphComment(bool create) {
{
return d->tag.access<Ogg::XiphComment>(FlacXiphIndex, create); return d->tag.access<Ogg::XiphComment>(FlacXiphIndex, create);
} }
void FLAC::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory) List<FLAC::Picture *> FLAC::File::pictureList() {
{
d->ID3v2FrameFactory = factory;
}
ByteVector FLAC::File::streamInfoData()
{
debug("FLAC::File::streamInfoData() -- This function is obsolete. Returning an empty ByteVector.");
return ByteVector();
}
long FLAC::File::streamLength()
{
debug("FLAC::File::streamLength() -- This function is obsolete. Returning zero.");
return 0;
}
List<FLAC::Picture *> FLAC::File::pictureList()
{
List<Picture *> pictures; List<Picture *> pictures;
for (BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) { for (BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) {
Picture *picture = dynamic_cast<Picture *>(*it); Picture *picture = dynamic_cast<Picture *>(it->get());
if (picture) { if (picture) {
pictures.append(picture); pictures.append(picture);
} }
} }
return pictures; return pictures;
} }
void FLAC::File::addPicture(Picture *picture) void FLAC::File::addPicture(Picture *picture) {
{ d->blocks.append(std::shared_ptr<Picture>(picture));
d->blocks.append(picture);
} }
void FLAC::File::removePicture(Picture *picture, bool del) void FLAC::File::removePicture(Picture *picture) {
{
BlockIterator it = d->blocks.find(picture); BlockIterator it = d->blocks.find(picture);
if (it != d->blocks.end()) if (it != d->blocks.end())
d->blocks.erase(it); d->blocks.erase(it);
if(del)
delete picture;
} }
void FLAC::File::removePictures() void FLAC::File::removePictures() {
{
for (BlockIterator it = d->blocks.begin(); it != d->blocks.end();) { for (BlockIterator it = d->blocks.begin(); it != d->blocks.end();) {
if(dynamic_cast<Picture *>(*it)) { if (dynamic_cast<Picture *>(it->get())) {
delete *it;
it = d->blocks.erase(it); it = d->blocks.erase(it);
} }
else { else {
++it; ++it;
} }
} }
} }
void FLAC::File::strip(int tags) void FLAC::File::strip(int tags) {
{
if (tags & ID3v1) if (tags & ID3v1)
d->tag.set(FlacID3v1Index, 0); d->tag.set(FlacID3v1Index, nullptr);
if (tags & ID3v2) if (tags & ID3v2)
d->tag.set(FlacID3v2Index, 0); d->tag.set(FlacID3v2Index, nullptr);
if (tags & XiphComment) { if (tags & XiphComment) {
xiphComment()->removeAllFields(); xiphComment()->removeAllFields();
xiphComment()->removeAllPictures(); xiphComment()->removeAllPictures();
} }
} }
bool FLAC::File::hasXiphComment() const bool FLAC::File::hasXiphComment() const {
{
return !d->xiphCommentData.isEmpty(); return !d->xiphCommentData.isEmpty();
} }
bool FLAC::File::hasID3v1Tag() const bool FLAC::File::hasID3v1Tag() const {
{
return (d->ID3v1Location >= 0); return (d->ID3v1Location >= 0);
} }
bool FLAC::File::hasID3v2Tag() const bool FLAC::File::hasID3v2Tag() const {
{
return (d->ID3v2Location >= 0); return (d->ID3v2Location >= 0);
} }
@@ -412,8 +373,8 @@ bool FLAC::File::hasID3v2Tag() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void FLAC::File::read(bool readProperties) void FLAC::File::read(bool readProperties) {
{
// Look for an ID3v2 tag // Look for an ID3v2 tag
d->ID3v2Location = Utils::findID3v2(this); d->ID3v2Location = Utils::findID3v2(this);
@@ -448,19 +409,20 @@ void FLAC::File::read(bool readProperties)
const ByteVector infoData = d->blocks.front()->render(); const ByteVector infoData = d->blocks.front()->render();
long streamLength; long long streamLength;
if (d->ID3v1Location >= 0) if (d->ID3v1Location >= 0)
streamLength = d->ID3v1Location - d->streamStart; streamLength = d->ID3v1Location - d->streamStart;
else else
streamLength = length() - d->streamStart; streamLength = length() - d->streamStart;
d->properties = new Properties(infoData, streamLength); d->properties.reset(new AudioProperties(infoData, streamLength));
}
} }
void FLAC::File::scan() }
{
void FLAC::File::scan() {
// Scan the metadata pages // Scan the metadata pages
if (d->scanned) if (d->scanned)
@@ -469,7 +431,7 @@ void FLAC::File::scan()
if (!isValid()) if (!isValid())
return; return;
long nextBlockOffset; long long nextBlockOffset;
if (d->ID3v2Location >= 0) if (d->ID3v2Location >= 0)
nextBlockOffset = find("fLaC", d->ID3v2Location + d->ID3v2OriginalSize); nextBlockOffset = find("fLaC", d->ID3v2Location + d->ID3v2OriginalSize);
@@ -504,7 +466,7 @@ void FLAC::File::scan()
const char blockType = header[0] & ~LastBlockFlag; const char blockType = header[0] & ~LastBlockFlag;
const bool isLastBlock = (header[0] & LastBlockFlag) != 0; const bool isLastBlock = (header[0] & LastBlockFlag) != 0;
const unsigned int blockLength = header.toUInt(1U, 3U); const size_t blockLength = header.toUInt24BE(1);
// First block should be the stream_info metadata // First block should be the stream_info metadata
@@ -514,9 +476,7 @@ void FLAC::File::scan()
return; return;
} }
if(blockLength == 0 if (blockLength == 0 && blockType != MetadataBlock::Padding && blockType != MetadataBlock::SeekTable) {
&& blockType != MetadataBlock::Padding && blockType != MetadataBlock::SeekTable)
{
debug("FLAC::File::scan() -- Zero-sized metadata block found"); debug("FLAC::File::scan() -- Zero-sized metadata block found");
setValid(false); setValid(false);
return; return;
@@ -529,33 +489,32 @@ void FLAC::File::scan()
return; return;
} }
MetadataBlock *block = 0; std::shared_ptr<MetadataBlock> block;
// Found the vorbis-comment // Found the vorbis-comment
if (blockType == MetadataBlock::VorbisComment) { if (blockType == MetadataBlock::VorbisComment) {
if (d->xiphCommentData.isEmpty()) { if (d->xiphCommentData.isEmpty()) {
d->xiphCommentData = data; d->xiphCommentData = data;
block = new UnknownMetadataBlock(MetadataBlock::VorbisComment, data); block.reset(new UnknownMetadataBlock(MetadataBlock::VorbisComment, data));
} }
else { else {
debug("FLAC::File::scan() -- multiple Vorbis Comment blocks found, discarding"); debug("FLAC::File::scan() -- multiple Vorbis Comment blocks found, discarding");
} }
} }
else if (blockType == MetadataBlock::Picture) { else if (blockType == MetadataBlock::Picture) {
FLAC::Picture *picture = new FLAC::Picture(); std::shared_ptr<FLAC::Picture> picture(new FLAC::Picture());
if (picture->parse(data)) { if (picture->parse(data)) {
block = picture; block = picture;
} }
else { else {
debug("FLAC::File::scan() -- invalid picture found, discarding"); debug("FLAC::File::scan() -- invalid picture found, discarding");
delete picture;
} }
} }
else if (blockType == MetadataBlock::Padding) { else if (blockType == MetadataBlock::Padding) {
// Skip all padding blocks. // Skip all padding blocks.
} }
else { else {
block = new UnknownMetadataBlock(blockType, data); block.reset(new UnknownMetadataBlock(blockType, data));
} }
if (block) if (block)
@@ -572,4 +531,5 @@ void FLAC::File::scan()
d->streamStart = nextBlockOffset; d->streamStart = nextBlockOffset;
d->scanned = true; d->scanned = true;
} }

View File

@@ -26,6 +26,8 @@
#ifndef TAGLIB_FLACFILE_H #ifndef TAGLIB_FLACFILE_H
#define TAGLIB_FLACFILE_H #define TAGLIB_FLACFILE_H
#include <memory>
#include "taglib_export.h" #include "taglib_export.h"
#include "tfile.h" #include "tfile.h"
#include "tlist.h" #include "tlist.h"
@@ -38,9 +40,16 @@ namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
class Tag; class Tag;
namespace ID3v2 { class FrameFactory; class Tag; } namespace ID3v2 {
namespace ID3v1 { class Tag; } class FrameFactory;
namespace Ogg { class XiphComment; } class Tag;
} // namespace ID3v2
namespace ID3v1 {
class Tag;
}
namespace Ogg {
class XiphComment;
}
//! An implementation of FLAC metadata //! An implementation of FLAC metadata
@@ -58,14 +67,12 @@ namespace TagLib {
//! An implementation of TagLib::File with FLAC specific methods //! An implementation of TagLib::File with FLAC specific methods
/*! /*!
* This implements and provides an interface for FLAC files to the * This implements and provides an interface for FLAC files to the TagLib::Tag and TagLib::AudioProperties interfaces
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing * by way of implementing the abstract TagLib::File API as well as providing some additional information specific to FLAC files.
* the abstract TagLib::File API as well as providing some additional *
* information specific to FLAC files.
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* This set of flags is used for various operations and is suitable for * This set of flags is used for various operations and is suitable for
@@ -85,111 +92,73 @@ namespace TagLib {
}; };
/*! /*!
* Constructs a FLAC file from \a file. If \a readProperties is true the * Constructs an FLAC file from \a file.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
*
* If this file contains and ID3v2 tag the frames will be created using \a frameFactory.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*
* \deprecated This constructor will be dropped in favor of the one below
* in a future version.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average, ID3v2::FrameFactory *frameFactory = nullptr);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an FLAC file from \a file. If \a readProperties is true the * Constructs a FLAC file from \a stream. If \a readProperties is true the file's audio properties will also be read.
* file's audio properties will also be read.
* *
* If this file contains and ID3v2 tag the frames will be created using * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* \a frameFactory. *
* If this file contains and ID3v2 tag the frames will be created using \a frameFactory.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
// BIC: merge with the above constructor // BIC: merge with the above constructor
File(FileName file, ID3v2::FrameFactory *frameFactory, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average, ID3v2::FrameFactory *frameFactory = nullptr);
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
/*!
* Constructs a FLAC file from \a stream. If \a readProperties is true the
* file's audio properties will also be read.
*
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*
* If this file contains and ID3v2 tag the frames will be created using
* \a frameFactory.
*
* \note In the current implementation, \a propertiesStyle is ignored.
*/
// BIC: merge with the above constructor
File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns the Tag for this file. This will be a union of XiphComment, * Returns the Tag for this file. This will be a union of XiphComment, ID3v1 and ID3v2 tags.
* ID3v1 and ID3v2 tags.
* *
* \see ID3v2Tag() * \see ID3v2Tag()
* \see ID3v1Tag() * \see ID3v1Tag()
* \see XiphComment() * \see XiphComment()
*/ */
virtual Strawberry_TagLib::TagLib::Tag *tag() const; Strawberry_TagLib::TagLib::Tag *tag() const override;
/*!
* Implements the unified property interface -- export function.
* If the file contains more than one tag (e.g. XiphComment and ID3v1),
* only the first one (in the order XiphComment, ID3v2, ID3v1) will be
* converted to the PropertyMap.
*/
PropertyMap properties() const;
void removeUnsupportedProperties(const StringList &);
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* This always creates a Xiph comment, if none exists. The return value * This always creates a Xiph comment, if none exists. The return value relates to the Xiph comment only.
* relates to the Xiph comment only. * Ignores any changes to ID3v1 or ID3v2 comments since they are not allowed in the FLAC specification.
* Ignores any changes to ID3v1 or ID3v2 comments since they are not allowed
* in the FLAC specification.
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
/*! /*!
* Returns the FLAC::Properties for this file. If no audio properties * Returns the FLAC::AudioProperties for this file. If no audio properties were read then this will return a null pointer.
* were read then this will return a null pointer.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Save the file. This will primarily save the XiphComment, but * Save the file. This will primarily save the XiphComment, but will also keep any old ID3-tags up to date.
* will also keep any old ID3-tags up to date. If the file * If the file has no XiphComment, one will be constructed from the ID3-tags.
* has no XiphComment, one will be constructed from the ID3-tags.
* *
* This returns true if the save was successful. * This returns true if the save was successful.
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Returns a pointer to the ID3v2 tag of the file. * Returns a pointer to the ID3v2 tag of the file.
* *
* If \a create is false (the default) this returns a null pointer * If \a create is false (the default) this returns a null pointer
* if there is no valid ID3v2 tag. If \a create is true it will create * if there is no valid ID3v2 tag.
* an ID3v2 tag if one does not exist and returns a valid pointer. * If \a create is true it will create an ID3v2 tag if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an ID3v2 tag.
* file on disk has an ID3v2 tag. Use hasID3v2Tag() to check if the file * Use hasID3v2Tag() to check if the file on disk actually has an ID3v2 tag.
* on disk actually has an ID3v2 tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be
* deleted by the user. It will be deleted when the file (object) is * deleted by the user. It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasID3v2Tag() * \see hasID3v2Tag()
*/ */
@@ -198,17 +167,14 @@ namespace TagLib {
/*! /*!
* Returns a pointer to the ID3v1 tag of the file. * Returns a pointer to the ID3v1 tag of the file.
* *
* If \a create is false (the default) this returns a null pointer * If \a create is false (the default) this returns a null pointer if there is no valid APE tag.
* if there is no valid APE tag. If \a create is true it will create * If \a create is true it will create an APE tag if one does not exist and returns a valid pointer.
* an APE tag if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an ID3v1 tag.
* file on disk has an ID3v1 tag. Use hasID3v1Tag() to check if the file * Use hasID3v1Tag() to check if the file on disk actually has an ID3v1 tag.
* on disk actually has an ID3v1 tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasID3v1Tag() * \see hasID3v1Tag()
*/ */
@@ -217,58 +183,28 @@ namespace TagLib {
/*! /*!
* Returns a pointer to the XiphComment for the file. * Returns a pointer to the XiphComment for the file.
* *
* If \a create is false (the default) this returns a null pointer * If \a create is false (the default) this returns a null pointer if there is no valid XiphComment.
* if there is no valid XiphComment. If \a create is true it will create * If \a create is true it will create a XiphComment if one does not exist and returns a valid pointer.
* a XiphComment if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has a XiphComment.
* file on disk has a XiphComment. Use hasXiphComment() to check if the * Use hasXiphComment() to check if the file on disk actually has a XiphComment.
* file on disk actually has a XiphComment.
* *
* \note The Tag <b>is still</b> owned by the FLAC::File and should not be * \note The Tag <b>is still</b> owned by the FLAC::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasXiphComment() * \see hasXiphComment()
*/ */
Ogg::XiphComment *xiphComment(bool create = false); Ogg::XiphComment *xiphComment(bool create = false);
/*!
* Set the ID3v2::FrameFactory to something other than the default. This
* can be used to specify the way that ID3v2 frames will be interpreted
* when
*
* \see ID3v2FrameFactory
* \deprecated This value should be passed in via the constructor
*/
TAGLIB_DEPRECATED void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
/*!
* Returns the block of data used by FLAC::Properties for parsing the
* stream properties.
*
* \deprecated Always returns an empty vector.
*/
TAGLIB_DEPRECATED ByteVector streamInfoData(); // BIC: remove
/*!
* Returns the length of the audio-stream, used by FLAC::Properties for
* calculating the bitrate.
*
* \deprecated Always returns zero.
*/
TAGLIB_DEPRECATED long streamLength(); // BIC: remove
/*! /*!
* Returns a list of pictures attached to the FLAC file. * Returns a list of pictures attached to the FLAC file.
*/ */
List<Picture *> pictureList(); List<Picture *> pictureList();
/*! /*!
* Removes an attached picture. If \a del is true the picture's memory * Removes an attached picture. The picture's memory will be freed.
* will be freed; if it is false, it must be deleted by the user.
*/ */
void removePicture(Picture *picture, bool del = true); void removePicture(Picture *picture);
/*! /*!
* Remove all attached images. * Remove all attached images.
@@ -276,25 +212,23 @@ namespace TagLib {
void removePictures(); void removePictures();
/*! /*!
* Add a new picture to the file. The file takes ownership of the * Add a new picture to the file.
* picture and will handle freeing its memory. * The file takes ownership of the picture and will handle freeing its memory.
* *
* \note The file will be saved only after calling save(). * \note The file will be saved only after calling save().
*/ */
void addPicture(Picture *picture); void addPicture(Picture *picture);
/*! /*!
* This will remove the tags that match the OR-ed together TagTypes from * This will remove the tags that match the OR-ed together TagTypes from the file.
* the file. By default it removes all tags. * By default it removes all tags.
* *
* \warning This will also invalidate pointers to the tags as their memory * \warning This will also invalidate pointers to the tags as their memory will be freed.
* will be freed.
* *
* \note In order to make the removal permanent save() still needs to be * \note In order to make the removal permanent save() still needs to be called.
* called.
* *
* \note This won't remove the Vorbis comment block completely. The * \note This won't remove the Vorbis comment block completely.
* vendor ID will be preserved. * The vendor ID will be preserved.
*/ */
void strip(int tags = AllTags); void strip(int tags = AllTags);
@@ -320,11 +254,10 @@ namespace TagLib {
bool hasID3v2Tag() const; bool hasID3v2Tag() const;
/*! /*!
* Returns whether or not the given \a stream can be opened as a FLAC * Returns whether or not the given \a stream can be opened as a FLAC file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check.
* not necessarily be correct. * The result may not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -338,8 +271,8 @@ namespace TagLib {
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace FLAC
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,25 +23,17 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include "taglib.h"
#include <tdebug.h> #include "tdebug.h"
#include "flacmetadatablock.h" #include "flacmetadatablock.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class FLAC::MetadataBlock::MetadataBlockPrivate class FLAC::MetadataBlock::MetadataBlockPrivate {
{
public: public:
MetadataBlockPrivate() {} MetadataBlockPrivate() {}
}; };
FLAC::MetadataBlock::MetadataBlock() FLAC::MetadataBlock::MetadataBlock() : d(nullptr) {}
{
d = 0;
}
FLAC::MetadataBlock::~MetadataBlock()
{
}
FLAC::MetadataBlock::~MetadataBlock() {}

View File

@@ -32,13 +32,11 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace FLAC { namespace FLAC {
class TAGLIB_EXPORT MetadataBlock class TAGLIB_EXPORT MetadataBlock {
{
public: public:
MetadataBlock(); explicit MetadataBlock();
virtual ~MetadataBlock(); virtual ~MetadataBlock();
enum BlockType { enum BlockType {
@@ -69,9 +67,8 @@ namespace TagLib {
MetadataBlockPrivate *d; MetadataBlockPrivate *d;
}; };
} } // namespace FLAC
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,22 +23,20 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include "taglib.h"
#include <tdebug.h> #include "tdebug.h"
#include "flacpicture.h" #include "flacpicture.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class FLAC::Picture::PicturePrivate class FLAC::Picture::PicturePrivate {
{
public: public:
PicturePrivate() : explicit PicturePrivate() : type(FLAC::Picture::Other),
type(FLAC::Picture::Other),
width(0), width(0),
height(0), height(0),
colorDepth(0), colorDepth(0),
numColors(0) numColors(0) {
{} }
Type type; Type type;
String mimeType; String mimeType;
@@ -50,38 +48,32 @@ public:
ByteVector data; ByteVector data;
}; };
FLAC::Picture::Picture() : FLAC::Picture::Picture() : d(new PicturePrivate()) {
d(new PicturePrivate())
{
} }
FLAC::Picture::Picture(const ByteVector &data) : FLAC::Picture::Picture(const ByteVector &data) : d(new PicturePrivate()) {
d(new PicturePrivate())
{
parse(data); parse(data);
} }
FLAC::Picture::~Picture() FLAC::Picture::~Picture() {
{
delete d; delete d;
} }
int FLAC::Picture::code() const int FLAC::Picture::code() const {
{
return FLAC::MetadataBlock::Picture; return FLAC::MetadataBlock::Picture;
} }
bool FLAC::Picture::parse(const ByteVector &data) bool FLAC::Picture::parse(const ByteVector &data) {
{
if (data.size() < 32) { if (data.size() < 32) {
debug("A picture block must contain at least 5 bytes."); debug("A picture block must contain at least 5 bytes.");
return false; return false;
} }
unsigned int pos = 0; size_t pos = 0;
d->type = FLAC::Picture::Type(data.toUInt(pos)); d->type = FLAC::Picture::Type(data.toUInt32BE(pos));
pos += 4; pos += 4;
unsigned int mimeTypeLength = data.toUInt(pos); const unsigned int mimeTypeLength = data.toUInt32BE(pos);
pos += 4; pos += 4;
if (pos + mimeTypeLength + 24 > data.size()) { if (pos + mimeTypeLength + 24 > data.size()) {
debug("Invalid picture block."); debug("Invalid picture block.");
@@ -89,7 +81,7 @@ bool FLAC::Picture::parse(const ByteVector &data)
} }
d->mimeType = String(data.mid(pos, mimeTypeLength), String::UTF8); d->mimeType = String(data.mid(pos, mimeTypeLength), String::UTF8);
pos += mimeTypeLength; pos += mimeTypeLength;
unsigned int descriptionLength = data.toUInt(pos); const unsigned int descriptionLength = data.toUInt32BE(pos);
pos += 4; pos += 4;
if (pos + descriptionLength + 20 > data.size()) { if (pos + descriptionLength + 20 > data.size()) {
debug("Invalid picture block."); debug("Invalid picture block.");
@@ -97,15 +89,15 @@ bool FLAC::Picture::parse(const ByteVector &data)
} }
d->description = String(data.mid(pos, descriptionLength), String::UTF8); d->description = String(data.mid(pos, descriptionLength), String::UTF8);
pos += descriptionLength; pos += descriptionLength;
d->width = data.toUInt(pos); d->width = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->height = data.toUInt(pos); d->height = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->colorDepth = data.toUInt(pos); d->colorDepth = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->numColors = data.toUInt(pos); d->numColors = data.toUInt32BE(pos);
pos += 4; pos += 4;
unsigned int dataLength = data.toUInt(pos); const unsigned int dataLength = data.toUInt32BE(pos);
pos += 4; pos += 4;
if (pos + dataLength > data.size()) { if (pos + dataLength > data.size()) {
debug("Invalid picture block."); debug("Invalid picture block.");
@@ -114,104 +106,89 @@ bool FLAC::Picture::parse(const ByteVector &data)
d->data = data.mid(pos, dataLength); d->data = data.mid(pos, dataLength);
return true; return true;
} }
ByteVector FLAC::Picture::render() const ByteVector FLAC::Picture::render() const {
{
ByteVector result; ByteVector result;
result.append(ByteVector::fromUInt(d->type)); result.append(ByteVector::fromUInt32BE(d->type));
ByteVector mimeTypeData = d->mimeType.data(String::UTF8); ByteVector mimeTypeData = d->mimeType.data(String::UTF8);
result.append(ByteVector::fromUInt(mimeTypeData.size())); result.append(ByteVector::fromUInt32BE(mimeTypeData.size()));
result.append(mimeTypeData); result.append(mimeTypeData);
ByteVector descriptionData = d->description.data(String::UTF8); ByteVector descriptionData = d->description.data(String::UTF8);
result.append(ByteVector::fromUInt(descriptionData.size())); result.append(ByteVector::fromUInt32BE(descriptionData.size()));
result.append(descriptionData); result.append(descriptionData);
result.append(ByteVector::fromUInt(d->width)); result.append(ByteVector::fromUInt32BE(d->width));
result.append(ByteVector::fromUInt(d->height)); result.append(ByteVector::fromUInt32BE(d->height));
result.append(ByteVector::fromUInt(d->colorDepth)); result.append(ByteVector::fromUInt32BE(d->colorDepth));
result.append(ByteVector::fromUInt(d->numColors)); result.append(ByteVector::fromUInt32BE(d->numColors));
result.append(ByteVector::fromUInt(d->data.size())); result.append(ByteVector::fromUInt32BE(d->data.size()));
result.append(d->data); result.append(d->data);
return result; return result;
} }
FLAC::Picture::Type FLAC::Picture::type() const FLAC::Picture::Type FLAC::Picture::type() const {
{
return d->type; return d->type;
} }
void FLAC::Picture::setType(FLAC::Picture::Type type) void FLAC::Picture::setType(FLAC::Picture::Type type) {
{
d->type = type; d->type = type;
} }
String FLAC::Picture::mimeType() const String FLAC::Picture::mimeType() const {
{
return d->mimeType; return d->mimeType;
} }
void FLAC::Picture::setMimeType(const String &mimeType) void FLAC::Picture::setMimeType(const String &mimeType) {
{
d->mimeType = mimeType; d->mimeType = mimeType;
} }
String FLAC::Picture::description() const String FLAC::Picture::description() const {
{
return d->description; return d->description;
} }
void FLAC::Picture::setDescription(const String &description) void FLAC::Picture::setDescription(const String &description) {
{
d->description = description; d->description = description;
} }
int FLAC::Picture::width() const int FLAC::Picture::width() const {
{
return d->width; return d->width;
} }
void FLAC::Picture::setWidth(int width) void FLAC::Picture::setWidth(int width) {
{
d->width = width; d->width = width;
} }
int FLAC::Picture::height() const int FLAC::Picture::height() const {
{
return d->height; return d->height;
} }
void FLAC::Picture::setHeight(int height) void FLAC::Picture::setHeight(int height) {
{
d->height = height; d->height = height;
} }
int FLAC::Picture::colorDepth() const int FLAC::Picture::colorDepth() const {
{
return d->colorDepth; return d->colorDepth;
} }
void FLAC::Picture::setColorDepth(int colorDepth) void FLAC::Picture::setColorDepth(int colorDepth) {
{
d->colorDepth = colorDepth; d->colorDepth = colorDepth;
} }
int FLAC::Picture::numColors() const int FLAC::Picture::numColors() const {
{
return d->numColors; return d->numColors;
} }
void FLAC::Picture::setNumColors(int numColors) void FLAC::Picture::setNumColors(int numColors) {
{
d->numColors = numColors; d->numColors = numColors;
} }
ByteVector FLAC::Picture::data() const ByteVector FLAC::Picture::data() const {
{
return d->data; return d->data;
} }
void FLAC::Picture::setData(const ByteVector &data) void FLAC::Picture::setData(const ByteVector &data) {
{
d->data = data; d->data = data;
} }

View File

@@ -37,10 +37,8 @@ namespace TagLib {
namespace FLAC { namespace FLAC {
class TAGLIB_EXPORT Picture : public MetadataBlock class TAGLIB_EXPORT Picture : public MetadataBlock {
{
public: public:
/*! /*!
* This describes the function or content of the picture. * This describes the function or content of the picture.
*/ */
@@ -89,9 +87,9 @@ namespace TagLib {
PublisherLogo = 0x14 PublisherLogo = 0x14
}; };
Picture(); explicit Picture();
Picture(const ByteVector &data); explicit Picture(const ByteVector &data);
~Picture(); ~Picture() override;
/*! /*!
* Returns the type of the image. * Returns the type of the image.
@@ -104,14 +102,12 @@ namespace TagLib {
void setType(Type type); void setType(Type type);
/*! /*!
* Returns the mime type of the image. This should in most cases be * Returns the mime type of the image. This should in most cases be "image/png" or "image/jpeg".
* "image/png" or "image/jpeg".
*/ */
String mimeType() const; String mimeType() const;
/*! /*!
* Sets the mime type of the image. This should in most cases be * Sets the mime type of the image. This should in most cases be "image/png" or "image/jpeg".
* "image/png" or "image/jpeg".
*/ */
void setMimeType(const String &m); void setMimeType(const String &m);
@@ -180,12 +176,12 @@ namespace TagLib {
/*! /*!
* Returns the FLAC metadata block type. * Returns the FLAC metadata block type.
*/ */
int code() const; int code() const override;
/*! /*!
* Render the content to the FLAC picture block format. * Render the content to the FLAC picture block format.
*/ */
ByteVector render() const; ByteVector render() const override;
/*! /*!
* Parse the picture data in the FLAC picture block format. * Parse the picture data in the FLAC picture block format.
@@ -200,11 +196,8 @@ namespace TagLib {
PicturePrivate *d; PicturePrivate *d;
}; };
typedef List<Picture> PictureList; } // namespace FLAC
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
}
#endif #endif

View File

@@ -23,19 +23,17 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tstring.h> #include "tstring.h"
#include <tdebug.h> #include "tdebug.h"
#include "flacproperties.h" #include "flacproperties.h"
#include "flacfile.h" #include "flacfile.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class FLAC::Properties::PropertiesPrivate class FLAC::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : length(0),
length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
bitsPerSample(0), bitsPerSample(0),
@@ -55,72 +53,43 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : FLAC::AudioProperties::AudioProperties(const ByteVector &data, long long streamLength, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
AudioProperties(style),
d(new PropertiesPrivate())
{
read(data, streamLength); read(data, streamLength);
} }
FLAC::Properties::Properties(File *, ReadStyle style) : FLAC::AudioProperties::~AudioProperties() {
AudioProperties(style),
d(new PropertiesPrivate())
{
debug("FLAC::Properties::Properties() - This constructor is no longer used.");
}
FLAC::Properties::~Properties()
{
delete d; delete d;
} }
int FLAC::Properties::length() const int FLAC::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int FLAC::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int FLAC::Properties::lengthInMilliseconds() const int FLAC::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int FLAC::Properties::bitrate() const int FLAC::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int FLAC::Properties::sampleRate() const int FLAC::AudioProperties::sampleRate() const {
{
return d->sampleRate; return d->sampleRate;
} }
int FLAC::Properties::bitsPerSample() const int FLAC::AudioProperties::bitsPerSample() const {
{
return d->bitsPerSample; return d->bitsPerSample;
} }
int FLAC::Properties::sampleWidth() const int FLAC::AudioProperties::channels() const {
{
return bitsPerSample();
}
int FLAC::Properties::channels() const
{
return d->channels; return d->channels;
} }
unsigned long long FLAC::Properties::sampleFrames() const unsigned long long FLAC::AudioProperties::sampleFrames() const {
{
return d->sampleFrames; return d->sampleFrames;
} }
ByteVector FLAC::Properties::signature() const ByteVector FLAC::AudioProperties::signature() const {
{
return d->signature; return d->signature;
} }
@@ -128,14 +97,14 @@ ByteVector FLAC::Properties::signature() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void FLAC::Properties::read(const ByteVector &data, long streamLength) void FLAC::AudioProperties::read(const ByteVector &data, long long streamLength) {
{
if (data.size() < 18) { if (data.size() < 18) {
debug("FLAC::Properties::read() - FLAC properties must contain at least 18 bytes."); debug("FLAC::AudioProperties::read() - FLAC properties must contain at least 18 bytes.");
return; return;
} }
unsigned int pos = 0; size_t pos = 0;
// Minimum block size (in samples) // Minimum block size (in samples)
pos += 2; pos += 2;
@@ -149,7 +118,7 @@ void FLAC::Properties::read(const ByteVector &data, long streamLength)
// Maximum frame size (in bytes) // Maximum frame size (in bytes)
pos += 3; pos += 3;
const unsigned int flags = data.toUInt(pos, true); const unsigned int flags = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->sampleRate = flags >> 12; d->sampleRate = flags >> 12;
@@ -160,7 +129,7 @@ void FLAC::Properties::read(const ByteVector &data, long streamLength)
// stream length in samples. (Audio files measured in days) // stream length in samples. (Audio files measured in days)
const unsigned long long hi = flags & 0xf; const unsigned long long hi = flags & 0xf;
const unsigned long long lo = data.toUInt(pos, true); const unsigned long long lo = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->sampleFrames = (hi << 32) | lo; d->sampleFrames = (hi << 32) | lo;
@@ -173,4 +142,5 @@ void FLAC::Properties::read(const ByteVector &data, long streamLength)
if (data.size() >= pos + 16) if (data.size() >= pos + 16)
d->signature = data.mid(pos, 16); d->signature = data.mid(pos, 16);
} }

View File

@@ -39,112 +39,73 @@ namespace TagLib {
//! An implementation of audio property reading for FLAC //! An implementation of audio property reading for FLAC
/*! /*!
* This reads the data from an FLAC stream found in the AudioProperties * This reads the data from an FLAC stream found in the AudioProperties API.
* API.
*/ */
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
/*! /*!
* Create an instance of FLAC::Properties with the data read from the * Create an instance of FLAC::AudioProperties with the data read from the ByteVector \a data.
* ByteVector \a data.
*/ */
// BIC: switch to const reference explicit AudioProperties(const ByteVector &data, long long streamLength, ReadStyle style = Average);
Properties(ByteVector data, long streamLength, ReadStyle style = Average);
/*! /*!
* Create an instance of FLAC::Properties with the data read from the * Destroys this FLAC::AudioProperties instance.
* FLAC::File \a file.
*/ */
// BIC: remove ~AudioProperties() override;
Properties(File *file, ReadStyle style = Average);
/*! /*!
* Destroys this FLAC::Properties instance. * Returns the length of the file in seconds. The length is rounded down to the nearest whole second.
*/
virtual ~Properties();
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual int lengthInSeconds() const override;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual int lengthInMilliseconds() const override;
int lengthInMilliseconds() const;
/*! /*!
* Returns the average bit rate of the file in kb/s. * Returns the average bit rate of the file in kb/s.
*/ */
virtual int bitrate() const; int bitrate() const override;
/*! /*!
* Returns the sample rate in Hz. * Returns the sample rate in Hz.
*/ */
virtual int sampleRate() const; int sampleRate() const override;
/*! /*!
* Returns the number of audio channels. * Returns the number of audio channels.
*/ */
virtual int channels() const; int channels() const override;
/*! /*!
* Returns the number of bits per audio sample as read from the FLAC * Returns the number of bits per audio sample as read from the FLAC identification header.
* identification header.
*/ */
int bitsPerSample() const; int bitsPerSample() const;
/*!
* Returns the sample width as read from the FLAC identification
* header.
*
* \note This method is just an alias of bitsPerSample().
*
* \deprecated
*/
TAGLIB_DEPRECATED int sampleWidth() const;
/*! /*!
* Return the number of sample frames. * Return the number of sample frames.
*/ */
unsigned long long sampleFrames() const; unsigned long long sampleFrames() const;
/*! /*!
* Returns the MD5 signature of the uncompressed audio stream as read * Returns the MD5 signature of the uncompressed audio stream as read from the stream info header.
* from the stream info header.
*/ */
ByteVector signature() const; ByteVector signature() const;
private: private:
Properties(const Properties &); void read(const ByteVector &data, long long streamLength);
Properties &operator=(const Properties &);
void read(const ByteVector &data, long streamLength); class AudioPropertiesPrivate;
AudioPropertiesPrivate *d;
class PropertiesPrivate;
PropertiesPrivate *d;
}; };
} } // namespace FLAC
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,56 +23,46 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include "taglib.h"
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include "flacunknownmetadatablock.h" #include "flacunknownmetadatablock.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class FLAC::UnknownMetadataBlock::UnknownMetadataBlockPrivate class FLAC::UnknownMetadataBlock::UnknownMetadataBlockPrivate {
{
public: public:
UnknownMetadataBlockPrivate() : code(0) {} explicit UnknownMetadataBlockPrivate() : code(0) {}
int code; int code;
ByteVector data; ByteVector data;
}; };
FLAC::UnknownMetadataBlock::UnknownMetadataBlock(int code, const ByteVector &data) : FLAC::UnknownMetadataBlock::UnknownMetadataBlock(int code, const ByteVector &data) : d(new UnknownMetadataBlockPrivate()) {
d(new UnknownMetadataBlockPrivate())
{
d->code = code; d->code = code;
d->data = data; d->data = data;
} }
FLAC::UnknownMetadataBlock::~UnknownMetadataBlock() FLAC::UnknownMetadataBlock::~UnknownMetadataBlock() {
{
delete d; delete d;
} }
int FLAC::UnknownMetadataBlock::code() const int FLAC::UnknownMetadataBlock::code() const {
{
return d->code; return d->code;
} }
void FLAC::UnknownMetadataBlock::setCode(int code) void FLAC::UnknownMetadataBlock::setCode(int code) {
{
d->code = code; d->code = code;
} }
ByteVector FLAC::UnknownMetadataBlock::data() const ByteVector FLAC::UnknownMetadataBlock::data() const {
{
return d->data; return d->data;
} }
void FLAC::UnknownMetadataBlock::setData(const ByteVector &data) void FLAC::UnknownMetadataBlock::setData(const ByteVector &data) {
{
d->data = data; d->data = data;
} }
ByteVector FLAC::UnknownMetadataBlock::render() const ByteVector FLAC::UnknownMetadataBlock::render() const {
{
return d->data; return d->data;
} }

View File

@@ -33,19 +33,17 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace FLAC { namespace FLAC {
class TAGLIB_EXPORT UnknownMetadataBlock : public MetadataBlock class TAGLIB_EXPORT UnknownMetadataBlock : public MetadataBlock {
{
public: public:
UnknownMetadataBlock(int blockType, const ByteVector &data); explicit UnknownMetadataBlock(int code, const ByteVector &data);
~UnknownMetadataBlock(); ~UnknownMetadataBlock() override;
/*! /*!
* Returns the FLAC metadata block type. * Returns the FLAC metadata block type.
*/ */
int code() const; int code() const override;
/*! /*!
* Sets the FLAC metadata block type. * Sets the FLAC metadata block type.
@@ -65,19 +63,18 @@ namespace TagLib {
/*! /*!
* Render the content of the block. * Render the content of the block.
*/ */
ByteVector render() const; ByteVector render() const override;
private: private:
UnknownMetadataBlock(const MetadataBlock &item); explicit UnknownMetadataBlock(const MetadataBlock &item);
UnknownMetadataBlock &operator=(const MetadataBlock &item); UnknownMetadataBlock &operator=(const MetadataBlock &item);
class UnknownMetadataBlockPrivate; class UnknownMetadataBlockPrivate;
UnknownMetadataBlockPrivate *d; UnknownMetadataBlockPrivate *d;
}; };
} } // namespace FLAC
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -33,65 +33,43 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace IT; using namespace IT;
class IT::File::FilePrivate class IT::File::FilePrivate {
{
public: public:
explicit FilePrivate(AudioProperties::ReadStyle propertiesStyle) explicit FilePrivate(AudioProperties::ReadStyle propertiesStyle) : properties(propertiesStyle) {}
: tag(), properties(propertiesStyle)
{
}
Mod::Tag tag; Mod::Tag tag;
IT::Properties properties; IT::AudioProperties properties;
}; };
IT::File::File(FileName file, bool readProperties, IT::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(file), d(new FilePrivate(propertiesStyle)) {
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(file),
d(new FilePrivate(propertiesStyle))
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
IT::File::File(IOStream *stream, bool readProperties, IT::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(stream), d(new FilePrivate(propertiesStyle)) {
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(stream),
d(new FilePrivate(propertiesStyle))
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
IT::File::~File() IT::File::~File() {
{
delete d; delete d;
} }
Mod::Tag *IT::File::tag() const Mod::Tag *IT::File::tag() const {
{
return &d->tag; return &d->tag;
} }
PropertyMap IT::File::properties() const IT::AudioProperties *IT::File::audioProperties() const {
{
return d->tag.properties();
}
PropertyMap IT::File::setProperties(const PropertyMap &properties)
{
return d->tag.setProperties(properties);
}
IT::Properties *IT::File::audioProperties() const
{
return &d->properties; return &d->properties;
} }
bool IT::File::save() bool IT::File::save() {
{
if(readOnly()) if (readOnly()) {
{
debug("IT::File::save() - Cannot save to a read only file."); debug("IT::File::save() - Cannot save to a read only file.");
return false; return false;
} }
@@ -113,8 +91,8 @@ bool IT::File::save()
// write comment as instrument and sample names: // write comment as instrument and sample names:
StringList lines = d->tag.comment().split("\n"); StringList lines = d->tag.comment().split("\n");
for (unsigned short i = 0; i < instrumentCount; ++i) { for (unsigned short i = 0; i < instrumentCount; ++i) {
seek(192L + length + ((long)i << 2)); seek(192L + length + (static_cast<long>(i) << 2));
unsigned long instrumentOffset = 0; unsigned int instrumentOffset = 0;
if (!readU32L(instrumentOffset)) if (!readU32L(instrumentOffset))
return false; return false;
@@ -128,14 +106,14 @@ bool IT::File::save()
} }
for (unsigned short i = 0; i < sampleCount; ++i) { for (unsigned short i = 0; i < sampleCount; ++i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2)); seek(192L + length + (static_cast<long>(instrumentCount) << 2) + (static_cast<long>(i) << 2));
unsigned long sampleOffset = 0; unsigned int sampleOffset = 0;
if (!readU32L(sampleOffset)) if (!readU32L(sampleOffset))
return false; return false;
seek(sampleOffset + 20); seek(sampleOffset + 20);
if((unsigned int)(i + instrumentCount) < lines.size()) if (static_cast<unsigned int>(i + instrumentCount) < lines.size())
writeString(lines[i + instrumentCount], 25); writeString(lines[i + instrumentCount], 25);
else else
writeString(String(), 25); writeString(String(), 25);
@@ -152,18 +130,18 @@ bool IT::File::save()
// terminating NUL but it does not hurt to add one: // terminating NUL but it does not hurt to add one:
if (message.size() > 7999) if (message.size() > 7999)
message.resize(7999); message.resize(7999);
message.append((char)0); message.append(static_cast<char>(0));
unsigned short special = 0; unsigned short special = 0;
unsigned short messageLength = 0; unsigned short messageLength = 0;
unsigned long messageOffset = 0; unsigned int messageOffset = 0;
seek(46); seek(46);
if (!readU16L(special)) if (!readU16L(special))
return false; return false;
unsigned long fileSize = File::length(); unsigned int fileSize = File::length();
if(special & Properties::MessageAttached) { if (special & AudioProperties::MessageAttached) {
seek(54); seek(54);
if (!readU16L(messageLength) || !readU32L(messageOffset)) if (!readU16L(messageLength) || !readU32L(messageOffset))
return false; return false;
@@ -171,8 +149,7 @@ bool IT::File::save()
if (messageLength == 0) if (messageLength == 0)
messageOffset = fileSize; messageOffset = fileSize;
} }
else else {
{
messageOffset = fileSize; messageOffset = fileSize;
seek(46); seek(46);
writeU16L(special | 0x1); writeU16L(special | 0x1);
@@ -199,8 +176,7 @@ bool IT::File::save()
return true; return true;
} }
void IT::File::read(bool) void IT::File::read(bool) {
{
if (!isOpen()) if (!isOpen())
return; return;
@@ -233,14 +209,14 @@ void IT::File::read(bool)
// sample/instrument names are abused as comments so // sample/instrument names are abused as comments so
// I just add all together. // I just add all together.
String message; String message;
if(special & Properties::MessageAttached) { if (special & AudioProperties::MessageAttached) {
READ_U16L_AS(messageLength); READ_U16L_AS(messageLength);
READ_U32L_AS(messageOffset); READ_U32L_AS(messageOffset);
seek(messageOffset); seek(messageOffset);
ByteVector messageBytes = readBlock(messageLength); ByteVector messageBytes = readBlock(messageLength);
READ_ASSERT(messageBytes.size() == messageLength); READ_ASSERT(messageBytes.size() == messageLength);
int index = messageBytes.find((char) 0); const size_t index = messageBytes.find(static_cast<char>(0));
if(index > -1) if (index != ByteVector::npos())
messageBytes.resize(index, 0); messageBytes.resize(index, 0);
messageBytes.replace('\r', '\n'); messageBytes.replace('\r', '\n');
message = messageBytes; message = messageBytes;
@@ -258,7 +234,7 @@ void IT::File::read(bool)
// But this always gives 64 channels for all my files anyway. // But this always gives 64 channels for all my files anyway.
// Strangely VLC does report other values. I wonder how VLC // Strangely VLC does report other values. I wonder how VLC
// gets it's values. // gets it's values.
if((unsigned char) pannings[i] < 128 && volumes[i] > 0) if (static_cast<unsigned char>(pannings[i]) < 128 && volumes[i] > 0)
++channels; ++channels;
} }
d->properties.setChannels(channels); d->properties.setChannels(channels);
@@ -280,7 +256,7 @@ void IT::File::read(bool)
// e.g. VLC seems to interpret a nil as a space. I // e.g. VLC seems to interpret a nil as a space. I
// don't know what is the proper behaviour. // don't know what is the proper behaviour.
for (unsigned short i = 0; i < instrumentCount; ++i) { for (unsigned short i = 0; i < instrumentCount; ++i) {
seek(192L + length + ((long)i << 2)); seek(192L + length + (static_cast<long>(i) << 2));
READ_U32L_AS(instrumentOffset); READ_U32L_AS(instrumentOffset);
seek(instrumentOffset); seek(instrumentOffset);
@@ -296,7 +272,7 @@ void IT::File::read(bool)
} }
for (unsigned short i = 0; i < sampleCount; ++i) { for (unsigned short i = 0; i < sampleCount; ++i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2)); seek(192L + length + (static_cast<long>(instrumentCount) << 2) + (static_cast<long>(i) << 2));
READ_U32L_AS(sampleOffset); READ_U32L_AS(sampleOffset);
seek(sampleOffset); seek(sampleOffset);
@@ -332,4 +308,5 @@ void IT::File::read(bool)
comment.append(message); comment.append(message);
d->tag.setComment(comment.toString("\n")); d->tag.setComment(comment.toString("\n"));
d->tag.setTrackerName("Impulse Tracker"); d->tag.setTrackerName("Impulse Tracker");
} }

View File

@@ -31,7 +31,6 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace IT { namespace IT {
class TAGLIB_EXPORT File : public Mod::FileBase { class TAGLIB_EXPORT File : public Mod::FileBase {
@@ -39,52 +38,33 @@ namespace TagLib {
/*! /*!
* Constructs a Impulse Tracker file from \a file. * Constructs a Impulse Tracker file from \a file.
* *
* \note In the current implementation, both \a readProperties and * \note In the current implementation, both \a readProperties and \a propertiesStyle are ignored.
* \a propertiesStyle are ignored. The audio properties are always * The audio properties are always read.
* read.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*! /*!
* Constructs a Impulse Tracker file from \a stream. * Constructs a Impulse Tracker file from \a stream.
* *
* \note In the current implementation, both \a readProperties and * \note In the current implementation, both \a readProperties and \a propertiesStyle are ignored.
* \a propertiesStyle are ignored. The audio properties are always * The audio properties are always read.
* read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* responsible for deleting it after the File object.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
Mod::Tag *tag() const; Mod::Tag *tag() const override;
/*! /*!
* Forwards to Mod::Tag::properties(). * Returns the IT::AudioProperties for this file. If no audio properties
* BIC: will be removed once File::toDict() is made virtual
*/
PropertyMap properties() const;
/*!
* Forwards to Mod::Tag::setProperties().
* BIC: will be removed once File::setProperties() is made virtual
*/
PropertyMap setProperties(const PropertyMap &);
/*!
* Returns the IT::Properties for this file. If no audio properties
* were read then this will return a null pointer. * were read then this will return a null pointer.
*/ */
IT::Properties *audioProperties() const; IT::AudioProperties *audioProperties() const override;
/*! /*!
* Save the file. * Save the file.
@@ -92,8 +72,7 @@ namespace TagLib {
* *
* \note Saving Impulse Tracker tags is not supported. * \note Saving Impulse Tracker tags is not supported.
*/ */
bool save(); bool save() override;
private: private:
File(const File&); File(const File&);
@@ -104,8 +83,9 @@ namespace TagLib {
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
}
} } // namespace IT
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

View File

@@ -29,11 +29,9 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace IT; using namespace IT;
class IT::Properties::PropertiesPrivate class IT::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : channels(0),
channels(0),
lengthInPatterns(0), lengthInPatterns(0),
instrumentCount(0), instrumentCount(0),
sampleCount(0), sampleCount(0),
@@ -47,8 +45,7 @@ public:
tempo(0), tempo(0),
bpmSpeed(0), bpmSpeed(0),
panningSeparation(0), panningSeparation(0),
pitchWheelDepth(0) pitchWheelDepth(0) {
{
} }
int channels; int channels;
@@ -68,193 +65,152 @@ public:
unsigned char pitchWheelDepth; unsigned char pitchWheelDepth;
}; };
IT::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) : IT::AudioProperties::AudioProperties(AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {}
AudioProperties(propertiesStyle),
d(new PropertiesPrivate())
{
}
IT::Properties::~Properties() IT::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int IT::Properties::length() const int IT::AudioProperties::lengthInSeconds() const {
{
return 0; return 0;
} }
int IT::Properties::lengthInSeconds() const int IT::AudioProperties::lengthInMilliseconds() const {
{
return 0; return 0;
} }
int IT::Properties::lengthInMilliseconds() const int IT::AudioProperties::bitrate() const {
{
return 0; return 0;
} }
int IT::Properties::bitrate() const int IT::AudioProperties::sampleRate() const {
{
return 0; return 0;
} }
int IT::Properties::sampleRate() const int IT::AudioProperties::channels() const {
{
return 0;
}
int IT::Properties::channels() const
{
return d->channels; return d->channels;
} }
unsigned short IT::Properties::lengthInPatterns() const unsigned short IT::AudioProperties::lengthInPatterns() const {
{
return d->lengthInPatterns; return d->lengthInPatterns;
} }
bool IT::Properties::stereo() const bool IT::AudioProperties::stereo() const {
{
return d->flags & Stereo; return d->flags & Stereo;
} }
unsigned short IT::Properties::instrumentCount() const unsigned short IT::AudioProperties::instrumentCount() const {
{
return d->instrumentCount; return d->instrumentCount;
} }
unsigned short IT::Properties::sampleCount() const unsigned short IT::AudioProperties::sampleCount() const {
{
return d->sampleCount; return d->sampleCount;
} }
unsigned short IT::Properties::patternCount() const unsigned short IT::AudioProperties::patternCount() const {
{
return d->patternCount; return d->patternCount;
} }
unsigned short IT::Properties::version() const unsigned short IT::AudioProperties::version() const {
{
return d->version; return d->version;
} }
unsigned short IT::Properties::compatibleVersion() const unsigned short IT::AudioProperties::compatibleVersion() const {
{
return d->compatibleVersion; return d->compatibleVersion;
} }
unsigned short IT::Properties::flags() const unsigned short IT::AudioProperties::flags() const {
{
return d->flags; return d->flags;
} }
unsigned short IT::Properties::special() const unsigned short IT::AudioProperties::special() const {
{
return d->special; return d->special;
} }
unsigned char IT::Properties::globalVolume() const unsigned char IT::AudioProperties::globalVolume() const {
{
return d->globalVolume; return d->globalVolume;
} }
unsigned char IT::Properties::mixVolume() const unsigned char IT::AudioProperties::mixVolume() const {
{
return d->mixVolume; return d->mixVolume;
} }
unsigned char IT::Properties::tempo() const unsigned char IT::AudioProperties::tempo() const {
{
return d->tempo; return d->tempo;
} }
unsigned char IT::Properties::bpmSpeed() const unsigned char IT::AudioProperties::bpmSpeed() const {
{
return d->bpmSpeed; return d->bpmSpeed;
} }
unsigned char IT::Properties::panningSeparation() const unsigned char IT::AudioProperties::panningSeparation() const {
{
return d->panningSeparation; return d->panningSeparation;
} }
unsigned char IT::Properties::pitchWheelDepth() const unsigned char IT::AudioProperties::pitchWheelDepth() const {
{
return d->pitchWheelDepth; return d->pitchWheelDepth;
} }
void IT::Properties::setChannels(int channels) ////////////////////////////////////////////////////////////////////////////////
{ // private members
////////////////////////////////////////////////////////////////////////////////
void IT::AudioProperties::setChannels(int channels) {
d->channels = channels; d->channels = channels;
} }
void IT::Properties::setLengthInPatterns(unsigned short lengthInPatterns) void IT::AudioProperties::setLengthInPatterns(unsigned short lengthInPatterns) {
{
d->lengthInPatterns = lengthInPatterns; d->lengthInPatterns = lengthInPatterns;
} }
void IT::Properties::setInstrumentCount(unsigned short instrumentCount) void IT::AudioProperties::setInstrumentCount(unsigned short instrumentCount) {
{
d->instrumentCount = instrumentCount; d->instrumentCount = instrumentCount;
} }
void IT::Properties::setSampleCount(unsigned short sampleCount) void IT::AudioProperties::setSampleCount(unsigned short sampleCount) {
{
d->sampleCount = sampleCount; d->sampleCount = sampleCount;
} }
void IT::Properties::setPatternCount(unsigned short patternCount) void IT::AudioProperties::setPatternCount(unsigned short patternCount) {
{
d->patternCount = patternCount; d->patternCount = patternCount;
} }
void IT::Properties::setFlags(unsigned short flags) void IT::AudioProperties::setFlags(unsigned short flags) {
{
d->flags = flags; d->flags = flags;
} }
void IT::Properties::setSpecial(unsigned short special) void IT::AudioProperties::setSpecial(unsigned short special) {
{
d->special = special; d->special = special;
} }
void IT::Properties::setCompatibleVersion(unsigned short compatibleVersion) void IT::AudioProperties::setCompatibleVersion(unsigned short compatibleVersion) {
{
d->compatibleVersion = compatibleVersion; d->compatibleVersion = compatibleVersion;
} }
void IT::Properties::setVersion(unsigned short version) void IT::AudioProperties::setVersion(unsigned short version) {
{
d->version = version; d->version = version;
} }
void IT::Properties::setGlobalVolume(unsigned char globalVolume) void IT::AudioProperties::setGlobalVolume(unsigned char globalVolume) {
{
d->globalVolume = globalVolume; d->globalVolume = globalVolume;
} }
void IT::Properties::setMixVolume(unsigned char mixVolume) void IT::AudioProperties::setMixVolume(unsigned char mixVolume) {
{
d->mixVolume = mixVolume; d->mixVolume = mixVolume;
} }
void IT::Properties::setTempo(unsigned char tempo) void IT::AudioProperties::setTempo(unsigned char tempo) {
{
d->tempo = tempo; d->tempo = tempo;
} }
void IT::Properties::setBpmSpeed(unsigned char bpmSpeed) void IT::AudioProperties::setBpmSpeed(unsigned char bpmSpeed) {
{
d->bpmSpeed = bpmSpeed; d->bpmSpeed = bpmSpeed;
} }
void IT::Properties::setPanningSeparation(unsigned char panningSeparation) void IT::AudioProperties::setPanningSeparation(unsigned char panningSeparation) {
{
d->panningSeparation = panningSeparation; d->panningSeparation = panningSeparation;
} }
void IT::Properties::setPitchWheelDepth(unsigned char pitchWheelDepth) void IT::AudioProperties::setPitchWheelDepth(unsigned char pitchWheelDepth) {
{
d->pitchWheelDepth = pitchWheelDepth; d->pitchWheelDepth = pitchWheelDepth;
} }

View File

@@ -32,8 +32,9 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace IT { namespace IT {
class TAGLIB_EXPORT Properties : public AudioProperties { class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
friend class File; friend class File;
public: public:
/*! Flag bits. */ /*! Flag bits. */
enum { enum {
@@ -53,15 +54,14 @@ namespace TagLib {
MidiConfEmbedded = 8 MidiConfEmbedded = 8
}; };
Properties(AudioProperties::ReadStyle propertiesStyle); explicit AudioProperties(AudioProperties::ReadStyle);
virtual ~Properties(); ~AudioProperties() override;
int length() const; int lengthInSeconds() const override;
int lengthInSeconds() const; int lengthInMilliseconds() const override;
int lengthInMilliseconds() const; int bitrate() const override;
int bitrate() const; int sampleRate() const override;
int sampleRate() const; int channels() const override;
int channels() const;
unsigned short lengthInPatterns() const; unsigned short lengthInPatterns() const;
bool stereo() const; bool stereo() const;
@@ -79,6 +79,7 @@ namespace TagLib {
unsigned char panningSeparation() const; unsigned char panningSeparation() const;
unsigned char pitchWheelDepth() const; unsigned char pitchWheelDepth() const;
private:
void setChannels(int channels); void setChannels(int channels);
void setLengthInPatterns(unsigned short lengthInPatterns); void setLengthInPatterns(unsigned short lengthInPatterns);
void setInstrumentCount(unsigned short instrumentCount); void setInstrumentCount(unsigned short instrumentCount);
@@ -96,14 +97,11 @@ namespace TagLib {
void setPitchWheelDepth(unsigned char pitchWheelDepth); void setPitchWheelDepth(unsigned char pitchWheelDepth);
private: private:
Properties(const Properties&); class AudioPropertiesPrivate;
Properties &operator=(const Properties&); AudioPropertiesPrivate *d;
class PropertiesPrivate;
PropertiesPrivate *d;
}; };
} } // namespace IT
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -33,63 +33,42 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace Mod; using namespace Mod;
class Mod::File::FilePrivate class Mod::File::FilePrivate {
{
public: public:
explicit FilePrivate(AudioProperties::ReadStyle propertiesStyle) explicit FilePrivate(AudioProperties::ReadStyle propertiesStyle) : properties(propertiesStyle) {}
: properties(propertiesStyle)
{
}
Mod::Tag tag; Mod::Tag tag;
Mod::Properties properties; Mod::AudioProperties properties;
}; };
Mod::File::File(FileName file, bool readProperties, Mod::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(file), d(new FilePrivate(propertiesStyle)) {
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(file),
d(new FilePrivate(propertiesStyle))
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
Mod::File::File(IOStream *stream, bool readProperties, Mod::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(stream), d(new FilePrivate(propertiesStyle)) {
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(stream),
d(new FilePrivate(propertiesStyle))
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
Mod::File::~File() Mod::File::~File() {
{
delete d; delete d;
} }
Mod::Tag *Mod::File::tag() const Mod::Tag *Mod::File::tag() const {
{
return &d->tag; return &d->tag;
} }
Mod::Properties *Mod::File::audioProperties() const Mod::AudioProperties *Mod::File::audioProperties() const {
{
return &d->properties; return &d->properties;
} }
PropertyMap Mod::File::properties() const bool Mod::File::save() {
{
return d->tag.properties();
}
PropertyMap Mod::File::setProperties(const PropertyMap &properties)
{
return d->tag.setProperties(properties);
}
bool Mod::File::save()
{
if (readOnly()) { if (readOnly()) {
debug("Mod::File::save() - Cannot save to a read only file."); debug("Mod::File::save() - Cannot save to a read only file.");
return false; return false;
@@ -97,21 +76,22 @@ bool Mod::File::save()
seek(0); seek(0);
writeString(d->tag.title(), 20); writeString(d->tag.title(), 20);
StringList lines = d->tag.comment().split("\n"); StringList lines = d->tag.comment().split("\n");
unsigned int n = std::min(lines.size(), d->properties.instrumentCount()); size_t n = std::min<size_t>(lines.size(), d->properties.instrumentCount());
for(unsigned int i = 0; i < n; ++ i) { for (size_t i = 0; i < n; ++i) {
writeString(lines[i], 22); writeString(lines[i], 22);
seek(8, Current); seek(8, Current);
} }
for(unsigned int i = n; i < d->properties.instrumentCount(); ++ i) { for (size_t i = n; i < d->properties.instrumentCount(); ++i) {
writeString(String(), 22); writeString(String(), 22);
seek(8, Current); seek(8, Current);
} }
return true; return true;
} }
void Mod::File::read(bool) void Mod::File::read(bool) {
{
if (!isOpen()) if (!isOpen())
return; return;
@@ -189,4 +169,5 @@ void Mod::File::read(bool)
READ_BYTE(d->properties.setLengthInPatterns); READ_BYTE(d->properties.setLengthInPatterns);
d->tag.setComment(comment.toString("\n")); d->tag.setComment(comment.toString("\n"));
} }

View File

@@ -35,60 +35,40 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace Mod { namespace Mod {
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::Mod::FileBase class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::Mod::FileBase {
{
public: public:
/*! /*!
* Constructs a Protracker file from \a file. * Constructs a Protracker file from \a file.
* *
* \note In the current implementation, both \a readProperties and * \note In the current implementation, both \a readProperties and \a propertiesStyle are ignored.
* \a propertiesStyle are ignored. The audio properties are always * The audio properties are always read.
* read.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*! /*!
* Constructs a Protracker file from \a stream. * Constructs a Protracker file from \a stream.
* *
* \note In the current implementation, both \a readProperties and * \note In the current implementation, both \a readProperties and \a propertiesStyle are ignored.
* \a propertiesStyle are ignored. The audio properties are always * The audio properties are always read.
* read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object. * responsible for deleting it after the File object.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
Mod::Tag *tag() const; Mod::Tag *tag() const override;
/*! /*!
* Implements the unified property interface -- export function. * Returns the Mod::AudioProperties for this file. If no audio properties were read then this will return a null pointer.
* Forwards to Mod::Tag::properties().
*/ */
PropertyMap properties() const; Mod::AudioProperties *audioProperties() const override;
/*!
* Implements the unified property interface -- import function.
* Forwards to Mod::Tag::setProperties().
*/
PropertyMap setProperties(const PropertyMap &);
/*!
* Returns the Mod::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
Mod::Properties *audioProperties() const;
/*! /*!
* Save the file. * Save the file.
@@ -96,7 +76,7 @@ namespace TagLib {
* *
* \note Saving Protracker tags is not supported. * \note Saving Protracker tags is not supported.
*/ */
bool save(); bool save() override;
private: private:
File(const File &); File(const File &);
@@ -108,9 +88,8 @@ namespace TagLib {
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace Mod
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -30,96 +30,93 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace Mod; using namespace Mod;
Mod::FileBase::FileBase(FileName file) : Strawberry_TagLib::TagLib::File(file) Mod::FileBase::FileBase(FileName file) : Strawberry_TagLib::TagLib::File(file) {}
{
}
Mod::FileBase::FileBase(IOStream *stream) : Strawberry_TagLib::TagLib::File(stream) Mod::FileBase::FileBase(IOStream *stream) : Strawberry_TagLib::TagLib::File(stream) {}
{
}
void Mod::FileBase::writeString(const String &s, unsigned long size, char padding) void Mod::FileBase::writeString(const String &s, unsigned int size, char padding) {
{
ByteVector data(s.data(String::Latin1)); ByteVector data(s.data(String::Latin1));
data.resize(size, padding); data.resize(size, padding);
writeBlock(data); writeBlock(data);
} }
bool Mod::FileBase::readString(String &s, unsigned long size) bool Mod::FileBase::readString(String &s, unsigned int size) {
{
ByteVector data(readBlock(size)); ByteVector data(readBlock(size));
if (data.size() < size) return false; if (data.size() < size) return false;
int index = data.find((char) 0); const size_t index = data.find(static_cast<char>(0));
if(index > -1) if (index != ByteVector::npos()) {
{
data.resize(index); data.resize(index);
} }
data.replace('\xff', ' '); data.replace('\xff', ' ');
s = data; s = data;
return true; return true;
} }
void Mod::FileBase::writeByte(unsigned char byte) void Mod::FileBase::writeByte(unsigned char _byte) {
{ ByteVector data(1, _byte);
ByteVector data(1, byte);
writeBlock(data); writeBlock(data);
} }
void Mod::FileBase::writeU16L(unsigned short number) void Mod::FileBase::writeU16L(unsigned short number) {
{ writeBlock(ByteVector::fromUInt16LE(number));
writeBlock(ByteVector::fromShort(number, false));
} }
void Mod::FileBase::writeU32L(unsigned long number) void Mod::FileBase::writeU32L(unsigned int number) {
{ writeBlock(ByteVector::fromUInt32LE(number));
writeBlock(ByteVector::fromUInt(number, false));
} }
void Mod::FileBase::writeU16B(unsigned short number) void Mod::FileBase::writeU16B(unsigned short number) {
{ writeBlock(ByteVector::fromUInt16BE(number));
writeBlock(ByteVector::fromShort(number, true));
} }
void Mod::FileBase::writeU32B(unsigned long number) void Mod::FileBase::writeU32B(unsigned int number) {
{ writeBlock(ByteVector::fromUInt32BE(number));
writeBlock(ByteVector::fromUInt(number, true));
} }
bool Mod::FileBase::readByte(unsigned char &byte) bool Mod::FileBase::readByte(unsigned char &_byte) {
{
ByteVector data(readBlock(1)); ByteVector data(readBlock(1));
if (data.size() < 1) return false; if (data.size() < 1) return false;
byte = data[0]; _byte = data[0];
return true; return true;
} }
bool Mod::FileBase::readU16L(unsigned short &number) bool Mod::FileBase::readU16L(unsigned short &number) {
{
ByteVector data(readBlock(2)); ByteVector data(readBlock(2));
if (data.size() < 2) return false; if (data.size() < 2) return false;
number = data.toUShort(false); number = data.toUInt16LE(0);
return true; return true;
} }
bool Mod::FileBase::readU32L(unsigned long &number) { bool Mod::FileBase::readU32L(unsigned int &number) {
ByteVector data(readBlock(4)); ByteVector data(readBlock(4));
if (data.size() < 4) return false; if (data.size() < 4) return false;
number = data.toUInt(false); number = data.toUInt32LE(0);
return true; return true;
} }
bool Mod::FileBase::readU16B(unsigned short &number) bool Mod::FileBase::readU16B(unsigned short &number) {
{
ByteVector data(readBlock(2)); ByteVector data(readBlock(2));
if (data.size() < 2) return false; if (data.size() < 2) return false;
number = data.toUShort(true); number = data.toUInt16BE(0);
return true; return true;
} }
bool Mod::FileBase::readU32B(unsigned long &number) { bool Mod::FileBase::readU32B(unsigned int &number) {
ByteVector data(readBlock(4)); ByteVector data(readBlock(4));
if (data.size() < 4) return false; if (data.size() < 4) return false;
number = data.toUInt(true); number = data.toUInt32BE(0);
return true; return true;
} }

View File

@@ -36,33 +36,30 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace Mod { namespace Mod {
class TAGLIB_EXPORT FileBase : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT FileBase : public Strawberry_TagLib::TagLib::File {
{
protected: protected:
FileBase(FileName file); explicit FileBase(FileName file);
FileBase(IOStream *stream); explicit FileBase(IOStream *stream);
void writeString(const String &s, unsigned long size, char padding = 0); void writeString(const String &s, unsigned int size, char padding = 0);
void writeByte(unsigned char byte); void writeByte(unsigned char byte);
void writeU16L(unsigned short number); void writeU16L(unsigned short number);
void writeU32L(unsigned long number); void writeU32L(unsigned int number);
void writeU16B(unsigned short number); void writeU16B(unsigned short number);
void writeU32B(unsigned long number); void writeU32B(unsigned int number);
bool readString(String &s, unsigned long size); bool readString(String &s, unsigned int size);
bool readByte(unsigned char &byte); bool readByte(unsigned char &_byte);
bool readU16L(unsigned short &number); bool readU16L(unsigned short &number);
bool readU32L(unsigned long &number); bool readU32L(unsigned int &number);
bool readU16B(unsigned short &number); bool readU16B(unsigned short &number);
bool readU32B(unsigned long &number); bool readU32B(unsigned int &number);
}; };
} } // namespace Mod
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -24,8 +24,7 @@
// some helper-macros only used internally by (s3m|it|xm)file.cpp // some helper-macros only used internally by (s3m|it|xm)file.cpp
#define READ_ASSERT(cond) \ #define READ_ASSERT(cond) \
if(!(cond)) \ if (!(cond)) { \
{ \
setValid(false); \ setValid(false); \
return; \ return; \
} }
@@ -39,9 +38,9 @@
#define READ_BYTE(setter) READ(setter, unsigned char, readByte) #define READ_BYTE(setter) READ(setter, unsigned char, readByte)
#define READ_U16L(setter) READ(setter, unsigned short, readU16L) #define READ_U16L(setter) READ(setter, unsigned short, readU16L)
#define READ_U32L(setter) READ(setter,unsigned long,readU32L) #define READ_U32L(setter) READ(setter, unsigned int, readU32L)
#define READ_U16B(setter) READ(setter, unsigned short, readU16B) #define READ_U16B(setter) READ(setter, unsigned short, readU16B)
#define READ_U32B(setter) READ(setter,unsigned long,readU32B) #define READ_U32B(setter) READ(setter, unsigned int, readU32B)
#define READ_STRING(setter, size) \ #define READ_STRING(setter, size) \
{ \ { \
@@ -56,9 +55,9 @@
#define READ_BYTE_AS(name) READ_AS(unsigned char, name, readByte) #define READ_BYTE_AS(name) READ_AS(unsigned char, name, readByte)
#define READ_U16L_AS(name) READ_AS(unsigned short, name, readU16L) #define READ_U16L_AS(name) READ_AS(unsigned short, name, readU16L)
#define READ_U32L_AS(name) READ_AS(unsigned long,name,readU32L) #define READ_U32L_AS(name) READ_AS(unsigned int, name, readU32L)
#define READ_U16B_AS(name) READ_AS(unsigned short, name, readU16B) #define READ_U16B_AS(name) READ_AS(unsigned short, name, readU16B)
#define READ_U32B_AS(name) READ_AS(unsigned long,name,readU32B) #define READ_U32B_AS(name) READ_AS(unsigned int, name, readU32B)
#define READ_STRING_AS(name, size) \ #define READ_STRING_AS(name, size) \
String name; \ String name; \

View File

@@ -29,83 +29,66 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace Mod; using namespace Mod;
class Mod::Properties::PropertiesPrivate class Mod::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : channels(0), instrumentCount(0), lengthInPatterns(0) {}
channels(0),
instrumentCount(0),
lengthInPatterns(0)
{
}
int channels; int channels;
unsigned int instrumentCount; unsigned int instrumentCount;
unsigned char lengthInPatterns; unsigned char lengthInPatterns;
}; };
Mod::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) : ////////////////////////////////////////////////////////////////////////////////
AudioProperties(propertiesStyle), // public members
d(new PropertiesPrivate()) ////////////////////////////////////////////////////////////////////////////////
{
Mod::AudioProperties::AudioProperties(AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
} }
Mod::Properties::~Properties() Mod::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int Mod::Properties::length() const int Mod::AudioProperties::lengthInSeconds() const {
{
return 0; return 0;
} }
int Mod::Properties::lengthInSeconds() const int Mod::AudioProperties::lengthInMilliseconds() const {
{
return 0; return 0;
} }
int Mod::Properties::lengthInMilliseconds() const int Mod::AudioProperties::bitrate() const {
{
return 0; return 0;
} }
int Mod::Properties::bitrate() const int Mod::AudioProperties::sampleRate() const {
{
return 0; return 0;
} }
int Mod::Properties::sampleRate() const int Mod::AudioProperties::channels() const {
{
return 0;
}
int Mod::Properties::channels() const
{
return d->channels; return d->channels;
} }
unsigned int Mod::Properties::instrumentCount() const unsigned int Mod::AudioProperties::instrumentCount() const {
{
return d->instrumentCount; return d->instrumentCount;
} }
unsigned char Mod::Properties::lengthInPatterns() const unsigned char Mod::AudioProperties::lengthInPatterns() const {
{
return d->lengthInPatterns; return d->lengthInPatterns;
} }
void Mod::Properties::setChannels(int channels) ////////////////////////////////////////////////////////////////////////////////
{ // private members
////////////////////////////////////////////////////////////////////////////////
void Mod::AudioProperties::setChannels(int channels) {
d->channels = channels; d->channels = channels;
} }
void Mod::Properties::setInstrumentCount(unsigned int instrumentCount) void Mod::AudioProperties::setInstrumentCount(unsigned int instrumentCount) {
{
d->instrumentCount = instrumentCount; d->instrumentCount = instrumentCount;
} }
void Mod::Properties::setLengthInPatterns(unsigned char lengthInPatterns) void Mod::AudioProperties::setLengthInPatterns(unsigned char lengthInPatterns) {
{
d->lengthInPatterns = lengthInPatterns; d->lengthInPatterns = lengthInPatterns;
} }

View File

@@ -31,43 +31,36 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace Mod { namespace Mod {
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{ friend class File;
public:
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
int length() const; public:
int lengthInSeconds() const; explicit AudioProperties(AudioProperties::ReadStyle propertiesStyle);
int lengthInMilliseconds() const; ~AudioProperties() override;
int bitrate() const;
int sampleRate() const; int lengthInSeconds() const override;
int channels() const; int lengthInMilliseconds() const override;
int bitrate() const override;
int sampleRate() const override;
int channels() const override;
unsigned int instrumentCount() const; unsigned int instrumentCount() const;
unsigned char lengthInPatterns() const; unsigned char lengthInPatterns() const;
private:
void setChannels(int channels); void setChannels(int channels);
void setInstrumentCount(unsigned int sampleCount); void setInstrumentCount(unsigned int instrumentCount);
void setLengthInPatterns(unsigned char lengthInPatterns); void setLengthInPatterns(unsigned char lengthInPatterns);
private: class AudioPropertiesPrivate;
friend class File; AudioPropertiesPrivate *d;
Properties(const Properties&);
Properties &operator=(const Properties&);
class PropertiesPrivate;
PropertiesPrivate *d;
}; };
} } // namespace Mod
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -27,139 +27,126 @@
#include "modtag.h" #include "modtag.h"
#include "tstringlist.h" #include "tstringlist.h"
#include "tpropertymap.h" #include "tpropertymap.h"
#include "tpicturemap.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace Mod; using namespace Mod;
class Mod::Tag::TagPrivate class Mod::Tag::TagPrivate {
{
public: public:
TagPrivate() explicit TagPrivate() {}
{
}
String title; String title;
String comment; String comment;
String trackerName; String trackerName;
}; };
Mod::Tag::Tag() : Mod::Tag::Tag() : d(new TagPrivate()) {}
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate())
{
}
Mod::Tag::~Tag() Mod::Tag::~Tag() {
{
delete d; delete d;
} }
String Mod::Tag::title() const String Mod::Tag::title() const {
{
return d->title; return d->title;
} }
String Mod::Tag::artist() const String Mod::Tag::artist() const {
{
return String(); return String();
} }
String Mod::Tag::album() const String Mod::Tag::album() const {
{
return String(); return String();
} }
String Mod::Tag::comment() const String Mod::Tag::comment() const {
{
return d->comment; return d->comment;
} }
String Mod::Tag::genre() const String Mod::Tag::genre() const {
{
return String(); return String();
} }
unsigned int Mod::Tag::year() const unsigned int Mod::Tag::year() const {
{
return 0; return 0;
} }
unsigned int Mod::Tag::track() const unsigned int Mod::Tag::track() const {
{
return 0; return 0;
} }
String Mod::Tag::trackerName() const Strawberry_TagLib::TagLib::PictureMap Mod::Tag::pictures() const {
{ return PictureMap();
}
String Mod::Tag::trackerName() const {
return d->trackerName; return d->trackerName;
} }
void Mod::Tag::setTitle(const String &title) void Mod::Tag::setTitle(const String &title) {
{
d->title = title; d->title = title;
} }
void Mod::Tag::setArtist(const String &) void Mod::Tag::setArtist(const String &) {
{
} }
void Mod::Tag::setAlbum(const String &) void Mod::Tag::setAlbum(const String &) {
{
} }
void Mod::Tag::setComment(const String &comment) void Mod::Tag::setComment(const String &comment) {
{
d->comment = comment; d->comment = comment;
} }
void Mod::Tag::setGenre(const String &) void Mod::Tag::setGenre(const String &) {
{
} }
void Mod::Tag::setYear(unsigned int) void Mod::Tag::setYear(unsigned int) {
{
} }
void Mod::Tag::setTrack(unsigned int) void Mod::Tag::setTrack(unsigned int) {
{
} }
void Mod::Tag::setTrackerName(const String &trackerName) void Mod::Tag::setPictures(const PictureMap&) {}
{
void Mod::Tag::setTrackerName(const String &trackerName) {
d->trackerName = trackerName; d->trackerName = trackerName;
} }
PropertyMap Mod::Tag::properties() const PropertyMap Mod::Tag::properties() const {
{
PropertyMap properties; PropertyMap properties;
properties["TITLE"] = d->title; properties["TITLE"] = d->title;
properties["COMMENT"] = d->comment; properties["COMMENT"] = d->comment;
if (!(d->trackerName.isEmpty())) if (!(d->trackerName.isEmpty()))
properties["TRACKERNAME"] = d->trackerName; properties["TRACKERNAME"] = d->trackerName;
return properties; return properties;
} }
PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps) PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps) {
{
PropertyMap properties(origProps); PropertyMap properties(origProps);
properties.removeEmpty(); properties.removeEmpty();
StringList oneValueSet; StringList oneValueSet;
if (properties.contains("TITLE")) { if (properties.contains("TITLE")) {
d->title = properties["TITLE"].front(); d->title = properties["TITLE"].front();
oneValueSet.append("TITLE"); oneValueSet.append("TITLE");
} else }
else
d->title.clear(); d->title.clear();
if (properties.contains("COMMENT")) { if (properties.contains("COMMENT")) {
d->comment = properties["COMMENT"].front(); d->comment = properties["COMMENT"].front();
oneValueSet.append("COMMENT"); oneValueSet.append("COMMENT");
} else }
else
d->comment.clear(); d->comment.clear();
if (properties.contains("TRACKERNAME")) { if (properties.contains("TRACKERNAME")) {
d->trackerName = properties["TRACKERNAME"].front(); d->trackerName = properties["TRACKERNAME"].front();
oneValueSet.append("TRACKERNAME"); oneValueSet.append("TRACKERNAME");
} else }
else
d->trackerName.clear(); d->trackerName.clear();
// for each tag that has been set above, remove the first entry in the corresponding // for each tag that has been set above, remove the first entry in the corresponding
@@ -171,4 +158,5 @@ PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps)
properties[*it].erase(properties[*it].begin()); properties[*it].erase(properties[*it].begin());
} }
return properties; return properties;
} }

View File

@@ -30,137 +30,131 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace Mod { namespace Mod {
/*! /*!
* Tags for module files (Mod, S3M, IT, XM). * Tags for module files (Mod, S3M, IT, XM).
* *
* Note that only the \a title is supported as such by most * Note that only the \a title is supported as such by most module file formats.
* module file formats. Except for XM files the \a trackerName * Except for XM files the \a trackerName is derived from the file format or the flavour of the file format.
* is derived from the file format or the flavour of the file * For XM files it is stored in the file.
* format. For XM files it is stored in the file.
* *
* The \a comment tag is not strictly supported by module files, * The \a comment tag is not strictly supported by module files,
* but it is common practice to abuse instrument/sample/pattern * but it is common practice to abuse instrument/sample/pattern names as multiline comments.
* names as multiline comments. TagLib does so as well. * TagLib does so as well.
*
*/ */
class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
{
public: public:
Tag(); explicit Tag();
virtual ~Tag(); ~Tag() override;
/*! /*!
* Returns the track name; if no track name is present in the tag * Returns the track name; if no track name is present in the tag String::null will be returned.
* String::null will be returned.
*/ */
virtual String title() const; String title() const override;
/*! /*!
* Not supported by module files. Therefore always returns String::null. * Not supported by module files. Therefore always returns String::null.
*/ */
virtual String artist() const; String artist() const override;
/*! /*!
* Not supported by module files. Therefore always returns String::null. * Not supported by module files. Therefore always returns String::null.
*/ */
virtual String album() const; String album() const override;
/*! /*!
* Returns the track comment derived from the instrument/sample/pattern * Returns the track comment derived from the instrument/sample/pattern
* names; if no comment is present in the tag String::null will be * names; if no comment is present in the tag String::null will be returned.
* returned.
*/ */
virtual String comment() const; String comment() const override;
/*! /*!
* Not supported by module files. Therefore always returns String::null. * Not supported by module files. Therefore always returns String::null.
*/ */
virtual String genre() const; String genre() const override;
/*! /*!
* Not supported by module files. Therefore always returns 0. * Not supported by module files. Therefore always returns 0.
*/ */
virtual unsigned int year() const; unsigned int year() const override;
/*! /*!
* Not supported by module files. Therefore always returns 0. * Not supported by module files. Therefore always returns 0.
*/ */
virtual unsigned int track() const; unsigned int track() const override;
PictureMap pictures() const override;
/*! /*!
* Returns the name of the tracker used to create/edit the module file. * Returns the name of the tracker used to create/edit the module file.
* Only XM files store this tag to the file as such, for other formats * Only XM files store this tag to the file as such, for other formats
* (Mod, S3M, IT) this is derived from the file type or the flavour of * (Mod, S3M, IT) this is derived from the file type or the flavour of the file type.
* the file type. Therefore only XM files might have an empty * Therefore only XM files might have an empty (String::null) tracker name.
* (String::null) tracker name.
*/ */
String trackerName() const; String trackerName() const;
/*! /*!
* Sets the title to \a title. If \a title is String::null then this * Sets the title to \a title.
* value will be cleared. * If \a title is String::null then this value will be cleared.
* *
* The length limits per file type are (1 character = 1 byte): * The length limits per file type are (1 character = 1 byte):
* Mod 20 characters, S3M 27 characters, IT 25 characters and XM 20 * Mod 20 characters, S3M 27 characters, IT 25 characters and XM 20 characters.
* characters.
*/ */
virtual void setTitle(const String &title); void setTitle(const String &title) override;
/*! /*!
* Not supported by module files and therefore ignored. * Not supported by module files and therefore ignored.
*/ */
virtual void setArtist(const String &artist); void setArtist(const String &artist) override;
/*! /*!
* Not supported by module files and therefore ignored. * Not supported by module files and therefore ignored.
*/ */
virtual void setAlbum(const String &album); void setAlbum(const String &album) override;
/*! /*!
* Sets the comment to \a comment. If \a comment is String::null then * Sets the comment to \a comment.
* this value will be cleared. * If \a comment is String::null then this value will be cleared.
* *
* Note that module file formats don't actually support a comment tag. * Note that module file formats don't actually support a comment tag.
* Instead the names of instruments/patterns/samples are abused as * Instead the names of instruments/patterns/samples are abused as a multiline comment.
* a multiline comment. Because of this the number of lines in a * Because of this the number of lines in a module file is fixed to the number of instruments/patterns/samples.
* module file is fixed to the number of instruments/patterns/samples.
* *
* Also note that the instrument/pattern/sample name length is limited * Also note that the instrument/pattern/sample name length is limited an thus the line length in comments are limited.
* an thus the line length in comments are limited. Too big comments * Too big comments will be truncated.
* will be truncated.
* *
* The line length limits per file type are (1 character = 1 byte): * The line length limits per file type are (1 character = 1 byte):
* Mod 22 characters, S3M 27 characters, IT 25 characters and XM 22 * Mod 22 characters, S3M 27 characters, IT 25 characters and XM 22 characters.
* characters.
*/ */
virtual void setComment(const String &comment); void setComment(const String &comment) override;
/*! /*!
* Not supported by module files and therefore ignored. * Not supported by module files and therefore ignored.
*/ */
virtual void setGenre(const String &genre); void setGenre(const String &genre) override;
/*! /*!
* Not supported by module files and therefore ignored. * Not supported by module files and therefore ignored.
*/ */
virtual void setYear(unsigned int year); void setYear(unsigned int year) override;
/*! /*!
* Not supported by module files and therefore ignored. * Not supported by module files and therefore ignored.
*/ */
virtual void setTrack(unsigned int track); void setTrack(unsigned int track) override;
void setPictures(const PictureMap &l) override;
/*! /*!
* Sets the tracker name to \a trackerName. If \a trackerName is * Sets the tracker name to \a trackerName.
* String::null then this value will be cleared. * If \a trackerName is String::null then this value will be cleared.
* *
* Note that only XM files support this tag. Setting the * Note that only XM files support this tag.
* tracker name for other module file formats will be ignored. * Setting the tracker name for other module file formats will be ignored.
* *
* The length of this tag is limited to 20 characters (1 character * The length of this tag is limited to 20 characters (1 character = 1 byte).
* = 1 byte).
*/ */
void setTrackerName(const String &trackerName); void setTrackerName(const String &trackerName);
@@ -168,17 +162,14 @@ namespace TagLib {
* Implements the unified property interface -- export function. * Implements the unified property interface -- export function.
* Since the module tag is very limited, the exported map is as well. * Since the module tag is very limited, the exported map is as well.
*/ */
PropertyMap properties() const; PropertyMap properties() const override;
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* Because of the limitations of the module file tag, any tags besides * Because of the limitations of the module file tag, any tags besides COMMENT, TITLE and, if it is an XM file, TRACKERNAME, will be returned.
* COMMENT, TITLE and, if it is an XM file, TRACKERNAME, will be * Additionally, if the map contains tags with multiple values, all but the first will be contained in the returned map of unsupported properties.
* returned. Additionally, if the map contains tags with multiple values,
* all but the first will be contained in the returned map of unsupported
* properties.
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
private: private:
Tag(const Tag&); Tag(const Tag&);
@@ -188,9 +179,8 @@ namespace TagLib {
TagPrivate *d; TagPrivate *d;
}; };
} } // namespace Mod
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -25,20 +25,16 @@
#include <climits> #include <climits>
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include "mp4atom.h" #include "mp4atom.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
const char *MP4::Atom::containers[11] = { const char *MP4::Atom::containers[11] = { "moov", "udta", "mdia", "meta", "ilst", "stbl", "minf", "moof", "traf", "trak", "stsd" };
"moov", "udta", "mdia", "meta", "ilst",
"stbl", "minf", "moof", "traf", "trak", MP4::Atom::Atom(File *file) {
"stsd"
};
MP4::Atom::Atom(File *file)
{
children.setAutoDelete(true); children.setAutoDelete(true);
offset = file->tell(); offset = file->tell();
@@ -52,7 +48,7 @@ MP4::Atom::Atom(File *file)
return; return;
} }
length = header.toUInt(); length = header.toUInt32BE(0);
if (length == 0) { if (length == 0) {
// The last atom which extends to the end of the file. // The last atom which extends to the end of the file.
@@ -60,17 +56,7 @@ MP4::Atom::Atom(File *file)
} }
else if (length == 1) { else if (length == 1) {
// The atom has a 64-bit length. // The atom has a 64-bit length.
const long long longLength = file->readBlock(8).toLongLong(); length = file->readBlock(8).toInt64BE(0);
if(longLength <= LONG_MAX) {
// The actual length fits in long. That's always the case if long is 64-bit.
length = static_cast<long>(longLength);
}
else {
debug("MP4: 64-bit atoms are not supported");
length = 0;
file->seek(0, File::End);
return;
}
} }
if (length < 8) { if (length < 8) {
@@ -101,16 +87,14 @@ MP4::Atom::Atom(File *file)
} }
file->seek(offset + length); file->seek(offset + length);
} }
MP4::Atom::~Atom() MP4::Atom::~Atom() {}
{
}
MP4::Atom * MP4::Atom *MP4::Atom::find(const char *name1, const char *name2, const char *name3, const char *name4) {
MP4::Atom::find(const char *name1, const char *name2, const char *name3, const char *name4)
{ if (!name1) {
if(name1 == 0) {
return this; return this;
} }
for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
@@ -119,28 +103,28 @@ MP4::Atom::find(const char *name1, const char *name2, const char *name3, const c
} }
} }
return nullptr; return nullptr;
} }
MP4::AtomList MP4::AtomList MP4::Atom::findall(const char *_name, bool recursive) {
MP4::Atom::findall(const char *name, bool recursive)
{
MP4::AtomList result; MP4::AtomList result;
for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
if((*it)->name == name) { if ((*it)->name == _name) {
result.append(*it); result.append(*it);
} }
if (recursive) { if (recursive) {
result.append((*it)->findall(name, recursive)); result.append((*it)->findall(_name, recursive));
} }
} }
return result; return result;
} }
bool bool MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const char *name3) {
MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const char *name3)
{
path.append(this); path.append(this);
if(name1 == 0) { if (!name1) {
return true; return true;
} }
for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { for (AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) {
@@ -149,14 +133,15 @@ MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const
} }
} }
return false; return false;
} }
MP4::Atoms::Atoms(File *file) MP4::Atoms::Atoms(File *file) {
{
atoms.setAutoDelete(true); atoms.setAutoDelete(true);
file->seek(0, File::End); file->seek(0, File::End);
long end = file->tell(); long long end = file->tell();
file->seek(0); file->seek(0);
while (file->tell() + 8 <= end) { while (file->tell() + 8 <= end) {
MP4::Atom *atom = new MP4::Atom(file); MP4::Atom *atom = new MP4::Atom(file);
@@ -164,26 +149,24 @@ MP4::Atoms::Atoms(File *file)
if (atom->length == 0) if (atom->length == 0)
break; break;
} }
} }
MP4::Atoms::~Atoms() MP4::Atoms::~Atoms() {}
{
} MP4::Atom *MP4::Atoms::find(const char *name1, const char *name2, const char *name3, const char *name4) {
MP4::Atom *
MP4::Atoms::find(const char *name1, const char *name2, const char *name3, const char *name4)
{
for (AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) { for (AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) {
if ((*it)->name == name1) { if ((*it)->name == name1) {
return (*it)->find(name2, name3, name4); return (*it)->find(name2, name3, name4);
} }
} }
return nullptr; return nullptr;
} }
MP4::AtomList MP4::AtomList MP4::Atoms::path(const char *name1, const char *name2, const char *name3, const char *name4) {
MP4::Atoms::path(const char *name1, const char *name2, const char *name3, const char *name4)
{
MP4::AtomList path; MP4::AtomList path;
for (AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) { for (AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) {
if ((*it)->name == name1) { if ((*it)->name == name1) {
@@ -194,4 +177,5 @@ MP4::Atoms::path(const char *name1, const char *name2, const char *name3, const
} }
} }
return path; return path;
} }

View File

@@ -35,14 +35,12 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace MP4 { namespace MP4 {
class Atom; class Atom;
typedef Strawberry_TagLib::TagLib::List<Atom *> AtomList; typedef Strawberry_TagLib::TagLib::List<Atom *> AtomList;
enum AtomDataType enum AtomDataType {
{
TypeImplicit = 0, // for use with tags for which no type needs to be indicated because only one type is allowed TypeImplicit = 0, // for use with tags for which no type needs to be indicated because only one type is allowed
TypeUTF8 = 1, // without any count or null terminator TypeUTF8 = 1, // without any count or null terminator
TypeUTF16 = 2, // also known as UTF-16BE TypeUTF16 = 2, // also known as UTF-16BE
@@ -67,7 +65,7 @@ namespace TagLib {
}; };
struct AtomData { struct AtomData {
AtomData(AtomDataType type, ByteVector data) : type(type), locale(0), data(data) {} explicit AtomData(AtomDataType _type, ByteVector _data) : type(_type), locale(0), data(_data) {}
AtomDataType type; AtomDataType type;
int locale; int locale;
ByteVector data; ByteVector data;
@@ -75,38 +73,38 @@ namespace TagLib {
typedef Strawberry_TagLib::TagLib::List<AtomData> AtomDataList; typedef Strawberry_TagLib::TagLib::List<AtomData> AtomDataList;
class Atom class Atom {
{
public: public:
Atom(File *file); explicit Atom(File *file);
~Atom(); ~Atom();
Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
bool path(AtomList &path, const char *name1, const char *name2 = 0, const char *name3 = 0); Atom *find(const char *name1, const char *name2 = nullptr, const char *name3 = nullptr, const char *name4 = nullptr);
bool path(AtomList &path, const char *name1, const char *name2 = nullptr, const char *name3 = nullptr);
AtomList findall(const char *name, bool recursive = false); AtomList findall(const char *name, bool recursive = false);
long offset; long long offset;
long length; long long length;
Strawberry_TagLib::TagLib::ByteVector name; Strawberry_TagLib::TagLib::ByteVector name;
AtomList children; AtomList children;
private: private:
static const int numContainers = 11; static const int numContainers = 11;
static const char *containers[11]; static const char *containers[11];
}; };
//! Root-level atoms //! Root-level atoms
class Atoms class Atoms {
{
public: public:
Atoms(File *file); explicit Atoms(File *file);
~Atoms(); ~Atoms();
Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
AtomList path(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0); Atom *find(const char *name1, const char *name2 = nullptr, const char *name3 = nullptr, const char *name4 = nullptr);
AtomList path(const char *name1, const char *name2 = nullptr, const char *name3 = nullptr, const char *name4 = nullptr);
AtomList atoms; AtomList atoms;
}; };
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
# endif # endif

View File

@@ -23,71 +23,63 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include <memory>
#include <tdebug.h>
#include "trefcounter.h" #include "taglib.h"
#include "tdebug.h"
#include "mp4coverart.h" #include "mp4coverart.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class MP4::CoverArt::CoverArtPrivate : public RefCounter namespace {
{
public:
CoverArtPrivate() :
RefCounter(),
format(MP4::CoverArt::JPEG) {}
Format format; struct CoverArtData {
MP4::CoverArt::Format format;
ByteVector data; ByteVector data;
}; };
} // namespace
class MP4::CoverArt::CoverArtPrivate {
public:
explicit CoverArtPrivate(Format f, const ByteVector &v) : data(new CoverArtData()) {
data->format = f;
data->data = v;
}
std::shared_ptr<CoverArtData> data;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MP4::CoverArt::CoverArt(Format format, const ByteVector &data) : MP4::CoverArt::CoverArt(Format format, const ByteVector &data) : d(new CoverArtPrivate(format, data)) {}
d(new CoverArtPrivate())
{
d->format = format;
d->data = data;
}
MP4::CoverArt::CoverArt(const CoverArt &item) : MP4::CoverArt::CoverArt(const CoverArt &item) : d(new CoverArtPrivate(*item.d)) {}
d(item.d)
{
d->ref();
}
MP4::CoverArt & MP4::CoverArt &
MP4::CoverArt::operator=(const CoverArt &item) MP4::CoverArt::operator=(const CoverArt &item) {
{
CoverArt(item).swap(*this); CoverArt(item).swap(*this);
return *this; return *this;
} }
void void MP4::CoverArt::swap(CoverArt &item) {
MP4::CoverArt::swap(CoverArt &item)
{
using std::swap; using std::swap;
swap(d, item.d); swap(d, item.d);
} }
MP4::CoverArt::~CoverArt() MP4::CoverArt::~CoverArt() {
{
if(d->deref()) {
delete d; delete d;
} }
}
MP4::CoverArt::Format MP4::CoverArt::Format
MP4::CoverArt::format() const MP4::CoverArt::format() const {
{ return d->data->format;
return d->format;
} }
ByteVector ByteVector
MP4::CoverArt::data() const MP4::CoverArt::data() const {
{ return d->data->data;
return d->data;
} }

View File

@@ -33,11 +33,9 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace MP4 { namespace MP4 {
class TAGLIB_EXPORT CoverArt class TAGLIB_EXPORT CoverArt {
{
public: public:
/*! /*!
* This describes the image type. * This describes the image type.
@@ -50,7 +48,7 @@ namespace TagLib {
Unknown = TypeImplicit, Unknown = TypeImplicit,
}; };
CoverArt(Format format, const ByteVector &data); explicit CoverArt(Format format, const ByteVector &data);
~CoverArt(); ~CoverArt();
CoverArt(const CoverArt &item); CoverArt(const CoverArt &item);
@@ -78,9 +76,8 @@ namespace TagLib {
typedef List<CoverArt> CoverArtList; typedef List<CoverArt> CoverArtList;
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,10 +23,10 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include <tpropertymap.h> #include "tpropertymap.h"
#include <tagutils.h> #include "tagutils.h"
#include "mp4atom.h" #include "mp4atom.h"
#include "mp4tag.h" #include "mp4tag.h"
@@ -34,10 +34,9 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{ bool checkValid(const MP4::AtomList &list) {
bool checkValid(const MP4::AtomList &list)
{
for (MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) { for (MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) {
if ((*it)->length == 0) if ((*it)->length == 0)
@@ -48,19 +47,15 @@ namespace
} }
return true; return true;
}
}
class MP4::File::FilePrivate }
{ } // namespace
class MP4::File::FilePrivate {
public: public:
FilePrivate() : explicit FilePrivate() : tag(nullptr), atoms(nullptr), properties(nullptr) {}
tag(0),
atoms(0),
properties(0) {}
~FilePrivate() ~FilePrivate() {
{
delete atoms; delete atoms;
delete tag; delete tag;
delete properties; delete properties;
@@ -68,76 +63,56 @@ public:
MP4::Tag *tag; MP4::Tag *tag;
MP4::Atoms *atoms; MP4::Atoms *atoms;
MP4::Properties *properties; MP4::AudioProperties *properties;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool MP4::File::isSupported(IOStream *stream) bool MP4::File::isSupported(IOStream *stream) {
{
// An MP4 file has to have an "ftyp" box first. // An MP4 file has to have an "ftyp" box first.
const ByteVector id = Utils::readHeader(stream, 8, false); const ByteVector id = Utils::readHeader(stream, 8, false);
return id.containsAt("ftyp", 4); return id.containsAt("ftyp", 4);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MP4::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) : MP4::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
MP4::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle) : MP4::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
MP4::File::~File() MP4::File::~File() {
{
delete d; delete d;
} }
MP4::Tag * MP4::Tag *
MP4::File::tag() const MP4::File::tag() const {
{
return d->tag; return d->tag;
} }
PropertyMap MP4::File::properties() const MP4::AudioProperties *
{ MP4::File::audioProperties() const {
return d->tag->properties();
}
void MP4::File::removeUnsupportedProperties(const StringList &properties)
{
d->tag->removeUnsupportedProperties(properties);
}
PropertyMap MP4::File::setProperties(const PropertyMap &properties)
{
return d->tag->setProperties(properties);
}
MP4::Properties *
MP4::File::audioProperties() const
{
return d->properties; return d->properties;
} }
void void MP4::File::read(bool readProperties) {
MP4::File::read(bool readProperties)
{
if (!isValid()) if (!isValid())
return; return;
@@ -155,13 +130,13 @@ MP4::File::read(bool readProperties)
d->tag = new Tag(this, d->atoms); d->tag = new Tag(this, d->atoms);
if (readProperties) { if (readProperties) {
d->properties = new Properties(this, d->atoms); d->properties = new AudioProperties(this, d->atoms);
}
} }
bool }
MP4::File::save()
{ bool MP4::File::save() {
if (readOnly()) { if (readOnly()) {
debug("MP4::File::save() -- File is read only."); debug("MP4::File::save() -- File is read only.");
return false; return false;
@@ -173,10 +148,9 @@ MP4::File::save()
} }
return d->tag->save(); return d->tag->save();
} }
bool bool MP4::File::hasMP4Tag() const {
MP4::File::hasMP4Tag() const return (d->atoms->find("moov", "udta", "meta", "ilst") != nullptr);
{
return (d->atoms->find("moov", "udta", "meta", "ilst") != 0);
} }

View File

@@ -46,87 +46,63 @@ namespace TagLib {
* the abstract TagLib::File API as well as providing some additional * the abstract TagLib::File API as well as providing some additional
* information specific to MP4 files. * information specific to MP4 files.
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* Constructs an MP4 file from \a file. If \a readProperties is true the * Constructs an MP4 file from \a file.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
Properties::ReadStyle audioPropertiesStyle = Properties::Average);
/*! /*!
* Constructs an MP4 file from \a stream. If \a readProperties is true the * Constructs an MP4 file from \a stream.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object. * responsible for deleting it after the File object.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
Properties::ReadStyle audioPropertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns a pointer to the MP4 tag of the file. * Returns a pointer to the MP4 tag of the file.
* *
* MP4::Tag implements the tag interface, so this serves as the * MP4::Tag implements the tag interface, so this serves as the reimplementation of TagLib::File::tag().
* reimplementation of TagLib::File::tag().
* *
* \note The Tag <b>is still</b> owned by the MP4::File and should not be * \note The Tag <b>is still</b> owned by the MP4::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
*/ */
Tag *tag() const; Tag *tag() const override;
/*!
* Implements the unified property interface -- export function.
*/
PropertyMap properties() const;
/*!
* Removes unsupported properties. Forwards to the actual Tag's
* removeUnsupportedProperties() function.
*/
void removeUnsupportedProperties(const StringList &properties);
/*!
* Implements the unified property interface -- import function.
*/
PropertyMap setProperties(const PropertyMap &);
/*! /*!
* Returns the MP4 audio properties for this file. * Returns the MP4 audio properties for this file.
*/ */
Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Save the file. * Save the file.
* *
* This returns true if the save was successful. * This returns true if the save was successful.
*/ */
bool save(); bool save() override;
/*! /*!
* Returns whether or not the file on disk actually has an MP4 tag, or the * Returns whether or not the file on disk actually has an MP4 tag, or the file has a Metadata Item List (ilst) atom.
* file has a Metadata Item List (ilst) atom.
*/ */
bool hasMP4Tag() const; bool hasMP4Tag() const;
/*! /*!
* Returns whether or not the given \a stream can be opened as an ASF * Returns whether or not the given \a stream can be opened as an ASF file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check. The result may not necessarily be correct.
* not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -137,9 +113,8 @@ namespace TagLib {
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,27 +23,25 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <taglib.h> #include <memory>
#include <tdebug.h>
#include "trefcounter.h" #include "taglib.h"
#include "tdebug.h"
#include "mp4item.h" #include "mp4item.h"
#include "tutils.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class MP4::Item::ItemPrivate : public RefCounter namespace {
{ struct ItemData {
public:
ItemPrivate() :
RefCounter(),
valid(true),
atomDataType(TypeUndefined) {}
bool valid; bool valid;
AtomDataType atomDataType; MP4::AtomDataType atomDataType;
MP4::Item::ItemType type;
union { union {
bool m_bool; bool m_bool;
int m_int; int m_int;
IntPair m_intPair; MP4::Item::IntPair m_intPair;
unsigned char m_byte; unsigned char m_byte;
unsigned int m_uint; unsigned int m_uint;
long long m_longlong; long long m_longlong;
@@ -52,161 +50,166 @@ public:
ByteVectorList m_byteVectorList; ByteVectorList m_byteVectorList;
MP4::CoverArtList m_coverArtList; MP4::CoverArtList m_coverArtList;
}; };
} // namespace
MP4::Item::Item() : class MP4::Item::ItemPrivate {
d(new ItemPrivate()) public:
{ explicit ItemPrivate() : data(new ItemData()) {
d->valid = false; data->valid = true;
data->atomDataType = MP4::TypeUndefined;
data->type = MP4::Item::TypeUndefined_;
} }
MP4::Item::Item(const Item &item) : std::shared_ptr<ItemData> data;
d(item.d) };
{
d->ref(); MP4::Item::Item() : d(new ItemPrivate()) {
d->data->valid = false;
} }
MP4::Item & MP4::Item::Item(const Item &item) : d(new ItemPrivate(*item.d)) {}
MP4::Item::operator=(const Item &item)
{ MP4::Item &MP4::Item::operator=(const Item &item) {
Item(item).swap(*this); Item(item).swap(*this);
return *this; return *this;
} }
void void MP4::Item::swap(Item &item) {
MP4::Item::swap(Item &item)
{
using std::swap; using std::swap;
swap(d, item.d); swap(d, item.d);
} }
MP4::Item::~Item() MP4::Item::~Item() {
{
if(d->deref())
delete d; delete d;
} }
MP4::Item::Item(bool value) : MP4::Item::Item(bool value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_bool = value;
{ d->data->type = TypeBool;
d->m_bool = value;
} }
MP4::Item::Item(int value) : MP4::Item::Item(int value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_int = value;
{ d->data->type = TypeInt;
d->m_int = value;
} }
MP4::Item::Item(unsigned char value) : MP4::Item::Item(unsigned char value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_byte = value;
{ d->data->type = TypeByte;
d->m_byte = value;
} }
MP4::Item::Item(unsigned int value) : MP4::Item::Item(unsigned int value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_uint = value;
{ d->data->type = TypeUInt;
d->m_uint = value;
} }
MP4::Item::Item(long long value) : MP4::Item::Item(long long value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_longlong = value;
{ d->data->type = TypeLongLong;
d->m_longlong = value;
} }
MP4::Item::Item(int value1, int value2) : MP4::Item::Item(int value1, int value2) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_intPair.first = value1;
{ d->data->m_intPair.second = value2;
d->m_intPair.first = value1; d->data->type = TypeIntPair;
d->m_intPair.second = value2;
} }
MP4::Item::Item(const ByteVectorList &value) : MP4::Item::Item(const ByteVectorList &value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_byteVectorList = value;
{ d->data->type = TypeByteVectorList;
d->m_byteVectorList = value;
} }
MP4::Item::Item(const StringList &value) : MP4::Item::Item(const StringList &value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_stringList = value;
{ d->data->type = TypeStringList;
d->m_stringList = value;
} }
MP4::Item::Item(const MP4::CoverArtList &value) : MP4::Item::Item(const MP4::CoverArtList &value) : d(new ItemPrivate()) {
d(new ItemPrivate()) d->data->m_coverArtList = value;
{ d->data->type = TypeCoverArtList;
d->m_coverArtList = value;
} }
void MP4::Item::setAtomDataType(MP4::AtomDataType type) void MP4::Item::setAtomDataType(MP4::AtomDataType type) {
{ d->data->atomDataType = type;
d->atomDataType = type;
} }
MP4::AtomDataType MP4::Item::atomDataType() const MP4::AtomDataType MP4::Item::atomDataType() const {
{ return d->data->atomDataType;
return d->atomDataType;
} }
bool bool MP4::Item::toBool() const {
MP4::Item::toBool() const return d->data->m_bool;
{
return d->m_bool;
} }
int int MP4::Item::toInt() const {
MP4::Item::toInt() const return d->data->m_int;
{
return d->m_int;
} }
unsigned char unsigned char MP4::Item::toByte() const {
MP4::Item::toByte() const return d->data->m_byte;
{
return d->m_byte;
} }
unsigned int unsigned int MP4::Item::toUInt() const {
MP4::Item::toUInt() const return d->data->m_uint;
{
return d->m_uint;
} }
long long long long MP4::Item::toLongLong() const {
MP4::Item::toLongLong() const return d->data->m_longlong;
{
return d->m_longlong;
} }
MP4::Item::IntPair MP4::Item::IntPair MP4::Item::toIntPair() const {
MP4::Item::toIntPair() const return d->data->m_intPair;
{
return d->m_intPair;
} }
StringList StringList MP4::Item::toStringList() const {
MP4::Item::toStringList() const return d->data->m_stringList;
{
return d->m_stringList;
} }
ByteVectorList ByteVectorList MP4::Item::toByteVectorList() const {
MP4::Item::toByteVectorList() const return d->data->m_byteVectorList;
{
return d->m_byteVectorList;
} }
MP4::CoverArtList MP4::CoverArtList MP4::Item::toCoverArtList() const {
MP4::Item::toCoverArtList() const return d->data->m_coverArtList;
{
return d->m_coverArtList;
} }
bool bool MP4::Item::isValid() const {
MP4::Item::isValid() const return d->data->valid;
{ }
return d->valid;
String MP4::Item::toString() const {
StringList desc;
switch (d->data->type) {
case TypeBool:
return d->data->m_bool ? "true" : "false";
case TypeInt:
return Utils::formatString("%d", d->data->m_int);
case TypeIntPair:
return Utils::formatString("%d/%d", d->data->m_intPair.first, d->data->m_intPair.second);
case TypeByte:
return Utils::formatString("%d", d->data->m_byte);
case TypeUInt:
return Utils::formatString("%u", d->data->m_uint);
case TypeLongLong:
return Utils::formatString("%lld", d->data->m_longlong);
case TypeStringList:
return d->data->m_stringList.toString(" / ");
case TypeByteVectorList:
for (size_t i = 0; i < d->data->m_byteVectorList.size(); i++) {
desc.append(Utils::formatString(
"[%d bytes of data]", static_cast<int>(d->data->m_byteVectorList[i].size())));
}
return desc.toString(", ");
case TypeCoverArtList:
for (size_t i = 0; i < d->data->m_coverArtList.size(); i++) {
desc.append(Utils::formatString("[%d bytes of data]", static_cast<int>(d->data->m_coverArtList[i].data().size())));
}
return desc.toString(", ");
case TypeUndefined_:
return "[unknown]";
}
return String();
} }

View File

@@ -32,17 +32,28 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace MP4 { namespace MP4 {
class TAGLIB_EXPORT Item class TAGLIB_EXPORT Item {
{
public: public:
struct IntPair { struct IntPair {
int first, second; int first, second;
}; };
Item(); enum ItemType {
TypeUndefined_ = 0,
TypeBool,
TypeInt,
TypeIntPair,
TypeByte,
TypeUInt,
TypeLongLong,
TypeStringList,
TypeByteVectorList,
TypeCoverArtList,
};
explicit Item();
Item(const Item &item); Item(const Item &item);
/*! /*!
@@ -80,16 +91,19 @@ namespace TagLib {
ByteVectorList toByteVectorList() const; ByteVectorList toByteVectorList() const;
CoverArtList toCoverArtList() const; CoverArtList toCoverArtList() const;
ItemType type() const;
bool isValid() const; bool isValid() const;
String toString() const;
private: private:
class ItemPrivate; class ItemPrivate;
ItemPrivate *d; ItemPrivate *d;
}; };
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,25 +23,23 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include "mp4file.h" #include "mp4file.h"
#include "mp4atom.h" #include "mp4atom.h"
#include "mp4properties.h" #include "mp4properties.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class MP4::Properties::PropertiesPrivate class MP4::AudioProperties::AudioPropertiesPrivate {
{
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : length(0),
length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
channels(0), channels(0),
bitsPerSample(0), bitsPerSample(0),
encrypted(false), encrypted(false),
codec(MP4::Properties::Unknown) {} codec(MP4::AudioProperties::Unknown) {}
int length; int length;
int bitrate; int bitrate;
@@ -56,86 +54,80 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) : MP4::AudioProperties::AudioProperties(File *file, MP4::Atoms *atoms, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
AudioProperties(style),
d(new PropertiesPrivate())
{
read(file, atoms); read(file, atoms);
} }
MP4::Properties::~Properties() MP4::AudioProperties::~AudioProperties() {
{
delete d; delete d;
} }
int int MP4::AudioProperties::channels() const {
MP4::Properties::channels() const
{
return d->channels; return d->channels;
} }
int int MP4::AudioProperties::sampleRate() const {
MP4::Properties::sampleRate() const
{
return d->sampleRate; return d->sampleRate;
} }
int int MP4::AudioProperties::lengthInSeconds() const {
MP4::Properties::length() const
{
return lengthInSeconds();
}
int
MP4::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int int MP4::AudioProperties::lengthInMilliseconds() const {
MP4::Properties::lengthInMilliseconds() const
{
return d->length; return d->length;
} }
int int MP4::AudioProperties::bitrate() const {
MP4::Properties::bitrate() const
{
return d->bitrate; return d->bitrate;
} }
int int MP4::AudioProperties::bitsPerSample() const {
MP4::Properties::bitsPerSample() const
{
return d->bitsPerSample; return d->bitsPerSample;
} }
bool bool MP4::AudioProperties::isEncrypted() const {
MP4::Properties::isEncrypted() const
{
return d->encrypted; return d->encrypted;
} }
MP4::Properties::Codec MP4::AudioProperties::Codec
MP4::Properties::codec() const MP4::AudioProperties::codec() const {
{
return d->codec; return d->codec;
} }
String MP4::AudioProperties::toString() const {
String format;
if (d->codec == AAC) {
format = "AAC";
}
else if (d->codec == ALAC) {
format = "ALAC";
}
else {
format = "Unknown";
}
StringList desc;
desc.append("MPEG-4 audio (" + format + ")");
desc.append(String::number(lengthInSeconds()) + " seconds");
desc.append(String::number(bitrate()) + " kbps");
return desc.toString(", ");
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void void MP4::AudioProperties::read(File *file, Atoms *atoms) {
MP4::Properties::read(File *file, Atoms *atoms)
{
MP4::Atom *moov = atoms->find("moov"); MP4::Atom *moov = atoms->find("moov");
if (!moov) { if (!moov) {
debug("MP4: Atom 'moov' not found"); debug("MP4: Atom 'moov' not found");
return; return;
} }
MP4::Atom *trak = 0; MP4::Atom *trak = nullptr;
ByteVector data; ByteVector data;
const MP4::AtomList trakList = moov->findall("trak"); const MP4::AtomList trakList = moov->findall("trak");
@@ -151,7 +143,7 @@ MP4::Properties::read(File *file, Atoms *atoms)
if (data.containsAt("soun", 16)) { if (data.containsAt("soun", 16)) {
break; break;
} }
trak = 0; trak = nullptr;
} }
if (!trak) { if (!trak) {
debug("MP4: No audio tracks"); debug("MP4: No audio tracks");
@@ -175,16 +167,16 @@ MP4::Properties::read(File *file, Atoms *atoms)
debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected");
return; return;
} }
unit = data.toUInt(28U); unit = data.toUInt32BE(28);
length = data.toLongLong(32U); length = data.toInt64BE(32);
} }
else { else {
if (data.size() < 24 + 8) { if (data.size() < 24 + 8) {
debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected");
return; return;
} }
unit = data.toUInt(20U); unit = data.toUInt32BE(20);
length = data.toUInt(24U); length = data.toUInt32BE(24);
} }
if (unit > 0 && length > 0) if (unit > 0 && length > 0)
d->length = static_cast<int>(length * 1000.0 / unit + 0.5); d->length = static_cast<int>(length * 1000.0 / unit + 0.5);
@@ -198,9 +190,9 @@ MP4::Properties::read(File *file, Atoms *atoms)
data = file->readBlock(atom->length); data = file->readBlock(atom->length);
if (data.containsAt("mp4a", 20)) { if (data.containsAt("mp4a", 20)) {
d->codec = AAC; d->codec = AAC;
d->channels = data.toShort(40U); d->channels = data.toUInt16BE(40);
d->bitsPerSample = data.toShort(42U); d->bitsPerSample = data.toUInt16BE(42);
d->sampleRate = data.toUInt(46U); d->sampleRate = data.toUInt32BE(46);
if (data.containsAt("esds", 56) && data[64] == 0x03) { if (data.containsAt("esds", 56) && data[64] == 0x03) {
unsigned int pos = 65; unsigned int pos = 65;
if (data.containsAt("\x80\x80\x80", pos)) { if (data.containsAt("\x80\x80\x80", pos)) {
@@ -213,7 +205,7 @@ MP4::Properties::read(File *file, Atoms *atoms)
pos += 3; pos += 3;
} }
pos += 10; pos += 10;
d->bitrate = static_cast<int>((data.toUInt(pos) + 500) / 1000.0 + 0.5); d->bitrate = static_cast<int>((data.toUInt32BE(pos) + 500) / 1000.0 + 0.5);
} }
} }
} }
@@ -222,8 +214,8 @@ MP4::Properties::read(File *file, Atoms *atoms)
d->codec = ALAC; d->codec = ALAC;
d->bitsPerSample = data.at(69); d->bitsPerSample = data.at(69);
d->channels = data.at(73); d->channels = data.at(73);
d->bitrate = static_cast<int>(data.toUInt(80U) / 1000.0 + 0.5); d->bitrate = static_cast<int>(data.toUInt32BE(80) / 1000.0 + 0.5);
d->sampleRate = data.toUInt(84U); d->sampleRate = data.toUInt32BE(84);
} }
} }
@@ -231,4 +223,5 @@ MP4::Properties::read(File *file, Atoms *atoms)
if (drms) { if (drms) {
d->encrypted = true; d->encrypted = true;
} }
} }

View File

@@ -31,15 +31,13 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace MP4 { namespace MP4 {
class Atoms; class Atoms;
class File; class File;
//! An implementation of MP4 audio properties //! An implementation of MP4 audio properties
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
enum Codec { enum Codec {
Unknown = 0, Unknown = 0,
@@ -47,50 +45,37 @@ namespace TagLib {
ALAC ALAC
}; };
Properties(File *file, Atoms *atoms, ReadStyle style = Average); explicit AudioProperties(File *file, Atoms *atoms, ReadStyle style = Average);
virtual ~Properties(); ~AudioProperties() override;
/*! /*!
* Returns the length of the file in seconds. The length is rounded down to * Returns the length of the file in seconds. The length is rounded down to the nearest whole second.
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual int lengthInSeconds() const override;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual int lengthInMilliseconds() const override;
int lengthInMilliseconds() const;
/*! /*!
* Returns the average bit rate of the file in kb/s. * Returns the average bit rate of the file in kb/s.
*/ */
virtual int bitrate() const; int bitrate() const override;
/*! /*!
* Returns the sample rate in Hz. * Returns the sample rate in Hz.
*/ */
virtual int sampleRate() const; int sampleRate() const override;
/*! /*!
* Returns the number of audio channels. * Returns the number of audio channels.
*/ */
virtual int channels() const; int channels() const override;
/*! /*!
* Returns the number of bits per audio sample. * Returns the number of bits per audio sample.
@@ -107,16 +92,17 @@ namespace TagLib {
*/ */
Codec codec() const; Codec codec() const;
String toString() const override;
private: private:
void read(File *file, Atoms *atoms); void read(File *file, Atoms *atoms);
class PropertiesPrivate; class AudioPropertiesPrivate;
PropertiesPrivate *d; AudioPropertiesPrivate *d;
}; };
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,35 +23,29 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include "tdebug.h"
#include <tstring.h> #include "tstring.h"
#include <tpropertymap.h> #include "tpicturemap.h"
#include "tpropertymap.h"
#include "mp4atom.h" #include "mp4atom.h"
#include "mp4tag.h" #include "mp4tag.h"
#include "id3v1genres.h" #include "id3v1genres.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class MP4::Tag::TagPrivate class MP4::Tag::TagPrivate {
{
public: public:
TagPrivate() : explicit TagPrivate() : file(nullptr), atoms(nullptr) {}
file(0),
atoms(0) {}
Strawberry_TagLib::TagLib::File *file; Strawberry_TagLib::TagLib::File *file;
Atoms *atoms; Atoms *atoms;
ItemMap items; ItemMap items;
}; };
MP4::Tag::Tag() : MP4::Tag::Tag() : d(new TagPrivate()) {}
d(new TagPrivate())
{ MP4::Tag::Tag(Strawberry_TagLib::TagLib::File *file, MP4::Atoms *atoms) : d(new TagPrivate()) {
}
MP4::Tag::Tag(Strawberry_TagLib::TagLib::File *file, MP4::Atoms *atoms) :
d(new TagPrivate())
{
d->file = file; d->file = file;
d->atoms = atoms; d->atoms = atoms;
@@ -83,8 +77,9 @@ MP4::Tag::Tag(Strawberry_TagLib::TagLib::File *file, MP4::Atoms *atoms) :
AtomData val = data[0]; AtomData val = data[0];
if (val.type == TypeUTF8) { if (val.type == TypeUTF8) {
addItem(atom->name, StringList(String(val.data, String::UTF8))); addItem(atom->name, StringList(String(val.data, String::UTF8)));
} else { }
addItem(atom->name, (int)(val.data.toShort())); else {
addItem(atom->name, static_cast<int>((val.data.toUInt16LE(0))));
} }
} }
} }
@@ -114,27 +109,25 @@ MP4::Tag::Tag(Strawberry_TagLib::TagLib::File *file, MP4::Atoms *atoms) :
} }
} }
MP4::Tag::~Tag() MP4::Tag::~Tag() {
{
delete d; delete d;
} }
MP4::AtomDataList MP4::AtomDataList MP4::Tag::parseData2(const MP4::Atom *atom, int expectedFlags, bool freeForm) {
MP4::Tag::parseData2(const MP4::Atom *atom, int expectedFlags, bool freeForm)
{
AtomDataList result; AtomDataList result;
ByteVector data = d->file->readBlock(atom->length - 8); ByteVector data = d->file->readBlock(atom->length - 8);
int i = 0; int i = 0;
unsigned int pos = 0; size_t pos = 0;
while (pos < data.size()) { while (pos < data.size()) {
const int length = static_cast<int>(data.toUInt(pos)); const int length = static_cast<int>(data.toUInt32BE(pos));
if (length < 12) { if (length < 12) {
debug("MP4: Too short atom"); debug("MP4: Too short atom");
return result; return result;
} }
const ByteVector name = data.mid(pos + 4, 4); const ByteVector name = data.mid(pos + 4, 4);
const int flags = static_cast<int>(data.toUInt(pos + 8)); const int flags = static_cast<int>(data.toUInt32BE(pos + 8));
if (freeForm && i < 2) { if (freeForm && i < 2) {
if (i == 0 && name != "mean") { if (i == 0 && name != "mean") {
debug("MP4: Unexpected atom \"" + name + "\", expecting \"mean\""); debug("MP4: Unexpected atom \"" + name + "\", expecting \"mean\"");
@@ -159,91 +152,91 @@ MP4::Tag::parseData2(const MP4::Atom *atom, int expectedFlags, bool freeForm)
i++; i++;
} }
return result; return result;
} }
ByteVectorList ByteVectorList MP4::Tag::parseData(const MP4::Atom *atom, int expectedFlags, bool freeForm) {
MP4::Tag::parseData(const MP4::Atom *atom, int expectedFlags, bool freeForm)
{
AtomDataList data = parseData2(atom, expectedFlags, freeForm); AtomDataList data = parseData2(atom, expectedFlags, freeForm);
ByteVectorList result; ByteVectorList result;
for (AtomDataList::ConstIterator it = data.begin(); it != data.end(); ++it) { for (AtomDataList::ConstIterator it = data.begin(); it != data.end(); ++it) {
result.append(it->data); result.append(it->data);
} }
return result; return result;
} }
void void MP4::Tag::parseInt(const MP4::Atom *atom) {
MP4::Tag::parseInt(const MP4::Atom *atom)
{
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
addItem(atom->name, (int)data[0].toShort()); addItem(atom->name, (int)data[0].toInt16BE(0));
}
} }
void }
MP4::Tag::parseUInt(const MP4::Atom *atom)
{ void MP4::Tag::parseUInt(const MP4::Atom *atom) {
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
addItem(atom->name, data[0].toUInt()); addItem(atom->name, data[0].toUInt32BE(0));
}
} }
void }
MP4::Tag::parseLongLong(const MP4::Atom *atom)
{ void MP4::Tag::parseLongLong(const MP4::Atom *atom) {
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
addItem(atom->name, data[0].toLongLong()); addItem(atom->name, data[0].toInt64BE(0));
}
} }
void }
MP4::Tag::parseByte(const MP4::Atom *atom)
{ void MP4::Tag::parseByte(const MP4::Atom *atom) {
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
addItem(atom->name, static_cast<unsigned char>(data[0].at(0))); addItem(atom->name, static_cast<unsigned char>(data[0].at(0)));
} }
} }
void void MP4::Tag::parseGnre(const MP4::Atom *atom) {
MP4::Tag::parseGnre(const MP4::Atom *atom)
{
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
int idx = (int)data[0].toShort(); int idx = static_cast<int>(data[0].toInt16BE(0));
if (idx > 0) { if (idx > 0) {
addItem("\251gen", StringList(ID3v1::genre(idx - 1))); addItem("\251gen", StringList(ID3v1::genre(idx - 1)));
} }
} }
} }
void void MP4::Tag::parseIntPair(const MP4::Atom *atom) {
MP4::Tag::parseIntPair(const MP4::Atom *atom)
{
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
const int a = data[0].toShort(2U); const int a = data[0].toInt16BE(2);
const int b = data[0].toShort(4U); const int b = data[0].toInt16BE(4);
addItem(atom->name, MP4::Item(a, b)); addItem(atom->name, MP4::Item(a, b));
} }
} }
void void MP4::Tag::parseBool(const MP4::Atom *atom) {
MP4::Tag::parseBool(const MP4::Atom *atom)
{
ByteVectorList data = parseData(atom); ByteVectorList data = parseData(atom);
if (!data.isEmpty()) { if (!data.isEmpty()) {
bool value = data[0].size() ? data[0][0] != '\0' : false; bool value = data[0].size() ? data[0][0] != '\0' : false;
addItem(atom->name, value); addItem(atom->name, value);
} }
} }
void void MP4::Tag::parseText(const MP4::Atom *atom, int expectedFlags) {
MP4::Tag::parseText(const MP4::Atom *atom, int expectedFlags)
{
ByteVectorList data = parseData(atom, expectedFlags); ByteVectorList data = parseData(atom, expectedFlags);
if (!data.isEmpty()) { if (!data.isEmpty()) {
StringList value; StringList value;
@@ -252,11 +245,11 @@ MP4::Tag::parseText(const MP4::Atom *atom, int expectedFlags)
} }
addItem(atom->name, value); addItem(atom->name, value);
} }
} }
void void MP4::Tag::parseFreeForm(const MP4::Atom *atom) {
MP4::Tag::parseFreeForm(const MP4::Atom *atom)
{
AtomDataList data = parseData2(atom, -1, true); AtomDataList data = parseData2(atom, -1, true);
if (data.size() > 2) { if (data.size() > 2) {
AtomDataList::ConstIterator itBegin = data.begin(); AtomDataList::ConstIterator itBegin = data.begin();
@@ -293,23 +286,24 @@ MP4::Tag::parseFreeForm(const MP4::Atom *atom)
addItem(name, item); addItem(name, item);
} }
} }
} }
void void MP4::Tag::parseCovr(const MP4::Atom *atom) {
MP4::Tag::parseCovr(const MP4::Atom *atom)
{
MP4::CoverArtList value; MP4::CoverArtList value;
ByteVector data = d->file->readBlock(atom->length - 8); ByteVector data = d->file->readBlock(atom->length - 8);
unsigned int pos = 0; unsigned int pos = 0;
while (pos < data.size()) { while (pos < data.size()) {
const int length = static_cast<int>(data.toUInt(pos)); const int length = static_cast<int>(data.toUInt32BE(pos));
if (length < 12) { if (length < 12) {
debug("MP4: Too short atom"); debug("MP4: Too short atom");
break;; break;
;
} }
const ByteVector name = data.mid(pos + 4, 4); const ByteVector name = data.mid(pos + 4, 4);
const int flags = static_cast<int>(data.toUInt(pos + 8)); const int flags = static_cast<int>(data.toUInt32BE(pos + 8));
if (name != "data") { if (name != "data") {
debug("MP4: Unexpected atom \"" + name + "\", expecting \"data\""); debug("MP4: Unexpected atom \"" + name + "\", expecting \"data\"");
break; break;
@@ -326,128 +320,125 @@ MP4::Tag::parseCovr(const MP4::Atom *atom)
} }
if (!value.isEmpty()) if (!value.isEmpty())
addItem(atom->name, value); addItem(atom->name, value);
} }
ByteVector ByteVector MP4::Tag::padIlst(const ByteVector &data, int length) const {
MP4::Tag::padIlst(const ByteVector &data, int length) const
{
if (length == -1) { if (length == -1) {
length = ((data.size() + 1023) & ~1023) - data.size(); length = ((data.size() + 1023) & ~1023) - data.size();
} }
return renderAtom("free", ByteVector(length, '\1')); return renderAtom("free", ByteVector(length, '\1'));
} }
ByteVector ByteVector MP4::Tag::renderAtom(const ByteVector &name, const ByteVector &data) const {
MP4::Tag::renderAtom(const ByteVector &name, const ByteVector &data) const return ByteVector::fromUInt32BE(data.size() + 8) + name + data;
{
return ByteVector::fromUInt(data.size() + 8) + name + data;
} }
ByteVector ByteVector MP4::Tag::renderData(const ByteVector &name, int flags, const ByteVectorList &data) const {
MP4::Tag::renderData(const ByteVector &name, int flags, const ByteVectorList &data) const
{
ByteVector result; ByteVector result;
for (ByteVectorList::ConstIterator it = data.begin(); it != data.end(); ++it) { for (ByteVectorList::ConstIterator it = data.begin(); it != data.end(); ++it) {
result.append(renderAtom("data", ByteVector::fromUInt(flags) + ByteVector(4, '\0') + *it)); result.append(renderAtom("data", ByteVector::fromUInt32BE(flags) + ByteVector(4, '\0') + *it));
} }
return renderAtom(name, result); return renderAtom(name, result);
} }
ByteVector ByteVector MP4::Tag::renderBool(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderBool(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector(1, item.toBool() ? '\1' : '\0')); data.append(ByteVector(1, item.toBool() ? '\1' : '\0'));
return renderData(name, TypeInteger, data); return renderData(name, TypeInteger, data);
} }
ByteVector ByteVector MP4::Tag::renderInt(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderInt(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector::fromShort(item.toInt())); data.append(ByteVector::fromUInt16BE(item.toInt()));
return renderData(name, TypeInteger, data); return renderData(name, TypeInteger, data);
} }
ByteVector ByteVector MP4::Tag::renderUInt(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderUInt(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector::fromUInt(item.toUInt())); data.append(ByteVector::fromUInt32BE(item.toUInt()));
return renderData(name, TypeInteger, data); return renderData(name, TypeInteger, data);
} }
ByteVector ByteVector MP4::Tag::renderLongLong(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderLongLong(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector::fromLongLong(item.toLongLong())); data.append(ByteVector::fromUInt64BE(item.toLongLong()));
return renderData(name, TypeInteger, data); return renderData(name, TypeInteger, data);
} }
ByteVector ByteVector MP4::Tag::renderByte(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderByte(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector(1, item.toByte())); data.append(ByteVector(1, item.toByte()));
return renderData(name, TypeInteger, data); return renderData(name, TypeInteger, data);
} }
ByteVector ByteVector MP4::Tag::renderIntPair(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderIntPair(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector(2, '\0') + data.append(ByteVector(2, '\0') +
ByteVector::fromShort(item.toIntPair().first) + ByteVector::fromUInt16BE(item.toIntPair().first) +
ByteVector::fromShort(item.toIntPair().second) + ByteVector::fromUInt16BE(item.toIntPair().second) +
ByteVector(2, '\0')); ByteVector(2, '\0'));
return renderData(name, TypeImplicit, data); return renderData(name, TypeImplicit, data);
} }
ByteVector ByteVector MP4::Tag::renderIntPairNoTrailing(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderIntPairNoTrailing(const ByteVector &name, const MP4::Item &item) const
{
ByteVectorList data; ByteVectorList data;
data.append(ByteVector(2, '\0') + data.append(ByteVector(2, '\0') +
ByteVector::fromShort(item.toIntPair().first) + ByteVector::fromUInt16BE(item.toIntPair().first) +
ByteVector::fromShort(item.toIntPair().second)); ByteVector::fromUInt16BE(item.toIntPair().second));
return renderData(name, TypeImplicit, data); return renderData(name, TypeImplicit, data);
} }
ByteVector ByteVector MP4::Tag::renderText(const ByteVector &name, const MP4::Item &item, int flags) const {
MP4::Tag::renderText(const ByteVector &name, const MP4::Item &item, int flags) const
{
ByteVectorList data; ByteVectorList data;
StringList value = item.toStringList(); StringList value = item.toStringList();
for (StringList::ConstIterator it = value.begin(); it != value.end(); ++it) { for (StringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
data.append(it->data(String::UTF8)); data.append(it->data(String::UTF8));
} }
return renderData(name, flags, data); return renderData(name, flags, data);
} }
ByteVector ByteVector MP4::Tag::renderCovr(const ByteVector &name, const MP4::Item &item) const {
MP4::Tag::renderCovr(const ByteVector &name, const MP4::Item &item) const
{
ByteVector data; ByteVector data;
MP4::CoverArtList value = item.toCoverArtList(); MP4::CoverArtList value = item.toCoverArtList();
for (MP4::CoverArtList::ConstIterator it = value.begin(); it != value.end(); ++it) { for (MP4::CoverArtList::ConstIterator it = value.begin(); it != value.end(); ++it) {
data.append(renderAtom("data", ByteVector::fromUInt(it->format()) + data.append(renderAtom("data", ByteVector::fromUInt32BE(it->format()) + ByteVector(4, '\0') + it->data()));
ByteVector(4, '\0') + it->data()));
} }
return renderAtom(name, data); return renderAtom(name, data);
} }
ByteVector ByteVector MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const {
MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const
{
StringList header = StringList::split(name, ":"); StringList header = StringList::split(name, ":");
if (header.size() != 3) { if (header.size() != 3) {
debug("MP4: Invalid free-form item name \"" + name + "\""); debug("MP4: Invalid free-form item name \"" + name + "\"");
return ByteVector(); return ByteVector();
} }
ByteVector data; ByteVector data;
data.append(renderAtom("mean", ByteVector::fromUInt(0) + header[1].data(String::UTF8))); data.append(renderAtom("mean", ByteVector::fromUInt32BE(0) + header[1].data(String::UTF8)));
data.append(renderAtom("name", ByteVector::fromUInt(0) + header[2].data(String::UTF8))); data.append(renderAtom("name", ByteVector::fromUInt32BE(0) + header[2].data(String::UTF8)));
AtomDataType type = item.atomDataType(); AtomDataType type = item.atomDataType();
if (type == TypeUndefined) { if (type == TypeUndefined) {
if (!item.toStringList().isEmpty()) { if (!item.toStringList().isEmpty()) {
@@ -460,21 +451,21 @@ MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const
if (type == TypeUTF8) { if (type == TypeUTF8) {
StringList value = item.toStringList(); StringList value = item.toStringList();
for (StringList::ConstIterator it = value.begin(); it != value.end(); ++it) { for (StringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + it->data(String::UTF8))); data.append(renderAtom("data", ByteVector::fromUInt32BE(type) + ByteVector(4, '\0') + it->data(String::UTF8)));
} }
} }
else { else {
ByteVectorList value = item.toByteVectorList(); ByteVectorList value = item.toByteVectorList();
for (ByteVectorList::ConstIterator it = value.begin(); it != value.end(); ++it) { for (ByteVectorList::ConstIterator it = value.begin(); it != value.end(); ++it) {
data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + *it)); data.append(renderAtom("data", ByteVector::fromUInt32BE(type) + ByteVector(4, '\0') + *it));
} }
} }
return renderAtom("----", data); return renderAtom("----", data);
} }
bool bool MP4::Tag::save() {
MP4::Tag::save()
{
ByteVector data; ByteVector data;
for (MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) { for (MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) {
const String name = it->first; const String name = it->first;
@@ -539,11 +530,11 @@ MP4::Tag::save()
} }
return true; return true;
} }
void void MP4::Tag::updateParents(const AtomList &path, long delta, int ignore) {
MP4::Tag::updateParents(const AtomList &path, long delta, int ignore)
{
if (static_cast<int>(path.size()) <= ignore) if (static_cast<int>(path.size()) <= ignore)
return; return;
@@ -552,26 +543,25 @@ MP4::Tag::updateParents(const AtomList &path, long delta, int ignore)
for (AtomList::ConstIterator it = path.begin(); it != itEnd; ++it) { for (AtomList::ConstIterator it = path.begin(); it != itEnd; ++it) {
d->file->seek((*it)->offset); d->file->seek((*it)->offset);
long size = d->file->readBlock(4).toUInt(); long size = d->file->readBlock(4).toUInt32BE(0);
// 64-bit // 64-bit
if (size == 1) { if (size == 1) {
d->file->seek(4, File::Current); // Skip name d->file->seek(4, File::Current); // Skip name
long long longSize = d->file->readBlock(8).toLongLong(); long long longSize = d->file->readBlock(8).toInt64BE(0);
// Seek the offset of the 64-bit size // Seek the offset of the 64-bit size
d->file->seek((*it)->offset + 8); d->file->seek((*it)->offset + 8);
d->file->writeBlock(ByteVector::fromLongLong(longSize + delta)); d->file->writeBlock(ByteVector::fromUInt64BE(longSize + delta));
} }
// 32-bit // 32-bit
else { else {
d->file->seek((*it)->offset); d->file->seek((*it)->offset);
d->file->writeBlock(ByteVector::fromUInt(size + delta)); d->file->writeBlock(ByteVector::fromUInt32BE(size + delta));
} }
} }
} }
void void MP4::Tag::updateOffsets(long delta, long long offset) {
MP4::Tag::updateOffsets(long delta, long offset)
{
MP4::Atom *moov = d->atoms->find("moov"); MP4::Atom *moov = d->atoms->find("moov");
if (moov) { if (moov) {
MP4::AtomList stco = moov->findall("stco", true); MP4::AtomList stco = moov->findall("stco", true);
@@ -582,15 +572,15 @@ MP4::Tag::updateOffsets(long delta, long offset)
} }
d->file->seek(atom->offset + 12); d->file->seek(atom->offset + 12);
ByteVector data = d->file->readBlock(atom->length - 12); ByteVector data = d->file->readBlock(atom->length - 12);
unsigned int count = data.toUInt(); unsigned int count = data.toUInt32BE(0);
d->file->seek(atom->offset + 16); d->file->seek(atom->offset + 16);
unsigned int pos = 4; size_t pos = 4;
while (count--) { while (count--) {
long o = static_cast<long>(data.toUInt(pos)); long o = data.toUInt32BE(pos);
if (o > offset) { if (o > offset) {
o += delta; o += delta;
} }
d->file->writeBlock(ByteVector::fromUInt(o)); d->file->writeBlock(ByteVector::fromUInt32BE(o));
pos += 4; pos += 4;
} }
} }
@@ -603,15 +593,15 @@ MP4::Tag::updateOffsets(long delta, long offset)
} }
d->file->seek(atom->offset + 12); d->file->seek(atom->offset + 12);
ByteVector data = d->file->readBlock(atom->length - 12); ByteVector data = d->file->readBlock(atom->length - 12);
unsigned int count = data.toUInt(); unsigned int count = data.toUInt32BE(0);
d->file->seek(atom->offset + 16); d->file->seek(atom->offset + 16);
unsigned int pos = 4; size_t pos = 4;
while (count--) { while (count--) {
long long o = data.toLongLong(pos); long long o = data.toInt64BE(pos);
if (o > offset) { if (o > offset) {
o += delta; o += delta;
} }
d->file->writeBlock(ByteVector::fromLongLong(o)); d->file->writeBlock(ByteVector::fromUInt64BE(o));
pos += 8; pos += 8;
} }
} }
@@ -627,26 +617,23 @@ MP4::Tag::updateOffsets(long delta, long offset)
} }
d->file->seek(atom->offset + 9); d->file->seek(atom->offset + 9);
ByteVector data = d->file->readBlock(atom->length - 9); ByteVector data = d->file->readBlock(atom->length - 9);
const unsigned int flags = data.toUInt(0, 3, true); const unsigned int flags = data.toUInt24BE(0);
if (flags & 1) { if (flags & 1) {
long long o = data.toLongLong(7U); long long o = data.toInt64BE(7);
if (o > offset) { if (o > offset) {
o += delta; o += delta;
} }
d->file->seek(atom->offset + 16); d->file->seek(atom->offset + 16);
d->file->writeBlock(ByteVector::fromLongLong(o)); d->file->writeBlock(ByteVector::fromUInt64BE(o));
}
} }
} }
} }
void }
MP4::Tag::saveNew(ByteVector data)
{ void MP4::Tag::saveNew(ByteVector data) {
data = renderAtom("meta", ByteVector(4, '\0') +
renderAtom("hdlr", ByteVector(8, '\0') + ByteVector("mdirappl") + data = renderAtom("meta", ByteVector(4, '\0') + renderAtom("hdlr", ByteVector(8, '\0') + ByteVector("mdirappl") + ByteVector(9, '\0')) + data + padIlst(data));
ByteVector(9, '\0')) +
data + padIlst(data));
AtomList path = d->atoms->path("moov", "udta"); AtomList path = d->atoms->path("moov", "udta");
if (path.size() != 2) { if (path.size() != 2) {
@@ -654,7 +641,7 @@ MP4::Tag::saveNew(ByteVector data)
data = renderAtom("udta", data); data = renderAtom("udta", data);
} }
long offset = path.back()->offset + 8; long long offset = path.back()->offset + 8;
d->file->insert(data, offset, 0); d->file->insert(data, offset, 0);
updateParents(path, data.size()); updateParents(path, data.size());
@@ -664,16 +651,16 @@ MP4::Tag::saveNew(ByteVector data)
d->file->seek(offset); d->file->seek(offset);
path.back()->children.prepend(new Atom(d->file)); path.back()->children.prepend(new Atom(d->file));
} }
void void MP4::Tag::saveExisting(ByteVector data, const AtomList &path) {
MP4::Tag::saveExisting(ByteVector data, const AtomList &path)
{
AtomList::ConstIterator it = path.end(); AtomList::ConstIterator it = path.end();
MP4::Atom *ilst = *(--it); MP4::Atom *ilst = *(--it);
long offset = ilst->offset; long long offset = ilst->offset;
long length = ilst->length; long long length = ilst->length;
MP4::Atom *meta = *(--it); MP4::Atom *meta = *(--it);
AtomList::ConstIterator index = meta->children.find(ilst); AtomList::ConstIterator index = meta->children.find(ilst);
@@ -704,7 +691,7 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path)
delta = data.size() - length; delta = data.size() - length;
} }
else if (delta < 0) { else if (delta < 0) {
data.append(padIlst(data, -delta - 8)); data.append(padIlst(data, 0 - delta - 8));
delta = 0; delta = 0;
} }
@@ -714,153 +701,193 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path)
updateParents(path, delta, 1); updateParents(path, delta, 1);
updateOffsets(delta, offset); updateOffsets(delta, offset);
} }
} }
String String MP4::Tag::title() const {
MP4::Tag::title() const
{
if (d->items.contains("\251nam")) if (d->items.contains("\251nam"))
return d->items["\251nam"].toStringList().toString(", "); return d->items["\251nam"].toStringList().toString(", ");
return String(); return String();
} }
String String MP4::Tag::artist() const {
MP4::Tag::artist() const
{
if (d->items.contains("\251ART")) if (d->items.contains("\251ART"))
return d->items["\251ART"].toStringList().toString(", "); return d->items["\251ART"].toStringList().toString(", ");
return String(); return String();
} }
String String MP4::Tag::album() const {
MP4::Tag::album() const
{
if (d->items.contains("\251alb")) if (d->items.contains("\251alb"))
return d->items["\251alb"].toStringList().toString(", "); return d->items["\251alb"].toStringList().toString(", ");
return String(); return String();
} }
String String MP4::Tag::comment() const {
MP4::Tag::comment() const
{
if (d->items.contains("\251cmt")) if (d->items.contains("\251cmt"))
return d->items["\251cmt"].toStringList().toString(", "); return d->items["\251cmt"].toStringList().toString(", ");
return String(); return String();
} }
String String MP4::Tag::genre() const {
MP4::Tag::genre() const
{
if (d->items.contains("\251gen")) if (d->items.contains("\251gen"))
return d->items["\251gen"].toStringList().toString(", "); return d->items["\251gen"].toStringList().toString(", ");
return String(); return String();
} }
unsigned int unsigned int MP4::Tag::year() const {
MP4::Tag::year() const
{
if (d->items.contains("\251day")) if (d->items.contains("\251day"))
return d->items["\251day"].toStringList().toString().toInt(); return d->items["\251day"].toStringList().toString().toInt();
return 0; return 0;
} }
unsigned int unsigned int MP4::Tag::track() const {
MP4::Tag::track() const
{
if (d->items.contains("trkn")) if (d->items.contains("trkn"))
return d->items["trkn"].toIntPair().first; return d->items["trkn"].toIntPair().first;
return 0; return 0;
} }
void PictureMap MP4::Tag::pictures() const {
MP4::Tag::setTitle(const String &value)
{ if (!d->items.contains("covr"))
return PictureMap();
CoverArtList list = d->items["covr"].toCoverArtList();
if (list.isEmpty())
return PictureMap();
PictureMap map;
for (CoverArtList::ConstIterator it = list.begin(); it != list.end(); ++it) {
CoverArt art = *it;
String mime = "image/";
switch (art.format()) {
case CoverArt::BMP:
mime.append("bmp");
break;
case CoverArt::JPEG:
mime.append("jpeg");
break;
case CoverArt::GIF:
mime.append("gif");
break;
case CoverArt::PNG:
mime.append("png");
break;
case CoverArt::Unknown:
break;
}
Picture picture(art.data(), Picture::Other, mime);
map.insert(picture);
}
return PictureMap(map);
}
void MP4::Tag::setTitle(const String &value) {
d->items["\251nam"] = StringList(value); d->items["\251nam"] = StringList(value);
} }
void void MP4::Tag::setArtist(const String &value) {
MP4::Tag::setArtist(const String &value)
{
d->items["\251ART"] = StringList(value); d->items["\251ART"] = StringList(value);
} }
void void MP4::Tag::setAlbum(const String &value) {
MP4::Tag::setAlbum(const String &value)
{
d->items["\251alb"] = StringList(value); d->items["\251alb"] = StringList(value);
} }
void void MP4::Tag::setComment(const String &value) {
MP4::Tag::setComment(const String &value)
{
d->items["\251cmt"] = StringList(value); d->items["\251cmt"] = StringList(value);
} }
void void MP4::Tag::setGenre(const String &value) {
MP4::Tag::setGenre(const String &value)
{
d->items["\251gen"] = StringList(value); d->items["\251gen"] = StringList(value);
} }
void void MP4::Tag::setYear(unsigned int value) {
MP4::Tag::setYear(unsigned int value)
{
if (value == 0) { if (value == 0) {
d->items.erase("\251day"); d->items.erase("\251day");
} }
else { else {
d->items["\251day"] = StringList(String::number(value)); d->items["\251day"] = StringList(String::number(value));
} }
} }
void void MP4::Tag::setTrack(unsigned int value) {
MP4::Tag::setTrack(unsigned int value)
{
if (value == 0) { if (value == 0) {
d->items.erase("trkn"); d->items.erase("trkn");
} }
else { else {
d->items["trkn"] = MP4::Item(value, 0); d->items["trkn"] = MP4::Item(value, 0);
} }
} }
bool MP4::Tag::isEmpty() const void MP4::Tag::setPictures(const PictureMap &l) {
{
CoverArtList list;
for (PictureMap::ConstIterator pictureMapIt = l.begin(); pictureMapIt != l.end(); ++pictureMapIt) {
PictureList pictures = pictureMapIt->second;
for (PictureList::ConstIterator pictureListIt = pictures.begin(); pictureListIt != pictures.end(); ++pictureListIt) {
Picture picture = *pictureListIt;
CoverArt::Format format;
String mime = picture.mime();
if (String("image/") == mime)
format = CoverArt::Unknown;
else if (String("image/bmp") == mime)
format = CoverArt::BMP;
else if (String("image/png") == mime)
format = CoverArt::PNG;
else if (String("image/gif") == mime)
format = CoverArt::GIF;
else if (String("image/jpeg") == mime)
format = CoverArt::JPEG;
else
format = CoverArt::Unknown;
CoverArt art(format, picture.data());
list.append(art);
}
}
d->items["covr"] = list;
}
bool MP4::Tag::isEmpty() const {
return d->items.isEmpty(); return d->items.isEmpty();
} }
MP4::ItemMap &MP4::Tag::itemListMap() const MP4::ItemMap &MP4::Tag::itemMap() const {
{
return d->items; return d->items;
} }
const MP4::ItemMap &MP4::Tag::itemMap() const MP4::Item MP4::Tag::item(const String &key) const {
{
return d->items;
}
MP4::Item MP4::Tag::item(const String &key) const
{
return d->items[key]; return d->items[key];
} }
void MP4::Tag::setItem(const String &key, const Item &value) void MP4::Tag::setItem(const String &key, const Item &value) {
{
d->items[key] = value; d->items[key] = value;
} }
void MP4::Tag::removeItem(const String &key) void MP4::Tag::removeItem(const String &key) {
{
d->items.erase(key); d->items.erase(key);
} }
bool MP4::Tag::contains(const String &key) const bool MP4::Tag::contains(const String &key) const {
{
return d->items.contains(key); return d->items.contains(key);
} }
namespace String MP4::Tag::toString() const {
{
StringList desc;
for (MP4::ItemListMap::Iterator i = d->items.begin(); i != d->items.end(); i++) {
desc.append(i->first + "=" + i->second.toString());
}
return desc.toString("\n");
}
namespace {
const char *keyTranslation[][2] = { const char *keyTranslation[][2] = {
{ "\251nam", "TITLE" }, { "\251nam", "TITLE" },
{ "\251ART", "ARTIST" }, { "\251ART", "ARTIST" },
@@ -917,19 +944,20 @@ namespace
}; };
const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]); const size_t keyTranslationSize = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
String translateKey(const String &key) String translateKey(const String &key) {
{
for (size_t i = 0; i < keyTranslationSize; ++i) { for (size_t i = 0; i < keyTranslationSize; ++i) {
if (key == keyTranslation[i][0]) if (key == keyTranslation[i][0])
return keyTranslation[i][1]; return keyTranslation[i][1];
} }
return String(); return String();
}
}
PropertyMap MP4::Tag::properties() const }
{ } // namespace
PropertyMap MP4::Tag::properties() const {
PropertyMap props; PropertyMap props;
for (MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) { for (MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) {
const String key = translateKey(it->first); const String key = translateKey(it->first);
@@ -957,16 +985,18 @@ PropertyMap MP4::Tag::properties() const
} }
} }
return props; return props;
} }
void MP4::Tag::removeUnsupportedProperties(const StringList &props) void MP4::Tag::removeUnsupportedProperties(const StringList &props) {
{
for (StringList::ConstIterator it = props.begin(); it != props.end(); ++it) for (StringList::ConstIterator it = props.begin(); it != props.end(); ++it)
d->items.erase(*it); d->items.erase(*it);
} }
PropertyMap MP4::Tag::setProperties(const PropertyMap &props) PropertyMap MP4::Tag::setProperties(const PropertyMap &props) {
{
static Map<String, String> reverseKeyMap; static Map<String, String> reverseKeyMap;
if (reverseKeyMap.isEmpty()) { if (reverseKeyMap.isEmpty()) {
int numKeys = sizeof(keyTranslation) / sizeof(keyTranslation[0]); int numKeys = sizeof(keyTranslation) / sizeof(keyTranslation[0]);
@@ -1015,14 +1045,16 @@ PropertyMap MP4::Tag::setProperties(const PropertyMap &props)
} }
return ignoredProps; return ignoredProps;
} }
void MP4::Tag::addItem(const String &name, const Item &value) void MP4::Tag::addItem(const String &name, const Item &value) {
{
if (!d->items.contains(name)) { if (!d->items.contains(name)) {
d->items.insert(name, value); d->items.insert(name, value);
} }
else { else {
debug("MP4: Ignoring duplicate atom \"" + name + "\""); debug("MP4: Ignoring duplicate atom \"" + name + "\"");
} }
} }

View File

@@ -37,46 +37,37 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace MP4 { namespace MP4 {
/*!
* \deprecated
*/
TAGLIB_DEPRECATED typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemListMap;
typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemMap; typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemMap;
typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemListMap;
class TAGLIB_EXPORT Tag: public Strawberry_TagLib::TagLib::Tag class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
{
public: public:
Tag(); explicit Tag();
Tag(Strawberry_TagLib::TagLib::File *file, Atoms *atoms); explicit Tag(Strawberry_TagLib::TagLib::File *file, Atoms *atoms);
virtual ~Tag(); ~Tag() override;
bool save(); bool save();
virtual String title() const; String title() const override;
virtual String artist() const; String artist() const override;
virtual String album() const; String album() const override;
virtual String comment() const; String comment() const override;
virtual String genre() const; String genre() const override;
virtual unsigned int year() const; unsigned int year() const override;
virtual unsigned int track() const; unsigned int track() const override;
PictureMap pictures() const override;
virtual void setTitle(const String &value); void setTitle(const String &value) override;
virtual void setArtist(const String &value); void setArtist(const String &value) override;
virtual void setAlbum(const String &value); void setAlbum(const String &value) override;
virtual void setComment(const String &value); void setComment(const String &value) override;
virtual void setGenre(const String &value); void setGenre(const String &value) override;
virtual void setYear(unsigned int value); void setYear(unsigned int value) override;
virtual void setTrack(unsigned int value); void setTrack(unsigned int value) override;
void setPictures(const PictureMap &l) override;
virtual bool isEmpty() const;
/*!
* \deprecated Use the item() and setItem() API instead
*/
TAGLIB_DEPRECATED ItemMap &itemListMap();
bool isEmpty() const override;
/*! /*!
* Returns a string-keyed map of the MP4::Items for this tag. * Returns a string-keyed map of the MP4::Items for this tag.
*/ */
@@ -93,8 +84,7 @@ namespace TagLib {
void setItem(const String &key, const Item &value); void setItem(const String &key, const Item &value);
/*! /*!
* Removes the entry with \a key from the tag, or does nothing if it does * Removes the entry with \a key from the tag, or does nothing if it does not exist.
* not exist.
*/ */
void removeItem(const String &key); void removeItem(const String &key);
@@ -103,15 +93,15 @@ namespace TagLib {
*/ */
bool contains(const String &key) const; bool contains(const String &key) const;
PropertyMap properties() const; String toString() const override;
void removeUnsupportedProperties(const StringList& properties);
PropertyMap setProperties(const PropertyMap &properties); PropertyMap properties() const override;
void removeUnsupportedProperties(const StringList &props) override;
PropertyMap setProperties(const PropertyMap &props) override;
private: private:
AtomDataList parseData2(const Atom *atom, int expectedFlags = -1, AtomDataList parseData2(const Atom *atom, int expectedFlags = -1, bool freeForm = false);
bool freeForm = false); ByteVectorList parseData(const Atom *atom, int expectedFlags = -1, bool freeForm = false);
ByteVectorList parseData(const Atom *atom, int expectedFlags = -1,
bool freeForm = false);
void parseText(const Atom *atom, int expectedFlags = 1); void parseText(const Atom *atom, int expectedFlags = 1);
void parseFreeForm(const Atom *atom); void parseFreeForm(const Atom *atom);
void parseInt(const Atom *atom); void parseInt(const Atom *atom);
@@ -125,10 +115,8 @@ namespace TagLib {
ByteVector padIlst(const ByteVector &data, int length = -1) const; ByteVector padIlst(const ByteVector &data, int length = -1) const;
ByteVector renderAtom(const ByteVector &name, const ByteVector &data) const; ByteVector renderAtom(const ByteVector &name, const ByteVector &data) const;
ByteVector renderData(const ByteVector &name, int flags, ByteVector renderData(const ByteVector &name, int flags, const ByteVectorList &data) const;
const ByteVectorList &data) const; ByteVector renderText(const ByteVector &name, const Item &item, int flags = TypeUTF8) const;
ByteVector renderText(const ByteVector &name, const Item &item,
int flags = TypeUTF8) const;
ByteVector renderFreeForm(const String &name, const Item &item) const; ByteVector renderFreeForm(const String &name, const Item &item) const;
ByteVector renderBool(const ByteVector &name, const Item &item) const; ByteVector renderBool(const ByteVector &name, const Item &item) const;
ByteVector renderInt(const ByteVector &name, const Item &item) const; ByteVector renderInt(const ByteVector &name, const Item &item) const;
@@ -140,7 +128,7 @@ namespace TagLib {
ByteVector renderCovr(const ByteVector &name, const Item &item) const; ByteVector renderCovr(const ByteVector &name, const Item &item) const;
void updateParents(const AtomList &path, long delta, int ignore = 0); void updateParents(const AtomList &path, long delta, int ignore = 0);
void updateOffsets(long delta, long offset); void updateOffsets(long delta, long long offset);
void saveNew(ByteVector data); void saveNew(ByteVector data);
void saveExisting(ByteVector data, const AtomList &path); void saveExisting(ByteVector data, const AtomList &path);
@@ -151,9 +139,8 @@ namespace TagLib {
TagPrivate *d; TagPrivate *d;
}; };
} } // namespace MP4
} // namespace TagLib
} } // namespace Strawberry_TagLib
}
#endif #endif

View File

@@ -23,12 +23,14 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevector.h> #include <memory>
#include <tstring.h>
#include <tagunion.h> #include "tbytevector.h"
#include <tdebug.h> #include "tstring.h"
#include <tpropertymap.h> #include "tagunion.h"
#include <tagutils.h> #include "tdebug.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "mpcfile.h" #include "mpcfile.h"
#include "id3v1tag.h" #include "id3v1tag.h"
@@ -38,111 +40,86 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{ enum { MPCAPEIndex = 0,
enum { MPCAPEIndex = 0, MPCID3v1Index = 1 }; MPCID3v1Index = 1 };
} }
class MPC::File::FilePrivate class MPC::File::FilePrivate {
{
public: public:
FilePrivate() : explicit FilePrivate() : APELocation(-1),
APELocation(-1),
APESize(0), APESize(0),
ID3v1Location(-1), ID3v1Location(-1),
ID3v2Header(0),
ID3v2Location(-1), ID3v2Location(-1),
ID3v2Size(0), ID3v2Size(0) {}
properties(0) {}
~FilePrivate() long long APELocation;
{ long long APESize;
delete ID3v2Header;
delete properties;
}
long APELocation; long long ID3v1Location;
long APESize;
long ID3v1Location; std::unique_ptr<ID3v2::Header> ID3v2Header;
long long ID3v2Location;
long long ID3v2Size;
ID3v2::Header *ID3v2Header; DoubleTagUnion tag;
long ID3v2Location;
long ID3v2Size;
TagUnion tag; std::unique_ptr<AudioProperties> properties;
Properties *properties;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// static members // static members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool MPC::File::isSupported(IOStream *stream) bool MPC::File::isSupported(IOStream *stream) {
{
// A newer MPC file has to start with "MPCK" or "MP+", but older files don't // A newer MPC file has to start with "MPCK" or "MP+", but older files don't
// have keys to do a quick check. // have keys to do a quick check.
const ByteVector id = Utils::readHeader(stream, 4, false); const ByteVector id = Utils::readHeader(stream, 4, false);
return (id == "MPCK" || id.startsWith("MP+")); return (id == "MPCK" || id.startsWith("MP+"));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MPC::File::File(FileName file, bool readProperties, Properties::ReadStyle) : MPC::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(file), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(file),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
MPC::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) : MPC::File::File(IOStream *stream, bool readProperties, AudioProperties::ReadStyle) : Strawberry_TagLib::TagLib::File(stream), d(new FilePrivate()) {
Strawberry_TagLib::TagLib::File(stream),
d(new FilePrivate())
{
if (isOpen()) if (isOpen())
read(readProperties); read(readProperties);
} }
MPC::File::~File() MPC::File::~File() {
{
delete d; delete d;
} }
Strawberry_TagLib::TagLib::Tag *MPC::File::tag() const Strawberry_TagLib::TagLib::Tag *MPC::File::tag() const {
{
return &d->tag; return &d->tag;
} }
PropertyMap MPC::File::properties() const PropertyMap MPC::File::setProperties(const PropertyMap &properties) {
{
return d->tag.properties();
}
void MPC::File::removeUnsupportedProperties(const StringList &properties)
{
d->tag.removeUnsupportedProperties(properties);
}
PropertyMap MPC::File::setProperties(const PropertyMap &properties)
{
if (ID3v1Tag()) if (ID3v1Tag())
ID3v1Tag()->setProperties(properties); ID3v1Tag()->setProperties(properties);
return APETag(true)->setProperties(properties); return APETag(true)->setProperties(properties);
} }
MPC::Properties *MPC::File::audioProperties() const MPC::AudioProperties *MPC::File::audioProperties() const {
{ return d->properties.get();
return d->properties;
} }
bool MPC::File::save() bool MPC::File::save() {
{
if (readOnly()) { if (readOnly()) {
debug("MPC::File::save() -- File is read only."); debug("MPC::File::save() -- File is read only.");
return false; return false;
@@ -226,47 +203,37 @@ bool MPC::File::save()
} }
return true; return true;
} }
ID3v1::Tag *MPC::File::ID3v1Tag(bool create) ID3v1::Tag *MPC::File::ID3v1Tag(bool create) {
{
return d->tag.access<ID3v1::Tag>(MPCID3v1Index, create); return d->tag.access<ID3v1::Tag>(MPCID3v1Index, create);
} }
APE::Tag *MPC::File::APETag(bool create) APE::Tag *MPC::File::APETag(bool create) {
{
return d->tag.access<APE::Tag>(MPCAPEIndex, create); return d->tag.access<APE::Tag>(MPCAPEIndex, create);
} }
void MPC::File::strip(int tags) void MPC::File::strip(int tags) {
{
if (tags & ID3v1) if (tags & ID3v1)
d->tag.set(MPCID3v1Index, 0); d->tag.set(MPCID3v1Index, nullptr);
if (tags & APE) if (tags & APE)
d->tag.set(MPCAPEIndex, 0); d->tag.set(MPCAPEIndex, nullptr);
if (!ID3v1Tag()) if (!ID3v1Tag())
APETag(true); APETag(true);
if(tags & ID3v2) { if (tags & ID3v2)
delete d->ID3v2Header; d->ID3v2Header.reset();
d->ID3v2Header = 0;
}
} }
void MPC::File::remove(int tags) bool MPC::File::hasID3v1Tag() const {
{
strip(tags);
}
bool MPC::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0); return (d->ID3v1Location >= 0);
} }
bool MPC::File::hasAPETag() const bool MPC::File::hasAPETag() const {
{
return (d->APELocation >= 0); return (d->APELocation >= 0);
} }
@@ -274,15 +241,15 @@ bool MPC::File::hasAPETag() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void MPC::File::read(bool readProperties) void MPC::File::read(bool readProperties) {
{
// Look for an ID3v2 tag // Look for an ID3v2 tag
d->ID3v2Location = Utils::findID3v2(this); d->ID3v2Location = Utils::findID3v2(this);
if (d->ID3v2Location >= 0) { if (d->ID3v2Location >= 0) {
seek(d->ID3v2Location); seek(d->ID3v2Location);
d->ID3v2Header = new ID3v2::Header(readBlock(ID3v2::Header::size())); d->ID3v2Header.reset(new ID3v2::Header(readBlock(ID3v2::Header::size())));
d->ID3v2Size = d->ID3v2Header->completeTagSize(); d->ID3v2Size = d->ID3v2Header->completeTagSize();
} }
@@ -310,7 +277,7 @@ void MPC::File::read(bool readProperties)
if (readProperties) { if (readProperties) {
long streamLength; long long streamLength;
if (d->APELocation >= 0) if (d->APELocation >= 0)
streamLength = d->APELocation; streamLength = d->APELocation;
@@ -327,6 +294,7 @@ void MPC::File::read(bool readProperties)
seek(0); seek(0);
} }
d->properties = new Properties(this, streamLength); d->properties.reset(new AudioProperties(this, streamLength));
} }
} }

View File

@@ -39,17 +39,21 @@ namespace TagLib {
class Tag; class Tag;
namespace ID3v1 { class Tag; } namespace ID3v1 {
namespace APE { class Tag; } class Tag;
}
namespace APE {
class Tag;
}
//! An implementation of MPC metadata //! An implementation of MPC metadata
/*! /*!
* This is implementation of MPC metadata. * This is implementation of MPC metadata.
* *
* This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream * This supports ID3v1 and APE (v1 and v2) style comments as well as reading stream properties from the file.
* properties from the file. ID3v2 tags are invalid in MPC-files, but will be skipped * ID3v2 tags are invalid in MPC-files, but will be skipped and ignored.
* and ignored. *
*/ */
namespace MPC { namespace MPC {
@@ -57,19 +61,14 @@ namespace TagLib {
//! An implementation of TagLib::File with MPC specific methods //! An implementation of TagLib::File with MPC specific methods
/*! /*!
* This implements and provides an interface for MPC files to the * This implements and provides an interface for MPC files to the TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing the abstract TagLib::File API as well as providing some additional information specific to MPC files.
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to MPC files.
* The only invalid tag combination supported is an ID3v1 tag after an APE tag. * The only invalid tag combination supported is an ID3v1 tag after an APE tag.
*/ */
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
{
public: public:
/*! /*!
* This set of flags is used for various operations and is suitable for * This set of flags is used for various operations and is suitable for being OR-ed together.
* being OR-ed together.
*/ */
enum TagTypes { enum TagTypes {
//! Empty set. Matches no tag types. //! Empty set. Matches no tag types.
@@ -85,80 +84,65 @@ namespace TagLib {
}; };
/*! /*!
* Constructs an MPC file from \a file. If \a readProperties is true the * Constructs an MPC file from \a file.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(FileName file, bool readProperties = true, explicit File(FileName file, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Constructs an MPC file from \a stream. If \a readProperties is true the * Constructs an MPC file from \a stream.
* file's audio properties will also be read. * If \a readProperties is true the file's audio properties will also be read.
* *
* \note TagLib will *not* take ownership of the stream, the caller is * \note TagLib will *not* take ownership of the stream, the caller is responsible for deleting it after the File object.
* responsible for deleting it after the File object.
* *
* \note In the current implementation, \a propertiesStyle is ignored. * \note In the current implementation, \a propertiesStyle is ignored.
*/ */
File(IOStream *stream, bool readProperties = true, explicit File(IOStream *stream, bool readProperties = true, AudioProperties::ReadStyle propertiesStyle = AudioProperties::Average);
Properties::ReadStyle propertiesStyle = Properties::Average);
/*! /*!
* Destroys this instance of the File. * Destroys this instance of the File.
*/ */
virtual ~File(); ~File() override;
/*! /*!
* Returns the Tag for this file. This will be an APE tag, an ID3v1 tag * Returns the Tag for this file.
* or a combination of the two. * This will be an APE tag, an ID3v1 tag or a combination of the two.
*/ */
virtual Strawberry_TagLib::TagLib::Tag *tag() const; Strawberry_TagLib::TagLib::Tag *tag() const override;
/*!
* Implements the unified property interface -- export function.
* If the file contains both an APE and an ID3v1 tag, only the APE
* tag will be converted to the PropertyMap.
*/
PropertyMap properties() const;
void removeUnsupportedProperties(const StringList &properties);
/*! /*!
* Implements the unified property interface -- import function. * Implements the unified property interface -- import function.
* Affects only the APEv2 tag which will be created if necessary. * Affects only the APEv2 tag which will be created if necessary.
* If an ID3v1 tag exists, it will be updated as well. * If an ID3v1 tag exists, it will be updated as well.
*/ */
PropertyMap setProperties(const PropertyMap &); PropertyMap setProperties(const PropertyMap &) override;
/*! /*!
* Returns the MPC::Properties for this file. If no audio properties * Returns the MPC::AudioProperties for this file.
* were read then this will return a null pointer. * If no audio properties were read then this will return a null pointer.
*/ */
virtual Properties *audioProperties() const; AudioProperties *audioProperties() const override;
/*! /*!
* Saves the file. * Saves the file.
* *
* This returns true if the save was successful. * This returns true if the save was successful.
*/ */
virtual bool save(); bool save() override;
/*! /*!
* Returns a pointer to the ID3v1 tag of the file. * Returns a pointer to the ID3v1 tag of the file.
* *
* If \a create is false (the default) this returns a null pointer * If \a create is false (the default) this returns a null pointer if there is no valid APE tag.
* if there is no valid APE tag. If \a create is true it will create * If \a create is true it will create an APE tag if one does not exist and returns a valid pointer.
* an APE tag if one does not exist and returns a valid pointer.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an ID3v1 tag.
* file on disk has an ID3v1 tag. Use hasID3v1Tag() to check if the file * Use hasID3v1Tag() to check if the file on disk actually has an ID3v1 tag.
* on disk actually has an ID3v1 tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasID3v1Tag() * \see hasID3v1Tag()
*/ */
@@ -168,39 +152,29 @@ namespace TagLib {
* Returns a pointer to the APE tag of the file. * Returns a pointer to the APE tag of the file.
* *
* If \a create is false (the default) this may return a null pointer * If \a create is false (the default) this may return a null pointer
* if there is no valid APE tag. If \a create is true it will create * if there is no valid APE tag.
* an APE tag if one does not exist and returns a valid pointer. If * If \a create is true it will create an APE tag if one does not exist and returns a valid pointer.
* there already be an ID3v1 tag, the new APE tag will be placed before it. * If there already be an ID3v1 tag, the new APE tag will be placed before it.
* *
* \note This may return a valid pointer regardless of whether or not the * \note This may return a valid pointer regardless of whether or not the file on disk has an APE tag.
* file on disk has an APE tag. Use hasAPETag() to check if the file * Use hasAPETag() to check if the file on disk actually has an APE tag.
* on disk actually has an APE tag.
* *
* \note The Tag <b>is still</b> owned by the MPEG::File and should not be * \note The Tag <b>is still</b> owned by the MPEG::File and should not be deleted by the user.
* deleted by the user. It will be deleted when the file (object) is * It will be deleted when the file (object) is destroyed.
* destroyed.
* *
* \see hasAPETag() * \see hasAPETag()
*/ */
APE::Tag *APETag(bool create = false); APE::Tag *APETag(bool create = false);
/*! /*!
* This will remove the tags that match the OR-ed together TagTypes from the * This will remove the tags that match the OR-ed together TagTypes from the file. By default it removes all tags.
* file. By default it removes all tags.
* *
* \warning This will also invalidate pointers to the tags * \warning This will also invalidate pointers to the tags as their memory will be freed.
* as their memory will be freed.
* *
* \note In order to make the removal permanent save() still needs to be called. * \note In order to make the removal permanent save() still needs to be called.
*/ */
void strip(int tags = AllTags); void strip(int tags = AllTags);
/*!
* \deprecated
* \see strip
*/
TAGLIB_DEPRECATED void remove(int tags = AllTags);
/*! /*!
* Returns whether or not the file on disk actually has an ID3v1 tag. * Returns whether or not the file on disk actually has an ID3v1 tag.
* *
@@ -216,11 +190,9 @@ namespace TagLib {
bool hasAPETag() const; bool hasAPETag() const;
/*! /*!
* Returns whether or not the given \a stream can be opened as an MPC * Returns whether or not the given \a stream can be opened as an MPC file.
* file.
* *
* \note This method is designed to do a quick check. The result may * \note This method is designed to do a quick check. The result may not necessarily be correct.
* not necessarily be correct.
*/ */
static bool isSupported(IOStream *stream); static bool isSupported(IOStream *stream);
@@ -233,8 +205,8 @@ namespace TagLib {
class FilePrivate; class FilePrivate;
FilePrivate *d; FilePrivate *d;
}; };
} } // namespace MPC
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,21 +23,25 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tstring.h>
#include <tdebug.h>
#include <bitset> #include <bitset>
#include <math.h> #include <cmath>
#include "tstring.h"
#include "tdebug.h"
#include "mpcproperties.h" #include "mpcproperties.h"
#include "mpcfile.h" #include "mpcfile.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
class MPC::Properties::PropertiesPrivate namespace {
{ const unsigned int HeaderSize = 56;
}
class MPC::AudioProperties::AudioPropertiesPrivate {
public: public:
PropertiesPrivate() : explicit AudioPropertiesPrivate() : version(0),
version(0),
length(0), length(0),
bitrate(0), bitrate(0),
sampleRate(0), sampleRate(0),
@@ -56,27 +60,18 @@ public:
int channels; int channels;
unsigned int totalFrames; unsigned int totalFrames;
unsigned int sampleFrames; unsigned int sampleFrames;
int trackGain; unsigned int trackGain;
int trackPeak; unsigned int trackPeak;
int albumGain; unsigned int albumGain;
int albumPeak; unsigned int albumPeak;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
MPC::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : MPC::AudioProperties::AudioProperties(File *file, long long streamLength, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
AudioProperties(style),
d(new PropertiesPrivate())
{
readSV7(data, streamLength);
}
MPC::Properties::Properties(File *file, long streamLength, ReadStyle style) :
AudioProperties(style),
d(new PropertiesPrivate())
{
ByteVector magic = file->readBlock(4); ByteVector magic = file->readBlock(4);
if (magic == "MPCK") { if (magic == "MPCK") {
// Musepack version 8 // Musepack version 8
@@ -84,77 +79,60 @@ MPC::Properties::Properties(File *file, long streamLength, ReadStyle style) :
} }
else { else {
// Musepack version 7 or older, fixed size header // Musepack version 7 or older, fixed size header
readSV7(magic + file->readBlock(MPC::HeaderSize - 4), streamLength); readSV7(magic + file->readBlock(HeaderSize - 4), streamLength);
}
} }
MPC::Properties::~Properties() }
{
MPC::AudioProperties::~AudioProperties() {
delete d; delete d;
} }
int MPC::Properties::length() const int MPC::AudioProperties::lengthInSeconds() const {
{
return lengthInSeconds();
}
int MPC::Properties::lengthInSeconds() const
{
return d->length / 1000; return d->length / 1000;
} }
int MPC::Properties::lengthInMilliseconds() const int MPC::AudioProperties::lengthInMilliseconds() const {
{
return d->length; return d->length;
} }
int MPC::Properties::bitrate() const int MPC::AudioProperties::bitrate() const {
{
return d->bitrate; return d->bitrate;
} }
int MPC::Properties::sampleRate() const int MPC::AudioProperties::sampleRate() const {
{
return d->sampleRate; return d->sampleRate;
} }
int MPC::Properties::channels() const int MPC::AudioProperties::channels() const {
{
return d->channels; return d->channels;
} }
int MPC::Properties::mpcVersion() const int MPC::AudioProperties::mpcVersion() const {
{
return d->version; return d->version;
} }
unsigned int MPC::Properties::totalFrames() const unsigned int MPC::AudioProperties::totalFrames() const {
{
return d->totalFrames; return d->totalFrames;
} }
unsigned int MPC::Properties::sampleFrames() const unsigned int MPC::AudioProperties::sampleFrames() const {
{
return d->sampleFrames; return d->sampleFrames;
} }
int MPC::Properties::trackGain() const int MPC::AudioProperties::trackGain() const {
{
return d->trackGain; return d->trackGain;
} }
int MPC::Properties::trackPeak() const int MPC::AudioProperties::trackPeak() const {
{
return d->trackPeak; return d->trackPeak;
} }
int MPC::Properties::albumGain() const int MPC::AudioProperties::albumGain() const {
{
return d->albumGain; return d->albumGain;
} }
int MPC::Properties::albumPeak() const int MPC::AudioProperties::albumPeak() const {
{
return d->albumPeak; return d->albumPeak;
} }
@@ -162,10 +140,9 @@ int MPC::Properties::albumPeak() const
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace namespace {
{ unsigned long readSize(File *file, size_t &sizeLength, bool &eof) {
unsigned long readSize(File *file, unsigned int &sizeLength, bool &eof)
{
sizeLength = 0; sizeLength = 0;
eof = false; eof = false;
@@ -182,47 +159,53 @@ namespace
tmp = b[0]; tmp = b[0];
size = (size << 7) | (tmp & 0x7F); size = (size << 7) | (tmp & 0x7F);
sizeLength++; sizeLength++;
} while((tmp & 0x80)); }
while ((tmp & 0x80));
return size; return size;
} }
unsigned long readSize(const ByteVector &data, unsigned int &pos) unsigned long readSize(const ByteVector &data, size_t &pos) {
{
unsigned char tmp; unsigned char tmp;
unsigned long size = 0; unsigned long size = 0;
do { do {
tmp = data[pos++]; tmp = data[pos++];
size = (size << 7) | (tmp & 0x7F); size = (size << 7) | (tmp & 0x7F);
} while((tmp & 0x80) && (pos < data.size())); }
while ((tmp & 0x80) && (pos < data.size()));
return size; return size;
} }
// This array looks weird, but the same as original MusePack code found at: // This array looks weird, but the same as original MusePack code found at:
// https://www.musepack.net/index.php?pg=src // https://www.musepack.net/index.php?pg=src
const unsigned short sftable[8] = { 44100, 48000, 37800, 32000, 0, 0, 0, 0 }; const unsigned short sftable[8] = { 44100, 48000, 37800, 32000, 0, 0, 0, 0 };
} } // namespace
void MPC::AudioProperties::readSV8(File *file, long long streamLength) {
void MPC::Properties::readSV8(File *file, long streamLength)
{
bool readSH = false, readRG = false; bool readSH = false, readRG = false;
while (!readSH && !readRG) { while (!readSH && !readRG) {
const ByteVector packetType = file->readBlock(2); const ByteVector packetType = file->readBlock(2);
unsigned int packetSizeLength; size_t packetSizeLength;
bool eof; bool eof;
const unsigned long packetSize = readSize(file, packetSizeLength, eof); const size_t packetSize = readSize(file, packetSizeLength, eof);
if (eof) { if (eof) {
debug("MPC::Properties::readSV8() - Reached to EOF."); debug("MPC::AudioProperties::readSV8() - Reached to EOF.");
break; break;
} }
const unsigned long dataSize = packetSize - 2 - packetSizeLength; const size_t dataSize = packetSize - 2 - packetSizeLength;
const ByteVector data = file->readBlock(dataSize); const ByteVector data = file->readBlock(dataSize);
if (data.size() != dataSize) { if (data.size() != dataSize) {
debug("MPC::Properties::readSV8() - dataSize doesn't match the actual data size."); debug("MPC::AudioProperties::readSV8() - dataSize doesn't match the actual data size.");
break; break;
} }
@@ -231,28 +214,28 @@ void MPC::Properties::readSV8(File *file, long streamLength)
// http://trac.musepack.net/wiki/SV8Specification#StreamHeaderPacket // http://trac.musepack.net/wiki/SV8Specification#StreamHeaderPacket
if (dataSize <= 5) { if (dataSize <= 5) {
debug("MPC::Properties::readSV8() - \"SH\" packet is too short to parse."); debug("MPC::AudioProperties::readSV8() - \"SH\" packet is too short to parse.");
break; break;
} }
readSH = true; readSH = true;
unsigned int pos = 4; size_t pos = 4;
d->version = data[pos]; d->version = data[pos];
pos += 1; pos += 1;
d->sampleFrames = readSize(data, pos); d->sampleFrames = readSize(data, pos);
if (pos > dataSize - 3) { if (pos > dataSize - 3) {
debug("MPC::Properties::readSV8() - \"SH\" packet is corrupt."); debug("MPC::AudioProperties::readSV8() - \"SH\" packet is corrupt.");
break; break;
} }
const unsigned long begSilence = readSize(data, pos); const unsigned long begSilence = readSize(data, pos);
if (pos > dataSize - 2) { if (pos > dataSize - 2) {
debug("MPC::Properties::readSV8() - \"SH\" packet is corrupt."); debug("MPC::AudioProperties::readSV8() - \"SH\" packet is corrupt.");
break; break;
} }
const unsigned short flags = data.toUShort(pos, true); const unsigned short flags = data.toUInt16BE(pos);
pos += 2; pos += 2;
d->sampleRate = sftable[(flags >> 13) & 0x07]; d->sampleRate = sftable[(flags >> 13) & 0x07];
@@ -270,7 +253,7 @@ void MPC::Properties::readSV8(File *file, long streamLength)
// http://trac.musepack.net/wiki/SV8Specification#ReplaygainPacket // http://trac.musepack.net/wiki/SV8Specification#ReplaygainPacket
if (dataSize <= 9) { if (dataSize <= 9) {
debug("MPC::Properties::readSV8() - \"RG\" packet is too short to parse."); debug("MPC::AudioProperties::readSV8() - \"RG\" packet is too short to parse.");
break; break;
} }
@@ -278,10 +261,10 @@ void MPC::Properties::readSV8(File *file, long streamLength)
const int replayGainVersion = data[0]; const int replayGainVersion = data[0];
if (replayGainVersion == 1) { if (replayGainVersion == 1) {
d->trackGain = data.toShort(1, true); d->trackGain = data.toUInt16BE(1);
d->trackPeak = data.toShort(3, true); d->trackPeak = data.toUInt16BE(3);
d->albumGain = data.toShort(5, true); d->albumGain = data.toUInt16BE(5);
d->albumPeak = data.toShort(7, true); d->albumPeak = data.toUInt16BE(7);
} }
} }
@@ -293,46 +276,47 @@ void MPC::Properties::readSV8(File *file, long streamLength)
file->seek(dataSize, File::Current); file->seek(dataSize, File::Current);
} }
} }
} }
void MPC::Properties::readSV7(const ByteVector &data, long streamLength) void MPC::AudioProperties::readSV7(const ByteVector &data, long long streamLength) {
{
if (data.startsWith("MP+")) { if (data.startsWith("MP+")) {
d->version = data[3] & 15; d->version = data[3] & 15;
if (d->version < 7) if (d->version < 7)
return; return;
d->totalFrames = data.toUInt(4, false); d->totalFrames = data.toUInt32LE(4);
const unsigned int flags = data.toUInt(8, false); const unsigned int flags = data.toUInt32LE(8);
d->sampleRate = sftable[(flags >> 16) & 0x03]; d->sampleRate = sftable[(flags >> 16) & 0x03];
d->channels = 2; d->channels = 2;
const unsigned int gapless = data.toUInt(5, false); const unsigned int gapless = data.toUInt32LE(5);
d->trackGain = data.toShort(14, false); d->trackGain = data.toUInt16LE(14);
d->trackPeak = data.toUShort(12, false); d->trackPeak = data.toUInt16LE(12);
d->albumGain = data.toShort(18, false); d->albumGain = data.toUInt16LE(18);
d->albumPeak = data.toUShort(16, false); d->albumPeak = data.toUInt16LE(16);
// convert gain info // convert gain info
if (d->trackGain != 0) { if (d->trackGain != 0) {
int tmp = (int)((64.82 - (short)d->trackGain / 100.) * 256. + .5); int tmp = static_cast<int>((64.82 - static_cast<short>(d->trackGain) / 100.) * 256. + .5);
if (tmp >= (1 << 16) || tmp < 0) tmp = 0; if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
d->trackGain = tmp; d->trackGain = tmp;
} }
if (d->albumGain != 0) { if (d->albumGain != 0) {
int tmp = (int)((64.82 - d->albumGain / 100.) * 256. + .5); int tmp = static_cast<int>((64.82 - d->albumGain / 100.) * 256. + .5);
if (tmp >= (1 << 16) || tmp < 0) tmp = 0; if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
d->albumGain = tmp; d->albumGain = tmp;
} }
if (d->trackPeak != 0) if (d->trackPeak != 0)
d->trackPeak = (int)(log10((double)d->trackPeak) * 20 * 256 + .5); d->trackPeak = static_cast<int>(log10(static_cast<double>(d->trackPeak)) * 20 * 256 + .5);
if (d->albumPeak != 0) if (d->albumPeak != 0)
d->albumPeak = (int)(log10((double)d->albumPeak) * 20 * 256 + .5); d->albumPeak = static_cast<int>(log10(static_cast<double>(d->albumPeak)) * 20 * 256 + .5);
bool trueGapless = (gapless >> 31) & 0x0001; bool trueGapless = (gapless >> 31) & 0x0001;
if (trueGapless) { if (trueGapless) {
@@ -343,7 +327,7 @@ void MPC::Properties::readSV7(const ByteVector &data, long streamLength)
d->sampleFrames = d->totalFrames * 1152 - 576; d->sampleFrames = d->totalFrames * 1152 - 576;
} }
else { else {
const unsigned int headerData = data.toUInt(0, false); const unsigned int headerData = data.toUInt32LE(0);
d->bitrate = (headerData >> 23) & 0x01ff; d->bitrate = (headerData >> 23) & 0x01ff;
d->version = (headerData >> 11) & 0x03ff; d->version = (headerData >> 11) & 0x03ff;
@@ -351,9 +335,9 @@ void MPC::Properties::readSV7(const ByteVector &data, long streamLength)
d->channels = 2; d->channels = 2;
if (d->version >= 5) if (d->version >= 5)
d->totalFrames = data.toUInt(4, false); d->totalFrames = data.toUInt32LE(4);
else else
d->totalFrames = data.toUShort(6, false); d->totalFrames = data.toUInt16LE(6);
d->sampleFrames = d->totalFrames * 1152 - 576; d->sampleFrames = d->totalFrames * 1152 - 576;
} }
@@ -365,4 +349,5 @@ void MPC::Properties::readSV7(const ByteVector &data, long streamLength)
if (d->bitrate == 0) if (d->bitrate == 0)
d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5); d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5);
} }
} }

View File

@@ -36,78 +36,53 @@ namespace TagLib {
class File; class File;
static const unsigned int HeaderSize = 8 * 7;
//! An implementation of audio property reading for MPC //! An implementation of audio property reading for MPC
/*! /*!
* This reads the data from an MPC stream found in the AudioProperties * This reads the data from an MPC stream found in the AudioProperties API.
* API.
*/ */
class TAGLIB_EXPORT Properties : public AudioProperties class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
{
public: public:
/*! /*!
* Create an instance of MPC::Properties with the data read from the * Create an instance of MPC::AudioProperties with the data read directly from a MPC::File.
* ByteVector \a data.
*
* This constructor is deprecated. It only works for MPC version up to 7.
*/ */
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average); explicit AudioProperties(File *file, long long streamLength, ReadStyle style = Average);
/*! /*!
* Create an instance of MPC::Properties with the data read directly * Destroys this MPC::AudioProperties instance.
* from a MPC::File.
*/ */
Properties(File *file, long streamLength, ReadStyle style = Average); ~AudioProperties() override;
/*! /*!
* Destroys this MPC::Properties instance. * Returns the length of the file in seconds.
*/ * The length is rounded down to the nearest whole second.
virtual ~Properties();
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
*
* \note This method is just an alias of lengthInSeconds().
*
* \deprecated
*/
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
* the nearest whole second.
* *
* \see lengthInMilliseconds() * \see lengthInMilliseconds()
*/ */
// BIC: make virtual int lengthInSeconds() const override;
int lengthInSeconds() const;
/*! /*!
* Returns the length of the file in milliseconds. * Returns the length of the file in milliseconds.
* *
* \see lengthInSeconds() * \see lengthInSeconds()
*/ */
// BIC: make virtual int lengthInMilliseconds() const override;
int lengthInMilliseconds() const;
/*! /*!
* Returns the average bit rate of the file in kb/s. * Returns the average bit rate of the file in kb/s.
*/ */
virtual int bitrate() const; int bitrate() const override;
/*! /*!
* Returns the sample rate in Hz. * Returns the sample rate in Hz.
*/ */
virtual int sampleRate() const; int sampleRate() const override;
/*! /*!
* Returns the number of audio channels. * Returns the number of audio channels.
*/ */
virtual int channels() const; int channels() const override;
/*! /*!
* Returns the version of the bitstream (SV4-SV8) * Returns the version of the bitstream (SV4-SV8)
@@ -144,17 +119,14 @@ namespace TagLib {
int albumPeak() const; int albumPeak() const;
private: private:
Properties(const Properties &); void readSV7(const ByteVector &data, long long streamLength);
Properties &operator=(const Properties &); void readSV8(File *file, long long streamLength);
void readSV7(const ByteVector &data, long streamLength); class AudioPropertiesPrivate;
void readSV8(File *file, long streamLength); AudioPropertiesPrivate *d;
class PropertiesPrivate;
PropertiesPrivate *d;
}; };
} } // namespace MPC
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -27,8 +27,7 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
namespace namespace {
{
const wchar_t *genres[] = { const wchar_t *genres[] = {
L"Blues", L"Blues",
L"Classic Rock", L"Classic Rock",
@@ -224,42 +223,46 @@ namespace
L"Psybient" L"Psybient"
}; };
const int genresSize = sizeof(genres) / sizeof(genres[0]); const int genresSize = sizeof(genres) / sizeof(genres[0]);
} } // namespace
StringList ID3v1::genreList() {
StringList ID3v1::genreList()
{
StringList l; StringList l;
for (int i = 0; i < genresSize; i++) { for (int i = 0; i < genresSize; i++) {
l.append(genres[i]); l.append(genres[i]);
} }
return l; return l;
} }
ID3v1::GenreMap ID3v1::genreMap() ID3v1::GenreMap ID3v1::genreMap() {
{
GenreMap m; GenreMap m;
for (int i = 0; i < genresSize; i++) { for (int i = 0; i < genresSize; i++) {
m.insert(genres[i], i); m.insert(genres[i], i);
} }
return m; return m;
} }
String ID3v1::genre(int i) String ID3v1::genre(int i) {
{
if (i >= 0 && i < genresSize) if (i >= 0 && i < genresSize)
return String(genres[i]); // always make a copy return String(genres[i]); // always make a copy
else else
return String(); return String();
} }
int ID3v1::genreIndex(const String &name) int ID3v1::genreIndex(const String &name) {
{
for (int i = 0; i < genresSize; ++i) { for (int i = 0; i < genresSize; ++i) {
if (name == genres[i]) if (name == genres[i])
return i; return i;
} }
return 255; return 255;
} }

View File

@@ -37,32 +37,28 @@ namespace TagLib {
typedef Map<String, int> GenreMap; typedef Map<String, int> GenreMap;
/*! /*!
* Returns the list of canonical ID3v1 genre names in the order that they * Returns the list of canonical ID3v1 genre names in the order that they are listed in the standard.
* are listed in the standard.
*/ */
StringList TAGLIB_EXPORT genreList(); StringList TAGLIB_EXPORT genreList();
/*! /*!
* A "reverse mapping" that goes from the canonical ID3v1 genre name to the * A "reverse mapping" that goes from the canonical ID3v1 genre name to the respective genre number. genreMap()["Rock"] ==
* respective genre number. genreMap()["Rock"] ==
*/ */
GenreMap TAGLIB_EXPORT genreMap(); GenreMap TAGLIB_EXPORT genreMap();
/*! /*!
* Returns the name of the genre at \a index in the ID3v1 genre list. If * Returns the name of the genre at \a index in the ID3v1 genre list.
* \a index is out of range -- less than zero or greater than 191 -- a null * If \a index is out of range -- less than zero or greater than 191 -- a null string will be returned.
* string will be returned.
*/ */
String TAGLIB_EXPORT genre(int index); String TAGLIB_EXPORT genre(int index);
/*! /*!
* Returns the genre index for the (case sensitive) genre \a name. If the * Returns the genre index for the (case sensitive) genre \a name.
* genre is not in the list 255 (which signifies an unknown genre in ID3v1) * If the genre is not in the list 255 (which signifies an unknown genre in ID3v1) will be returned.
* will be returned.
*/ */
int TAGLIB_EXPORT genreIndex(const String &name); int TAGLIB_EXPORT genreIndex(const String &name);
} } // namespace ID3v1
} } // namespace TagLib
} } // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,8 +23,9 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tdebug.h> #include "tdebug.h"
#include <tfile.h> #include "tfile.h"
#include "tpicturemap.h"
#include "id3v1tag.h" #include "id3v1tag.h"
#include "id3v1genres.h" #include "id3v1genres.h"
@@ -32,23 +33,36 @@
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace ID3v1; using namespace ID3v1;
namespace namespace {
{ class DefaultStringHandler : public Strawberry_TagLib::TagLib::StringHandler {
const ID3v1::StringHandler defaultStringHandler; public:
const ID3v1::StringHandler *stringHandler = &defaultStringHandler; explicit DefaultStringHandler() : Strawberry_TagLib::TagLib::StringHandler() {}
String parse(const ByteVector &data) const override {
return String(data, String::Latin1).stripWhiteSpace();
} }
class ID3v1::Tag::TagPrivate ByteVector render(const String &s) const override {
{ if (s.isLatin1())
return s.data(String::Latin1);
else
return ByteVector();
}
};
const DefaultStringHandler defaultStringHandler;
const Strawberry_TagLib::TagLib::StringHandler *stringHandler = &defaultStringHandler;
} // namespace
class ID3v1::Tag::TagPrivate {
public: public:
TagPrivate() : explicit TagPrivate() : file(nullptr),
file(0),
tagOffset(0), tagOffset(0),
track(0), track(0),
genre(255) {} genre(255) {}
File *file; File *file;
long tagOffset; long long tagOffset;
String title; String title;
String artist; String artist;
@@ -59,54 +73,26 @@ public:
unsigned char genre; unsigned char genre;
}; };
////////////////////////////////////////////////////////////////////////////////
// StringHandler implementation
////////////////////////////////////////////////////////////////////////////////
StringHandler::StringHandler()
{
}
String ID3v1::StringHandler::parse(const ByteVector &data) const
{
return String(data, String::Latin1).stripWhiteSpace();
}
ByteVector ID3v1::StringHandler::render(const String &s) const
{
if(s.isLatin1())
return s.data(String::Latin1);
else
return ByteVector();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ID3v1::Tag::Tag() : ID3v1::Tag::Tag() : d(new TagPrivate()) {}
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate()) ID3v1::Tag::Tag(File *file, long long tagOffset) : d(new TagPrivate()) {
{
}
ID3v1::Tag::Tag(File *file, long tagOffset) :
Strawberry_TagLib::TagLib::Tag(),
d(new TagPrivate())
{
d->file = file; d->file = file;
d->tagOffset = tagOffset; d->tagOffset = tagOffset;
read(); read();
} }
ID3v1::Tag::~Tag() ID3v1::Tag::~Tag() {
{
delete d; delete d;
} }
ByteVector ID3v1::Tag::render() const ByteVector ID3v1::Tag::render() const {
{
ByteVector data; ByteVector data;
data.append(fileIdentifier()); data.append(fileIdentifier());
@@ -120,95 +106,84 @@ ByteVector ID3v1::Tag::render() const
data.append(char(d->genre)); data.append(char(d->genre));
return data; return data;
} }
ByteVector ID3v1::Tag::fileIdentifier() ByteVector ID3v1::Tag::fileIdentifier() {
{
return ByteVector::fromCString("TAG"); return ByteVector::fromCString("TAG");
} }
String ID3v1::Tag::title() const String ID3v1::Tag::title() const {
{
return d->title; return d->title;
} }
String ID3v1::Tag::artist() const String ID3v1::Tag::artist() const {
{
return d->artist; return d->artist;
} }
String ID3v1::Tag::album() const String ID3v1::Tag::album() const {
{
return d->album; return d->album;
} }
String ID3v1::Tag::comment() const String ID3v1::Tag::comment() const {
{
return d->comment; return d->comment;
} }
String ID3v1::Tag::genre() const String ID3v1::Tag::genre() const {
{
return ID3v1::genre(d->genre); return ID3v1::genre(d->genre);
} }
unsigned int ID3v1::Tag::year() const unsigned int ID3v1::Tag::year() const {
{
return d->year.toInt(); return d->year.toInt();
} }
unsigned int ID3v1::Tag::track() const unsigned int ID3v1::Tag::track() const {
{
return d->track; return d->track;
} }
void ID3v1::Tag::setTitle(const String &s) Strawberry_TagLib::TagLib::PictureMap ID3v1::Tag::pictures() const {
{ return PictureMap();
}
void ID3v1::Tag::setTitle(const String &s) {
d->title = s; d->title = s;
} }
void ID3v1::Tag::setArtist(const String &s) void ID3v1::Tag::setArtist(const String &s) {
{
d->artist = s; d->artist = s;
} }
void ID3v1::Tag::setAlbum(const String &s) void ID3v1::Tag::setAlbum(const String &s) {
{
d->album = s; d->album = s;
} }
void ID3v1::Tag::setComment(const String &s) void ID3v1::Tag::setComment(const String &s) {
{
d->comment = s; d->comment = s;
} }
void ID3v1::Tag::setGenre(const String &s) void ID3v1::Tag::setGenre(const String &s) {
{
d->genre = ID3v1::genreIndex(s); d->genre = ID3v1::genreIndex(s);
} }
void ID3v1::Tag::setYear(unsigned int i) void ID3v1::Tag::setYear(unsigned int i) {
{
d->year = i > 0 ? String::number(i) : String(); d->year = i > 0 ? String::number(i) : String();
} }
void ID3v1::Tag::setTrack(unsigned int i) void ID3v1::Tag::setTrack(unsigned int i) {
{
d->track = i < 256 ? i : 0; d->track = i < 256 ? i : 0;
} }
unsigned int ID3v1::Tag::genreNumber() const void ID3v1::Tag::setPictures(const PictureMap&) {}
{
unsigned int ID3v1::Tag::genreNumber() const {
return d->genre; return d->genre;
} }
void ID3v1::Tag::setGenreNumber(unsigned int i) void ID3v1::Tag::setGenreNumber(unsigned int i) {
{
d->genre = i < 256 ? i : 255; d->genre = i < 256 ? i : 255;
} }
void ID3v1::Tag::setStringHandler(const StringHandler *handler) void ID3v1::Tag::setStringHandler(const Strawberry_TagLib::TagLib::StringHandler *handler) {
{
if (handler) if (handler)
stringHandler = handler; stringHandler = handler;
else else
@@ -219,8 +194,8 @@ void ID3v1::Tag::setStringHandler(const StringHandler *handler)
// protected methods // protected methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ID3v1::Tag::read() void ID3v1::Tag::read() {
{
if (d->file && d->file->isValid()) { if (d->file && d->file->isValid()) {
d->file->seek(d->tagOffset); d->file->seek(d->tagOffset);
// read the tag -- always 128 bytes // read the tag -- always 128 bytes
@@ -232,10 +207,11 @@ void ID3v1::Tag::read()
else else
debug("ID3v1 tag is not valid or could not be read at the specified offset."); debug("ID3v1 tag is not valid or could not be read at the specified offset.");
} }
} }
void ID3v1::Tag::parse(const ByteVector &data) void ID3v1::Tag::parse(const ByteVector &data) {
{
int offset = 3; int offset = 3;
d->title = stringHandler->parse(data.mid(offset, 30)); d->title = stringHandler->parse(data.mid(offset, 30));
@@ -267,4 +243,5 @@ void ID3v1::Tag::parse(const ByteVector &data)
offset += 30; offset += 30;
d->genre = static_cast<unsigned char>(data[offset]); d->genre = static_cast<unsigned char>(data[offset]);
} }

View File

@@ -28,6 +28,7 @@
#include "tag.h" #include "tag.h"
#include "tbytevector.h" #include "tbytevector.h"
#include "tstringhandler.h"
#include "taglib_export.h" #include "taglib_export.h"
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
@@ -39,118 +40,71 @@ namespace TagLib {
namespace ID3v1 { namespace ID3v1 {
//! A abstraction for the string to data encoding in ID3v1 tags.
/*!
* ID3v1 should in theory always contain ISO-8859-1 (Latin1) data. In
* practice it does not. TagLib by default only supports ISO-8859-1 data
* in ID3v1 tags.
*
* However by subclassing this class and reimplementing parse() and render()
* and setting your reimplementation as the default with
* ID3v1::Tag::setStringHandler() you can define how you would like these
* transformations to be done.
*
* \warning It is advisable <b>not</b> to write non-ISO-8859-1 data to ID3v1
* tags. Please consider disabling the writing of ID3v1 tags in the case
* that the data is not ISO-8859-1.
*
* \see ID3v1::Tag::setStringHandler()
*/
class TAGLIB_EXPORT StringHandler
{
TAGLIB_IGNORE_MISSING_DESTRUCTOR
public:
// BIC: Add virtual destructor.
StringHandler();
/*!
* Decode a string from \a data. The default implementation assumes that
* \a data is an ISO-8859-1 (Latin1) character array.
*/
virtual String parse(const ByteVector &data) const;
/*!
* Encode a ByteVector with the data from \a s. The default implementation
* assumes that \a s is an ISO-8859-1 (Latin1) string. If the string is
* does not conform to ISO-8859-1, no value is written.
*
* \warning It is recommended that you <b>not</b> override this method, but
* instead do not write an ID3v1 tag in the case that the data is not
* ISO-8859-1.
*/
virtual ByteVector render(const String &s) const;
};
//! The main class in the ID3v1 implementation //! The main class in the ID3v1 implementation
/*! /*!
* This is an implementation of the ID3v1 format. ID3v1 is both the simplest * This is an implementation of the ID3v1 format.
* and most common of tag formats but is rather limited. Because of its * ID3v1 is both the simplest and most common of tag formats but is rather limited.
* pervasiveness and the way that applications have been written around the * Because of its pervasiveness and the way that applications have been written around the
* fields that it provides, the generic TagLib::Tag API is a mirror of what is * fields that it provides, the generic TagLib::Tag API is a mirror of what is provided by ID3v1.
* provided by ID3v1.
* *
* ID3v1 tags should generally only contain Latin1 information. However because * ID3v1 tags should generally only contain Latin1 information.
* many applications do not follow this rule there is now support for overriding * However because many applications do not follow this rule there is now support for overriding
* the ID3v1 string handling using the ID3v1::StringHandler class. Please see * the ID3v1 string handling using the ID3v1::StringHandler class.
* the documentation for that class for more information. * Please see the documentation for that class for more information.
* *
* \see StringHandler * \see StringHandler
* *
* \note Most fields are truncated to a maximum of 28-30 bytes. The * \note Most fields are truncated to a maximum of 28-30 bytes.
* truncation happens automatically when the tag is rendered. * The truncation happens automatically when the tag is rendered.
*/ */
class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag class TAGLIB_EXPORT Tag : public Strawberry_TagLib::TagLib::Tag {
{
public: public:
/*! /*!
* Create an ID3v1 tag with default values. * Create an ID3v1 tag with default values.
*/ */
Tag(); explicit Tag();
/*! /*!
* Create an ID3v1 tag and parse the data in \a file starting at * Create an ID3v1 tag and parse the data in \a file starting at \a tagOffset.
* \a tagOffset.
*/ */
Tag(File *file, long tagOffset); explicit Tag(File *file, long long tagOffset);
/*! /*!
* Destroys this Tag instance. * Destroys this Tag instance.
*/ */
virtual ~Tag(); ~Tag() override;
/*! /*!
* Renders the in memory values to a ByteVector suitable for writing to * Renders the in memory values to a ByteVector suitable for writing to the file.
* the file.
*/ */
ByteVector render() const; ByteVector render() const;
/*! /*!
* Returns the string "TAG" suitable for usage in locating the tag in a * Returns the string "TAG" suitable for usage in locating the tag in a file.
* file.
*/ */
static ByteVector fileIdentifier(); static ByteVector fileIdentifier();
// Reimplementations. // Reimplementations.
virtual String title() const; String title() const override;
virtual String artist() const; String artist() const override;
virtual String album() const; String album() const override;
virtual String comment() const; String comment() const override;
virtual String genre() const; String genre() const override;
virtual unsigned int year() const; unsigned int year() const override;
virtual unsigned int track() const; unsigned int track() const override;
PictureMap pictures() const override;
virtual void setTitle(const String &s); void setTitle(const String &s) override;
virtual void setArtist(const String &s); void setArtist(const String &s) override;
virtual void setAlbum(const String &s); void setAlbum(const String &s) override;
virtual void setComment(const String &s); void setComment(const String &s) override;
virtual void setGenre(const String &s); void setGenre(const String &s) override;
virtual void setYear(unsigned int i); void setYear(unsigned int i) override;
virtual void setTrack(unsigned int i); void setTrack(unsigned int i) override;
void setPictures(const PictureMap&) override;
/*! /*!
* Returns the genre in number. * Returns the genre in number.
@@ -162,23 +116,18 @@ namespace TagLib {
/*! /*!
* Sets the genre in number to \a i. * Sets the genre in number to \a i.
* *
* \note Valid value is from 0 up to 255. Normally 255 indicates that * \note Valid value is from 0 up to 255. Normally 255 indicates that this tag contains no genre.
* this tag contains no genre.
*/ */
void setGenreNumber(unsigned int i); void setGenreNumber(unsigned int i);
/*! /*!
* Sets the string handler that decides how the ID3v1 data will be * Sets the string handler that decides how the ID3v1 data will be converted to and from binary data.
* converted to and from binary data. * If the parameter \a handler is null, the previous handler is released and default ISO-8859-1 handler is restored.
* If the parameter \a handler is null, the previous handler is
* released and default ISO-8859-1 handler is restored.
* *
* \note The caller is responsible for deleting the previous handler * \note The caller is responsible for deleting the previous handler as needed after it is released.
* as needed after it is released.
* *
* \see StringHandler
*/ */
static void setStringHandler(const StringHandler *handler); static void setStringHandler(const Strawberry_TagLib::TagLib::StringHandler *handler);
protected: protected:
/*! /*!
@@ -197,8 +146,9 @@ namespace TagLib {
class TagPrivate; class TagPrivate;
TagPrivate *d; TagPrivate *d;
}; };
}
} } // namespace ID3v1
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

View File

@@ -25,17 +25,15 @@
#include "attachedpictureframe.h" #include "attachedpictureframe.h"
#include <tstringlist.h> #include "tstringlist.h"
#include <tdebug.h> #include "tdebug.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace ID3v2; using namespace ID3v2;
class AttachedPictureFrame::AttachedPictureFramePrivate class AttachedPictureFrame::AttachedPictureFramePrivate {
{
public: public:
AttachedPictureFramePrivate() : textEncoding(String::Latin1), explicit AttachedPictureFramePrivate() : textEncoding(String::Latin1), type(AttachedPictureFrame::Other) {}
type(AttachedPictureFrame::Other) {}
String::Type textEncoding; String::Type textEncoding;
String mimeType; String mimeType;
@@ -48,77 +46,58 @@ public:
// public members // public members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AttachedPictureFrame::AttachedPictureFrame() : AttachedPictureFrame::AttachedPictureFrame() : Frame("APIC"), d(new AttachedPictureFramePrivate()) {}
Frame("APIC"),
d(new AttachedPictureFramePrivate())
{
}
AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data) : AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data) : Frame(data), d(new AttachedPictureFramePrivate()) {
Frame(data),
d(new AttachedPictureFramePrivate())
{
setData(data); setData(data);
} }
AttachedPictureFrame::~AttachedPictureFrame() AttachedPictureFrame::~AttachedPictureFrame() {
{
delete d; delete d;
} }
String AttachedPictureFrame::toString() const String AttachedPictureFrame::toString() const {
{
String s = "[" + d->mimeType + "]"; String s = "[" + d->mimeType + "]";
return d->description.isEmpty() ? s : d->description + " " + s; return d->description.isEmpty() ? s : d->description + " " + s;
} }
String::Type AttachedPictureFrame::textEncoding() const String::Type AttachedPictureFrame::textEncoding() const {
{
return d->textEncoding; return d->textEncoding;
} }
void AttachedPictureFrame::setTextEncoding(String::Type t) void AttachedPictureFrame::setTextEncoding(String::Type t) {
{
d->textEncoding = t; d->textEncoding = t;
} }
String AttachedPictureFrame::mimeType() const String AttachedPictureFrame::mimeType() const {
{
return d->mimeType; return d->mimeType;
} }
void AttachedPictureFrame::setMimeType(const String &m) void AttachedPictureFrame::setMimeType(const String &m) {
{
d->mimeType = m; d->mimeType = m;
} }
AttachedPictureFrame::Type AttachedPictureFrame::type() const AttachedPictureFrame::Type AttachedPictureFrame::type() const {
{
return d->type; return d->type;
} }
void AttachedPictureFrame::setType(Type t) void AttachedPictureFrame::setType(Type t) {
{
d->type = t; d->type = t;
} }
String AttachedPictureFrame::description() const String AttachedPictureFrame::description() const {
{
return d->description; return d->description;
} }
void AttachedPictureFrame::setDescription(const String &desc) void AttachedPictureFrame::setDescription(const String &desc) {
{
d->description = desc; d->description = desc;
} }
ByteVector AttachedPictureFrame::picture() const ByteVector AttachedPictureFrame::picture() const {
{
return d->data; return d->data;
} }
void AttachedPictureFrame::setPicture(const ByteVector &p) void AttachedPictureFrame::setPicture(const ByteVector &p) {
{
d->data = p; d->data = p;
} }
@@ -126,8 +105,8 @@ void AttachedPictureFrame::setPicture(const ByteVector &p)
// protected members // protected members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void AttachedPictureFrame::parseFields(const ByteVector &data) void AttachedPictureFrame::parseFields(const ByteVector &data) {
{
if (data.size() < 5) { if (data.size() < 5) {
debug("A picture frame must contain at least 5 bytes."); debug("A picture frame must contain at least 5 bytes.");
return; return;
@@ -135,23 +114,24 @@ void AttachedPictureFrame::parseFields(const ByteVector &data)
d->textEncoding = String::Type(data[0]); d->textEncoding = String::Type(data[0]);
int pos = 1; size_t pos = 1;
d->mimeType = readStringField(data, String::Latin1, &pos); d->mimeType = readStringField(data, String::Latin1, pos);
/* Now we need at least two more bytes available */ /* Now we need at least two more bytes available */
if(static_cast<unsigned int>(pos) + 1 >= data.size()) { if (pos + 1 >= data.size()) {
debug("Truncated picture frame."); debug("Truncated picture frame.");
return; return;
} }
d->type = (Strawberry_TagLib::TagLib::ID3v2::AttachedPictureFrame::Type)data[pos++]; d->type = static_cast<ID3v2::AttachedPictureFrame::Type>(data[pos++]);
d->description = readStringField(data, d->textEncoding, &pos); d->description = readStringField(data, d->textEncoding, pos);
d->data = data.mid(pos); d->data = data.mid(pos);
} }
ByteVector AttachedPictureFrame::renderFields() const ByteVector AttachedPictureFrame::renderFields() const {
{
ByteVector data; ByteVector data;
String::Type encoding = checkTextEncoding(d->description, d->textEncoding); String::Type encoding = checkTextEncoding(d->description, d->textEncoding);
@@ -165,16 +145,14 @@ ByteVector AttachedPictureFrame::renderFields() const
data.append(d->data); data.append(d->data);
return data; return data;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private members // private members
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data, Header *h) : AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data, Header *h) : Frame(h), d(new AttachedPictureFramePrivate()) {
Frame(h),
d(new AttachedPictureFramePrivate())
{
parseFields(fieldData(data)); parseFields(fieldData(data));
} }
@@ -182,8 +160,8 @@ AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data, Header *h) :
// support for ID3v2.2 PIC frames // support for ID3v2.2 PIC frames
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void AttachedPictureFrameV22::parseFields(const ByteVector &data) void AttachedPictureFrameV22::parseFields(const ByteVector &data) {
{
if (data.size() < 5) { if (data.size() < 5) {
debug("A picture frame must contain at least 5 bytes."); debug("A picture frame must contain at least 5 bytes.");
return; return;
@@ -191,28 +169,31 @@ void AttachedPictureFrameV22::parseFields(const ByteVector &data)
d->textEncoding = String::Type(data[0]); d->textEncoding = String::Type(data[0]);
int pos = 1; size_t pos = 1;
String fixedString = String(data.mid(pos, 3), String::Latin1); String fixedString = String(data.mid(pos, 3), String::Latin1);
pos += 3; pos += 3;
// convert fixed string image type to mime string // convert fixed string image type to mime string
if (fixedString.upper() == "JPG") { if (fixedString.upper() == "JPG") {
d->mimeType = "image/jpeg"; d->mimeType = "image/jpeg";
} else if (fixedString.upper() == "PNG") { }
else if (fixedString.upper() == "PNG") {
d->mimeType = "image/png"; d->mimeType = "image/png";
} else { }
else {
debug("probably unsupported image type"); debug("probably unsupported image type");
d->mimeType = "image/" + fixedString; d->mimeType = "image/" + fixedString;
} }
d->type = (Strawberry_TagLib::TagLib::ID3v2::AttachedPictureFrame::Type)data[pos++]; d->type = static_cast<ID3v2::AttachedPictureFrame::Type>(data[pos++]);
d->description = readStringField(data, d->textEncoding, &pos); d->description = readStringField(data, d->textEncoding, pos);
d->data = data.mid(pos); d->data = data.mid(pos);
} }
AttachedPictureFrameV22::AttachedPictureFrameV22(const ByteVector &data, Header *h) AttachedPictureFrameV22::AttachedPictureFrameV22(const ByteVector &data, Header *h) {
{
// set v2.2 header to make fieldData work correctly // set v2.2 header to make fieldData work correctly
setHeader(h, true); setHeader(h, true);
@@ -222,4 +203,5 @@ AttachedPictureFrameV22::AttachedPictureFrameV22(const ByteVector &data, Header
Frame::Header *newHeader = new Frame::Header("APIC"); Frame::Header *newHeader = new Frame::Header("APIC");
newHeader->setFrameSize(h->frameSize()); newHeader->setFrameSize(h->frameSize());
setHeader(newHeader, true); setHeader(newHeader, true);
} }

View File

@@ -32,24 +32,20 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace ID3v2 { namespace ID3v2 {
//! An ID3v2 attached picture frame implementation //! An ID3v2 attached picture frame implementation
/*! /*!
* This is an implementation of ID3v2 attached pictures. Pictures may be * This is an implementation of ID3v2 attached pictures.
* included in tags, one per APIC frame (but there may be multiple APIC * Pictures may be included in tags, one per APIC frame (but there may be multiple APIC frames in a single tag).
* frames in a single tag). These pictures are usually in either JPEG or * These pictures are usually in either JPEG or PNG format.
* PNG format.
*/ */
class TAGLIB_EXPORT AttachedPictureFrame : public Frame class TAGLIB_EXPORT AttachedPictureFrame : public Frame {
{
friend class FrameFactory; friend class FrameFactory;
public: public:
/*! /*!
* This describes the function or content of the picture. * This describes the function or content of the picture.
*/ */
@@ -99,10 +95,10 @@ namespace TagLib {
}; };
/*! /*!
* Constructs an empty picture frame. The description, content and text * Constructs an empty picture frame.
* encoding should be set manually. * The description, content and text encoding should be set manually.
*/ */
AttachedPictureFrame(); explicit AttachedPictureFrame();
/*! /*!
* Constructs an AttachedPicture frame based on \a data. * Constructs an AttachedPicture frame based on \a data.
@@ -112,12 +108,12 @@ namespace TagLib {
/*! /*!
* Destroys the AttahcedPictureFrame instance. * Destroys the AttahcedPictureFrame instance.
*/ */
virtual ~AttachedPictureFrame(); ~AttachedPictureFrame() override;
/*! /*!
* Returns a string containing the description and mime-type * Returns a string containing the description and mime-type
*/ */
virtual String toString() const; String toString() const override;
/*! /*!
* Returns the text encoding used for the description. * Returns the text encoding used for the description.
@@ -135,14 +131,14 @@ namespace TagLib {
void setTextEncoding(String::Type t); void setTextEncoding(String::Type t);
/*! /*!
* Returns the mime type of the image. This should in most cases be * Returns the mime type of the image.
* "image/png" or "image/jpeg". * This should in most cases be "image/png" or "image/jpeg".
*/ */
String mimeType() const; String mimeType() const;
/*! /*!
* Sets the mime type of the image. This should in most cases be * Sets the mime type of the image.
* "image/png" or "image/jpeg". * This should in most cases be "image/png" or "image/jpeg".
*/ */
void setMimeType(const String &m); void setMimeType(const String &m);
@@ -185,8 +181,7 @@ namespace TagLib {
/*! /*!
* Returns the image data as a ByteVector. * Returns the image data as a ByteVector.
* *
* \note ByteVector has a data() method that returns a const char * which * \note ByteVector has a data() method that returns a const char * which should make it easy to export this data to external programs.
* should make it easy to export this data to external programs.
* *
* \see setPicture() * \see setPicture()
* \see mimeType() * \see mimeType()
@@ -194,8 +189,7 @@ namespace TagLib {
ByteVector picture() const; ByteVector picture() const;
/*! /*!
* Sets the image data to \a p. \a p should be of the type specified in * Sets the image data to \a p. \a p should be of the type specified in this frame's mime-type specification.
* this frame's mime-type specification.
* *
* \see picture() * \see picture()
* \see mimeType() * \see mimeType()
@@ -204,29 +198,29 @@ namespace TagLib {
void setPicture(const ByteVector &p); void setPicture(const ByteVector &p);
protected: protected:
virtual void parseFields(const ByteVector &data); void parseFields(const ByteVector &data) override;
virtual ByteVector renderFields() const; ByteVector renderFields() const override;
class AttachedPictureFramePrivate; class AttachedPictureFramePrivate;
AttachedPictureFramePrivate *d; AttachedPictureFramePrivate *d;
private: private:
AttachedPictureFrame(const AttachedPictureFrame&); AttachedPictureFrame(const AttachedPictureFrame&);
AttachedPictureFrame &operator=(const AttachedPictureFrame&); AttachedPictureFrame &operator=(const AttachedPictureFrame&);
AttachedPictureFrame(const ByteVector &data, Header *h); explicit AttachedPictureFrame(const ByteVector &data, Header *h);
}; };
//! support for ID3v2.2 PIC frames //! support for ID3v2.2 PIC frames
class TAGLIB_EXPORT AttachedPictureFrameV22 : public AttachedPictureFrame class TAGLIB_EXPORT AttachedPictureFrameV22 : public AttachedPictureFrame {
{
protected: protected:
virtual void parseFields(const ByteVector &data); void parseFields(const ByteVector &data) override;
private: private:
AttachedPictureFrameV22(const ByteVector &data, Header *h); explicit AttachedPictureFrameV22(const ByteVector &data, Header *h);
friend class FrameFactory; friend class FrameFactory;
}; };
}
} } // namespace ID3v2
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

View File

@@ -23,26 +23,24 @@
* http://www.mozilla.org/MPL/ * * http://www.mozilla.org/MPL/ *
***************************************************************************/ ***************************************************************************/
#include <tbytevectorlist.h> #include <cstdio>
#include <tpropertymap.h>
#include <tdebug.h> #include "tbytevectorlist.h"
#include <stdio.h> #include "tpropertymap.h"
#include "tdebug.h"
#include "chapterframe.h" #include "chapterframe.h"
using namespace Strawberry_TagLib::TagLib; using namespace Strawberry_TagLib::TagLib;
using namespace ID3v2; using namespace ID3v2;
class ChapterFrame::ChapterFramePrivate class ChapterFrame::ChapterFramePrivate {
{
public: public:
ChapterFramePrivate() : explicit ChapterFramePrivate() : tagHeader(nullptr),
tagHeader(0),
startTime(0), startTime(0),
endTime(0), endTime(0),
startOffset(0), startOffset(0),
endOffset(0) endOffset(0) {
{
embeddedFrameList.setAutoDelete(true); embeddedFrameList.setAutoDelete(true);
} }
@@ -60,23 +58,14 @@ public:
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ChapterFrame::ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data) : ChapterFrame::ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data) : ID3v2::Frame(data), d(new ChapterFramePrivate()) {
ID3v2::Frame(data),
d(new ChapterFramePrivate())
{
d->tagHeader = tagHeader; d->tagHeader = tagHeader;
setData(data); setData(data);
} }
ChapterFrame::ChapterFrame(const ByteVector &elementID, ChapterFrame::ChapterFrame(const ByteVector &elementID, unsigned int startTime, unsigned int endTime, unsigned int startOffset, unsigned int endOffset, const FrameList &embeddedFrames) : ID3v2::Frame("CHAP"), d(new ChapterFramePrivate()) {
unsigned int startTime, unsigned int endTime,
unsigned int startOffset, unsigned int endOffset, // setElementID has a workaround for a previously silly API where you had to specifically include the null byte.
const FrameList &embeddedFrames) :
ID3v2::Frame("CHAP"),
d(new ChapterFramePrivate())
{
// setElementID has a workaround for a previously silly API where you had to
// specifically include the null byte.
setElementID(elementID); setElementID(elementID);
@@ -86,91 +75,80 @@ ChapterFrame::ChapterFrame(const ByteVector &elementID,
d->endOffset = endOffset; d->endOffset = endOffset;
for (FrameList::ConstIterator it = embeddedFrames.begin(); for (FrameList::ConstIterator it = embeddedFrames.begin();
it != embeddedFrames.end(); ++it) it != embeddedFrames.end();
++it)
addEmbeddedFrame(*it); addEmbeddedFrame(*it);
} }
ChapterFrame::~ChapterFrame() ChapterFrame::~ChapterFrame() {
{
delete d; delete d;
} }
ByteVector ChapterFrame::elementID() const ByteVector ChapterFrame::elementID() const {
{
return d->elementID; return d->elementID;
} }
unsigned int ChapterFrame::startTime() const unsigned int ChapterFrame::startTime() const {
{
return d->startTime; return d->startTime;
} }
unsigned int ChapterFrame::endTime() const unsigned int ChapterFrame::endTime() const {
{
return d->endTime; return d->endTime;
} }
unsigned int ChapterFrame::startOffset() const unsigned int ChapterFrame::startOffset() const {
{
return d->startOffset; return d->startOffset;
} }
unsigned int ChapterFrame::endOffset() const unsigned int ChapterFrame::endOffset() const {
{
return d->endOffset; return d->endOffset;
} }
void ChapterFrame::setElementID(const ByteVector &eID) void ChapterFrame::setElementID(const ByteVector &eID) {
{
d->elementID = eID; d->elementID = eID;
if (d->elementID.endsWith(char(0))) if (d->elementID.endsWith(char(0)))
d->elementID = d->elementID.mid(0, d->elementID.size() - 1); d->elementID = d->elementID.mid(0, d->elementID.size() - 1);
} }
void ChapterFrame::setStartTime(const unsigned int &sT) void ChapterFrame::setStartTime(const unsigned int &sT) {
{
d->startTime = sT; d->startTime = sT;
} }
void ChapterFrame::setEndTime(const unsigned int &eT) void ChapterFrame::setEndTime(const unsigned int &eT) {
{
d->endTime = eT; d->endTime = eT;
} }
void ChapterFrame::setStartOffset(const unsigned int &sO) void ChapterFrame::setStartOffset(const unsigned int &sO) {
{
d->startOffset = sO; d->startOffset = sO;
} }
void ChapterFrame::setEndOffset(const unsigned int &eO) void ChapterFrame::setEndOffset(const unsigned int &eO) {
{
d->endOffset = eO; d->endOffset = eO;
} }
const FrameListMap &ChapterFrame::embeddedFrameListMap() const const FrameListMap &ChapterFrame::embeddedFrameListMap() const {
{
return d->embeddedFrameListMap; return d->embeddedFrameListMap;
} }
const FrameList &ChapterFrame::embeddedFrameList() const const FrameList &ChapterFrame::embeddedFrameList() const {
{
return d->embeddedFrameList; return d->embeddedFrameList;
} }
const FrameList &ChapterFrame::embeddedFrameList(const ByteVector &frameID) const const FrameList &ChapterFrame::embeddedFrameList(const ByteVector &frameID) const {
{
return d->embeddedFrameListMap[frameID]; return d->embeddedFrameListMap[frameID];
} }
void ChapterFrame::addEmbeddedFrame(Frame *frame) void ChapterFrame::addEmbeddedFrame(Frame *frame) {
{
d->embeddedFrameList.append(frame); d->embeddedFrameList.append(frame);
d->embeddedFrameListMap[frame->frameID()].append(frame); d->embeddedFrameListMap[frame->frameID()].append(frame);
} }
void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del) void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del) {
{
// remove the frame from the frame list // remove the frame from the frame list
FrameList::Iterator it = d->embeddedFrameList.find(frame); FrameList::Iterator it = d->embeddedFrameList.find(frame);
d->embeddedFrameList.erase(it); d->embeddedFrameList.erase(it);
@@ -182,17 +160,19 @@ void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del)
// ...and delete as desired // ...and delete as desired
if (del) if (del)
delete frame; delete frame;
} }
void ChapterFrame::removeEmbeddedFrames(const ByteVector &id) void ChapterFrame::removeEmbeddedFrames(const ByteVector &id) {
{
FrameList l = d->embeddedFrameListMap[id]; FrameList l = d->embeddedFrameListMap[id];
for (FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) for (FrameList::ConstIterator it = l.begin(); it != l.end(); ++it)
removeEmbeddedFrame(*it, true); removeEmbeddedFrame(*it, true);
} }
String ChapterFrame::toString() const String ChapterFrame::toString() const {
{
String s = String(d->elementID) + String s = String(d->elementID) +
": start time: " + String::number(d->startTime) + ": start time: " + String::number(d->startTime) +
", end time: " + String::number(d->endTime); ", end time: " + String::number(d->endTime);
@@ -206,58 +186,61 @@ String ChapterFrame::toString() const
if (!d->embeddedFrameList.isEmpty()) { if (!d->embeddedFrameList.isEmpty()) {
StringList frameIDs; StringList frameIDs;
for (FrameList::ConstIterator it = d->embeddedFrameList.begin(); for (FrameList::ConstIterator it = d->embeddedFrameList.begin();
it != d->embeddedFrameList.end(); ++it) it != d->embeddedFrameList.end();
++it)
frameIDs.append((*it)->frameID()); frameIDs.append((*it)->frameID());
s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]"; s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]";
} }
return s; return s;
} }
PropertyMap ChapterFrame::asProperties() const PropertyMap ChapterFrame::asProperties() const {
{
PropertyMap map; PropertyMap map;
map.unsupportedData().append(frameID() + String("/") + d->elementID); map.unsupportedData().append(frameID() + String("/") + d->elementID);
return map; return map;
} }
ChapterFrame *ChapterFrame::findByElementID(const ID3v2::Tag *tag, const ByteVector &eID) // static ChapterFrame *ChapterFrame::findByElementID(const ID3v2::Tag *tag, const ByteVector &eID) { // static
{
ID3v2::FrameList comments = tag->frameList("CHAP"); ID3v2::FrameList comments = tag->frameList("CHAP");
for (ID3v2::FrameList::ConstIterator it = comments.begin(); for (ID3v2::FrameList::ConstIterator it = comments.begin();
it != comments.end(); it != comments.end();
++it) ++it) {
{
ChapterFrame *frame = dynamic_cast<ChapterFrame *>(*it); ChapterFrame *frame = dynamic_cast<ChapterFrame *>(*it);
if (frame && frame->elementID() == eID) if (frame && frame->elementID() == eID)
return frame; return frame;
} }
return nullptr; return nullptr;
} }
void ChapterFrame::parseFields(const ByteVector &data) void ChapterFrame::parseFields(const ByteVector &data) {
{
unsigned int size = data.size(); size_t size = data.size();
if (size < 18) { if (size < 18) {
debug("A CHAP frame must contain at least 18 bytes (1 byte element ID " debug("A CHAP frame must contain at least 18 bytes (1 byte element ID "
"terminated by null and 4x4 bytes for start and end time and offset)."); "terminated by null and 4x4 bytes for start and end time and offset).");
return; return;
} }
int pos = 0; size_t pos = 0;
unsigned int embPos = 0; size_t embPos = 0;
d->elementID = readStringField(data, String::Latin1, &pos).data(String::Latin1); d->elementID = readStringField(data, String::Latin1, pos).data(String::Latin1);
d->startTime = data.toUInt(pos, true); d->startTime = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->endTime = data.toUInt(pos, true); d->endTime = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->startOffset = data.toUInt(pos, true); d->startOffset = data.toUInt32BE(pos);
pos += 4; pos += 4;
d->endOffset = data.toUInt(pos, true); d->endOffset = data.toUInt32BE(pos);
pos += 4; pos += 4;
size -= pos; size -= pos;
@@ -281,29 +264,30 @@ void ChapterFrame::parseFields(const ByteVector &data)
embPos += frame->size() + header()->size(); embPos += frame->size() + header()->size();
addEmbeddedFrame(frame); addEmbeddedFrame(frame);
} }
} }
ByteVector ChapterFrame::renderFields() const ByteVector ChapterFrame::renderFields() const {
{
ByteVector data; ByteVector data;
data.append(d->elementID); data.append(d->elementID);
data.append('\0'); data.append('\0');
data.append(ByteVector::fromUInt(d->startTime, true)); data.append(ByteVector::fromUInt32BE(d->startTime));
data.append(ByteVector::fromUInt(d->endTime, true)); data.append(ByteVector::fromUInt32BE(d->endTime));
data.append(ByteVector::fromUInt(d->startOffset, true)); data.append(ByteVector::fromUInt32BE(d->startOffset));
data.append(ByteVector::fromUInt(d->endOffset, true)); data.append(ByteVector::fromUInt32BE(d->endOffset));
FrameList l = d->embeddedFrameList; FrameList l = d->embeddedFrameList;
for (FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) for (FrameList::ConstIterator it = l.begin(); it != l.end(); ++it)
data.append((*it)->render()); data.append((*it)->render());
return data; return data;
} }
ChapterFrame::ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data, Header *h) : ChapterFrame::ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data, Header *h) : Frame(h), d(new ChapterFramePrivate()) {
Frame(h),
d(new ChapterFramePrivate())
{
d->tagHeader = tagHeader; d->tagHeader = tagHeader;
parseFields(fieldData(data)); parseFields(fieldData(data));
} }

View File

@@ -32,49 +32,43 @@
namespace Strawberry_TagLib { namespace Strawberry_TagLib {
namespace TagLib { namespace TagLib {
namespace ID3v2 { namespace ID3v2 {
/*! /*!
* This is an implementation of ID3v2 chapter frames. The purpose of this * This is an implementation of ID3v2 chapter frames.
* frame is to describe a single chapter within an audio file. * The purpose of this frame is to describe a single chapter within an audio file.
*/ */
//! An implementation of ID3v2 chapter frames //! An implementation of ID3v2 chapter frames
class TAGLIB_EXPORT ChapterFrame : public ID3v2::Frame class TAGLIB_EXPORT ChapterFrame : public ID3v2::Frame {
{
friend class FrameFactory; friend class FrameFactory;
public: public:
/*! /*!
* Creates a chapter frame based on \a data. \a tagHeader is required as * Creates a chapter frame based on \a data.
* the internal frames are parsed based on the tag version. * \a tagHeader is required as the internal frames are parsed based on the tag version.
*/ */
ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data); explicit ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data);
/*! /*!
* Creates a chapter frame with the element ID \a elementID, start time * Creates a chapter frame with the element ID \a elementID,
* \a startTime, end time \a endTime, start offset \a startOffset, * start time \a startTime, end time \a endTime, start offset \a startOffset,
* end offset \a endOffset and optionally a list of embedded frames, * end offset \a endOffset and optionally a list of embedded frames,
* whose ownership will then be taken over by this Frame, in * whose ownership will then be taken over by this Frame, in \a embeededFrames;
* \a embeededFrames;
* *
* All times are in milliseconds. * All times are in milliseconds.
*/ */
ChapterFrame(const ByteVector &elementID, explicit ChapterFrame(const ByteVector &elementID, unsigned int startTime, unsigned int endTime, unsigned int startOffset, unsigned int endOffset, const FrameList &embeddedFrames = FrameList());
unsigned int startTime, unsigned int endTime,
unsigned int startOffset, unsigned int endOffset,
const FrameList &embeddedFrames = FrameList());
/*! /*!
* Destroys the frame. * Destroys the frame.
*/ */
virtual ~ChapterFrame(); ~ChapterFrame() override;
/*! /*!
* Returns the element ID of the frame. Element ID * Returns the element ID of the frame.
* is a null terminated string, however it's not human-readable. * Element ID is a null terminated string, however it's not human-readable.
* *
* \see setElementID() * \see setElementID()
*/ */
@@ -95,8 +89,7 @@ namespace TagLib {
unsigned int endTime() const; unsigned int endTime() const;
/*! /*!
* Returns zero based byte offset (count of bytes from the beginning * Returns zero based byte offset (count of bytes from the beginning of the audio file) of chapter's start.
* of the audio file) of chapter's start.
* *
* \note If returned value is 0xFFFFFFFF, start time should be used instead. * \note If returned value is 0xFFFFFFFF, start time should be used instead.
* \see setStartOffset() * \see setStartOffset()
@@ -104,8 +97,7 @@ namespace TagLib {
unsigned int startOffset() const; unsigned int startOffset() const;
/*! /*!
* Returns zero based byte offset (count of bytes from the beginning * Returns zero based byte offset (count of bytes from the beginning of the audio file) of chapter's end.
* of the audio file) of chapter's end.
* *
* \note If returned value is 0xFFFFFFFF, end time should be used instead. * \note If returned value is 0xFFFFFFFF, end time should be used instead.
* \see setEndOffset() * \see setEndOffset()
@@ -113,8 +105,7 @@ namespace TagLib {
unsigned int endOffset() const; unsigned int endOffset() const;
/*! /*!
* Sets the element ID of the frame to \a eID. If \a eID isn't * Sets the element ID of the frame to \a eID. If \a eID isn't null terminated, a null char is appended automatically.
* null terminated, a null char is appended automatically.
* *
* \see elementID() * \see elementID()
*/ */
@@ -135,29 +126,26 @@ namespace TagLib {
void setEndTime(const unsigned int &eT); void setEndTime(const unsigned int &eT);
/*! /*!
* Sets zero based byte offset (count of bytes from the beginning * Sets zero based byte offset (count of bytes from the beginning of the audio file) of chapter's start to \a sO.
* of the audio file) of chapter's start to \a sO.
* *
* \see startOffset() * \see startOffset()
*/ */
void setStartOffset(const unsigned int &sO); void setStartOffset(const unsigned int &sO);
/*! /*!
* Sets zero based byte offset (count of bytes from the beginning * Sets zero based byte offset (count of bytes from the beginning of the audio file) of chapter's end to \a eO.
* of the audio file) of chapter's end to \a eO.
* *
* \see endOffset() * \see endOffset()
*/ */
void setEndOffset(const unsigned int &eO); void setEndOffset(const unsigned int &eO);
/*! /*!
* Returns a reference to the frame list map. This is an FrameListMap of * Returns a reference to the frame list map.
* all of the frames embedded in the CHAP frame. * This is an FrameListMap of all of the frames embedded in the CHAP frame.
* *
* This is the most convenient structure for accessing the CHAP frame's * This is the most convenient structure for accessing the CHAP frame's embedded frames.
* embedded frames. Many frame types allow multiple instances of the same * Many frame types allow multiple instances of the same rame type so this is a map of lists.
* frame type so this is a map of lists. In most cases however there will * In most cases however there will only be a single frame of a certain type.
* only be a single frame of a certain type.
* *
* \warning You should not modify this data structure directly, instead * \warning You should not modify this data structure directly, instead
* use addEmbeddedFrame() and removeEmbeddedFrame(). * use addEmbeddedFrame() and removeEmbeddedFrame().
@@ -167,22 +155,20 @@ namespace TagLib {
const FrameListMap &embeddedFrameListMap() const; const FrameListMap &embeddedFrameListMap() const;
/*! /*!
* Returns a reference to the embedded frame list. This is an FrameList * Returns a reference to the embedded frame list.
* of all of the frames embedded in the CHAP frame in the order that they * This is an FrameList of all of the frames embedded in the CHAP frame in the order that they were parsed.
* were parsed.
* *
* This can be useful if for example you want iterate over the CHAP frame's * This can be useful if for example you want iterate over the CHAP frame's
* embedded frames in the order that they occur in the CHAP frame. * embedded frames in the order that they occur in the CHAP frame.
* *
* \warning You should not modify this data structure directly, instead * \warning You should not modify this data structure directly,
* use addEmbeddedFrame() and removeEmbeddedFrame(). * instead use addEmbeddedFrame() and removeEmbeddedFrame().
*/ */
const FrameList &embeddedFrameList() const; const FrameList &embeddedFrameList() const;
/*! /*!
* Returns the embedded frame list for frames with the id \a frameID * Returns the embedded frame list for frames with the id \a frameID or an empty list if there are no embedded frames of that type.
* or an empty list if there are no embedded frames of that type. This * This is just a convenience and is equivalent to:
* is just a convenience and is equivalent to:
* *
* \code * \code
* embeddedFrameListMap()[frameID]; * embeddedFrameListMap()[frameID];
@@ -193,59 +179,55 @@ namespace TagLib {
const FrameList &embeddedFrameList(const ByteVector &frameID) const; const FrameList &embeddedFrameList(const ByteVector &frameID) const;
/*! /*!
* Add an embedded frame to the CHAP frame. At this point the CHAP frame * Add an embedded frame to the CHAP frame.
* takes ownership of the embedded frame and will handle freeing its memory. * At this point the CHAP frame takes ownership of the embedded frame and will handle freeing its memory.
* *
* \note Using this method will invalidate any pointers on the list * \note Using this method will invalidate any pointers on the list returned by embeddedFrameList()
* returned by embeddedFrameList()
*/ */
void addEmbeddedFrame(Frame *frame); void addEmbeddedFrame(Frame *frame);
/*! /*!
* Remove an embedded frame from the CHAP frame. If \a del is true the frame's * Remove an embedded frame from the CHAP frame.
* memory will be freed; if it is false, it must be deleted by the user. * If \a del is true the frame's memory will be freed; if it is false, it must be deleted by the user.
* *
* \note Using this method will invalidate any pointers on the list * \note Using this method will invalidate any pointers on the list returned by embeddedFrameList()
* returned by embeddedFrameList()
*/ */
void removeEmbeddedFrame(Frame *frame, bool del = true); void removeEmbeddedFrame(Frame *frame, bool del = true);
/*! /*!
* Remove all embedded frames of type \a id from the CHAP frame and free their * Remove all embedded frames of type \a id from the CHAP frame and free their memory.
* memory.
* *
* \note Using this method will invalidate any pointers on the list * \note Using this method will invalidate any pointers on the list returned by embeddedFrameList()
* returned by embeddedFrameList()
*/ */
void removeEmbeddedFrames(const ByteVector &id); void removeEmbeddedFrames(const ByteVector &id);
virtual String toString() const; String toString() const override;
PropertyMap asProperties() const; PropertyMap asProperties() const;
/*! /*!
* CHAP frames each have a unique element ID. This searches for a CHAP * CHAP frames each have a unique element ID. This searches for a CHAP frame with the element ID \a eID and returns a pointer to it.
* frame with the element ID \a eID and returns a pointer to it. This * This can be used to link CTOC and CHAP frames together.
* can be used to link CTOC and CHAP frames together.
* *
* \see elementID() * \see elementID()
*/ */
static ChapterFrame *findByElementID(const Tag *tag, const ByteVector &eID); static ChapterFrame *findByElementID(const Tag *tag, const ByteVector &eID);
protected: protected:
virtual void parseFields(const ByteVector &data); void parseFields(const ByteVector &data) override;
virtual ByteVector renderFields() const; ByteVector renderFields() const override;
private: private:
ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data, Header *h); explicit ChapterFrame(const ID3v2::Header *tagHeader, const ByteVector &data, Header *h);
ChapterFrame(const ChapterFrame&); ChapterFrame(const ChapterFrame&);
ChapterFrame &operator=(const ChapterFrame&); ChapterFrame &operator=(const ChapterFrame&);
class ChapterFramePrivate; class ChapterFramePrivate;
ChapterFramePrivate *d; ChapterFramePrivate *d;
}; };
}
} } // namespace ID3v2
} } // namespace TagLib
} // namespace Strawberry_TagLib
#endif #endif

Some files were not shown because too many files have changed in this diff Show More