File indexing completed on 2024-10-06 04:26:03
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include <config-k3b.h> 0007 0008 #ifdef ENABLE_MUSICBRAINZ 0009 0010 #include "k3btrm.h" 0011 #include "musicbrainz/mb_c.h" 0012 0013 #include <KProtocolManager> 0014 #include <QDebug> 0015 #include <QUrl> 0016 0017 0018 class K3b::TRM::Private 0019 { 0020 public: 0021 trm_t trm; 0022 QByteArray sig; 0023 QByteArray rawSig; 0024 }; 0025 0026 0027 K3b::TRM::TRM() 0028 { 0029 d = new Private; 0030 d->trm = trm_New(); 0031 d->rawSig.resize( 17 ); 0032 d->sig.resize( 37 ); 0033 } 0034 0035 0036 K3b::TRM::~TRM() 0037 { 0038 trm_Delete( d->trm ); 0039 delete d; 0040 } 0041 0042 0043 void K3b::TRM::start( const K3b::Msf& length ) 0044 { 0045 if( KProtocolManager::useProxy() ) { 0046 QUrl proxy( KProtocolManager::proxyFor("http") ); 0047 trm_SetProxy( d->trm, const_cast<char*>(proxy.host().toLatin1().constData()), short(proxy.port()) ); 0048 } 0049 0050 trm_SetPCMDataInfo( d->trm, 44100, 2, 16 ); 0051 trm_SetSongLength( d->trm, length.totalFrames()/75 ); 0052 } 0053 0054 0055 bool K3b::TRM::generate( char* data, int len ) 0056 { 0057 return ( trm_GenerateSignature( d->trm, data, len ) == 1 ); 0058 } 0059 0060 0061 bool K3b::TRM::finalize() 0062 { 0063 if( trm_FinalizeSignature( d->trm, d->rawSig.data(), 0 ) == 0 ) { 0064 trm_ConvertSigToASCII( d->trm, d->rawSig.data(), d->sig.data() ); 0065 return true; 0066 } 0067 else 0068 return false; 0069 } 0070 0071 0072 QByteArray K3b::TRM::rawSignature() const 0073 { 0074 return d->rawSig; 0075 } 0076 0077 0078 QByteArray K3b::TRM::signature() const 0079 { 0080 return d->sig; 0081 } 0082 0083 #endif