diff -Nru kodi-audiodecoder-timidity-1.1.0/appveyor.yml kodi-audiodecoder-timidity-2.0.1/appveyor.yml --- kodi-audiodecoder-timidity-1.1.0/appveyor.yml 1970-01-01 00:00:00.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/appveyor.yml 2018-01-18 11:33:04.000000000 +0000 @@ -0,0 +1,27 @@ +version: BuildNr.{build} + +image: Visual Studio 2015 + +shallow_clone: true + +clone_folder: c:\projects\audiodecoder.timidity + +environment: + app_id: audiodecoder.timidity + + matrix: + - GENERATOR: "Visual Studio 14" + CONFIG: Release + - GENERATOR: "Visual Studio 14 Win64" + CONFIG: Release + +build_script: + - cd .. + - git clone --depth=1 https://github.com/xbmc/xbmc.git + - cd %app_id% + - mkdir build + - cd build + - mkdir -p definition\%app_id% + - echo %app_id% %APPVEYOR_BUILD_FOLDER% %APPVEYOR_REPO_COMMIT% > definition\%app_id%\%app_id%.txt + - cmake -T host=x64 -G "%GENERATOR%" -DADDONS_TO_BUILD=%app_id% -DCMAKE_BUILD_TYPE=%CONFIG% -DADDONS_DEFINITION_DIR=%APPVEYOR_BUILD_FOLDER%/build/definition -DADDON_SRC_PREFIX=../.. -DCMAKE_INSTALL_PREFIX=../../xbmc/addons -DPACKAGE_ZIP=1 ../../xbmc/cmake/addons + - cmake --build . --config %CONFIG% --target %app_id% diff -Nru kodi-audiodecoder-timidity-1.1.0/audiodecoder.timidity/addon.xml.in kodi-audiodecoder-timidity-2.0.1/audiodecoder.timidity/addon.xml.in --- kodi-audiodecoder-timidity-1.1.0/audiodecoder.timidity/addon.xml.in 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/audiodecoder.timidity/addon.xml.in 2018-01-18 11:33:04.000000000 +0000 @@ -1,12 +1,10 @@ - - - + @ADDON_DEPENDS@ - + +
+ + + + + + true + .sf2|.cfg + + + + + +
diff -Nru kodi-audiodecoder-timidity-1.1.0/CMakeLists.txt kodi-audiodecoder-timidity-2.0.1/CMakeLists.txt --- kodi-audiodecoder-timidity-1.1.0/CMakeLists.txt 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/CMakeLists.txt 2018-01-18 11:33:04.000000000 +0000 @@ -7,15 +7,21 @@ enable_language(CXX) find_package(Kodi REQUIRED) +find_package(p8-platform REQUIRED) -include_directories(${KODI_INCLUDE_DIR} +include_directories(${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways (becomes done in future) + ${p8-platform_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/lib/timidity) add_subdirectory(lib/timidity) set(TIMIDITY_SOURCES src/TimidityCodec.cpp) -set(DEPLIBS timidity) +set(DEPLIBS timidity + ${p8-platform_LIBRARIES}) + +add_definitions(-DLIBRARY_PREFIX="${CMAKE_SHARED_LIBRARY_PREFIX}" + -DLIBRARY_SUFFIX="${CMAKE_SHARED_LIBRARY_SUFFIX}") build_addon(audiodecoder.timidity TIMIDITY DEPLIBS) diff -Nru kodi-audiodecoder-timidity-1.1.0/debian/changelog kodi-audiodecoder-timidity-2.0.1/debian/changelog --- kodi-audiodecoder-timidity-1.1.0/debian/changelog 2018-04-30 15:08:05.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/debian/changelog 2018-03-12 17:02:05.000000000 +0000 @@ -1,4 +1,4 @@ -kodi-audiodecoder-timidity (1.1.0-1~bionic) bionic; urgency=low +kodi-audiodecoder-timidity (2.0.1-1~bionic) bionic; urgency=low [ kodi ] * autogenerated dummy changelog @@ -6,4 +6,4 @@ [ wsnipex ] * no upstream changelog available - -- wsnipex Mon, 30 Apr 2018 17:08:05 +0200 + -- wsnipex Mon, 12 Mar 2018 18:02:05 +0100 diff -Nru kodi-audiodecoder-timidity-1.1.0/debian/changelog.tmp kodi-audiodecoder-timidity-2.0.1/debian/changelog.tmp --- kodi-audiodecoder-timidity-1.1.0/debian/changelog.tmp 2018-04-30 15:08:00.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/debian/changelog.tmp 2018-03-12 17:02:00.000000000 +0000 @@ -1,4 +1,4 @@ -kodi-audiodecoder-timidity (1.1.0-1~#DIST#) #DIST#; urgency=low +kodi-audiodecoder-timidity (2.0.1-1~#DIST#) #DIST#; urgency=low [ kodi ] * autogenerated dummy changelog diff -Nru kodi-audiodecoder-timidity-1.1.0/debian/control kodi-audiodecoder-timidity-2.0.1/debian/control --- kodi-audiodecoder-timidity-1.1.0/debian/control 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/debian/control 2018-01-18 11:33:04.000000000 +0000 @@ -1,8 +1,7 @@ Source: kodi-audiodecoder-timidity Priority: extra Maintainer: Arne Morten Kvarving -Build-Depends: debhelper (>= 8.0.0), cmake, kodi-audio-dev, - kodi-addon-dev +Build-Depends: debhelper (>= 8.0.0), cmake, kodi-addon-dev, libp8-platform-dev Standards-Version: 3.9.2 Section: libs diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/CMakeLists.txt kodi-audiodecoder-timidity-2.0.1/lib/timidity/CMakeLists.txt --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/CMakeLists.txt 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/CMakeLists.txt 2018-01-18 11:33:04.000000000 +0000 @@ -42,11 +42,14 @@ add_options(C ALL_BUILDS "-fPIC") -add_definitions(-DHAVE_GETTIMEOFDAY=1 -DHAVE_ALSA_ASOUNDLIB=1 -DHAVE_LIBASOUND=1 -DHAVE_SYS_TIME_H=1 -DHAVE_ERRNO_H=1) +add_definitions(-DHAVE_ALSA_ASOUNDLIB=1 -DHAVE_LIBASOUND=1 -DHAVE_ERRNO_H=1) if(APPLE) add_definitions(-DHAVE_STRLCPY=1 -DHAVE_STRLCAT=1) endif(APPLE) +if(NOT WIN32) + add_definitions(-DHAVE_SYS_TIME_H=1 -DHAVE_GETTIMEOFDAY=1) +endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR} timidity libarc utils) diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/libarc/url.h kodi-audiodecoder-timidity-2.0.1/lib/timidity/libarc/url.h --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/libarc/url.h 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/libarc/url.h 2018-01-18 11:33:04.000000000 +0000 @@ -35,7 +35,7 @@ /* Define if you want to appended on a user's home directory if a filename * is beginning with '~' */ -#if !defined(__MACOS__) && !defined(__W32__) +#if !defined(__MACOS__) && !defined(__W32__) && !defined(_WIN32) #define TILD_SCHEME_ENABLE #endif diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/aq.c kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/aq.c --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/aq.c 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/aq.c 2018-01-18 11:33:04.000000000 +0000 @@ -52,6 +52,10 @@ #define MAX_BUCKET_TIME 0.2 #define MAX_FILLED_TIME 2.0 +#if defined(_WIN32) +#define usleep(X) Sleep((X) / 1000U) +#endif + static int32 device_qsize; static int Bps; /* Bytes per sample frame */ static int bucket_size; diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/buffer_a.c kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/buffer_a.c --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/buffer_a.c 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/buffer_a.c 2018-01-18 11:33:04.000000000 +0000 @@ -71,7 +71,7 @@ unsigned int freespace = output_song->output_size - output_song->output_offset; unsigned int copylength = freespace > bytes ? bytes : freespace; - memcpy( output_song->output_buffer + output_song->output_offset, buf, copylength ); + memcpy( (char*)(output_song->output_buffer) + output_song->output_offset, buf, copylength ); output_song->output_offset += copylength; // If we didn't copy everything, allocate a special buffer, and store it there @@ -87,7 +87,7 @@ return -1; // just stop adding output_song->stored_buffer = newbuf; - memcpy( output_song->stored_buffer + output_song->stored_size, buf + copylength, stored_size ); + memcpy( (char*)(output_song->stored_buffer) + output_song->stored_size, buf + copylength, stored_size ); output_song->stored_size = output_song->stored_size + stored_size; } else diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/optcode.h kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/optcode.h --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/optcode.h 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/optcode.h 2018-01-18 11:33:04.000000000 +0000 @@ -127,7 +127,7 @@ return result; } -#elif _MSC_VER +#elif defined(_MSC_VER) && defined(_M_IX86) inline int32 imuldiv8(int32 a, int32 b) { _asm { mov eax, a diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/playmidi.c kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/playmidi.c --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/playmidi.c 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/playmidi.c 2018-01-18 11:33:04.000000000 +0000 @@ -73,6 +73,8 @@ #ifdef SOLARIS /* shut gcc warning up */ int usleep(unsigned int useconds); +#elif defined(_WIN32) +#define usleep(X) Sleep((X) / 1000U) #endif #ifdef SUPPORT_SOUNDSPEC @@ -9154,7 +9156,7 @@ // In case there is still data in the stored_buffer, move it and return. if ( song->stored_size > 0 ) { - memmove( song->stored_buffer, song->stored_buffer + copylength, song->stored_size ); + memmove( song->stored_buffer, (char*)song->stored_buffer + copylength, song->stored_size ); song->output_offset = copylength; // and the while() loop will throw us away diff -Nru kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/reverb.c kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/reverb.c --- kodi-audiodecoder-timidity-1.1.0/lib/timidity/timidity/reverb.c 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/lib/timidity/timidity/reverb.c 2018-01-18 11:33:04.000000000 +0000 @@ -64,7 +64,7 @@ static int32 direct_buffer[AUDIO_BUFFER_SIZE * 2]; static int32 direct_bufsize = sizeof(direct_buffer); -#if OPT_MODE != 0 && ( defined(_MSC_VER) || defined(__WATCOMC__)|| (defined(__BORLANDC__) && (__BORLANDC__ >= 1380)) ) +#if OPT_MODE != 0 && ( (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)|| (defined(__BORLANDC__) && (__BORLANDC__ >= 1380)) ) void set_dry_signal(int32 *buf, int32 count) { int32 *dbuf = direct_buffer; @@ -108,7 +108,7 @@ /* XG has "dry level". */ #if OPT_MODE != 0 /* fixed-point implementation */ -#if defined(_MSC_VER) || defined(__WATCOMC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 1380)) +#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 1380)) void set_dry_signal_xg(int32 *buf, int32 count, int32 level) { int32 *dbuf = direct_buffer; @@ -920,7 +920,7 @@ static int32 reverb_effect_bufsize = sizeof(reverb_effect_buffer); #if OPT_MODE != 0 -#if defined(_MSC_VER) || defined(__WATCOMC__) || ( defined(__BORLANDC__) &&(__BORLANDC__ >= 1380) ) +#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) || ( defined(__BORLANDC__) &&(__BORLANDC__ >= 1380) ) void set_ch_reverb(int32 *buf, int32 count, int32 level) { int32 *dbuf = reverb_effect_buffer; @@ -1952,7 +1952,7 @@ } #if OPT_MODE != 0 -#if defined(_MSC_VER) || defined(__WATCOMC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) +#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) void set_ch_delay(int32 *buf, int32 count, int32 level) { int32 *dbuf = delay_effect_buffer; @@ -2264,7 +2264,7 @@ } #if OPT_MODE != 0 /* fixed-point implementation */ -#if defined(_MSC_VER) || defined(__WATCOMC__) || ( defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) +#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) || ( defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) void set_ch_chorus(int32 *buf, int32 count, int32 level) { int32 *dbuf = chorus_effect_buffer; @@ -2393,7 +2393,7 @@ } #if OPT_MODE != 0 -#if defined(_MSC_VER) || defined(__WATCOMC__) || ( defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) +#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) || ( defined(__BORLANDC__) && (__BORLANDC__ >= 1380) ) void set_ch_eq_gs(int32 *buf, int32 count) { int32 *dbuf = eq_buffer; diff -Nru kodi-audiodecoder-timidity-1.1.0/README.md kodi-audiodecoder-timidity-2.0.1/README.md --- kodi-audiodecoder-timidity-1.1.0/README.md 1970-01-01 00:00:00.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/README.md 2018-01-18 11:33:04.000000000 +0000 @@ -0,0 +1,26 @@ +# audiodecoder.timidity addon for Kodi + +This is a [Kodi](http://kodi.tv) audio decoder addon for midi files. + +[![Build Status](https://travis-ci.org/notspiff/audiodecoder.timidity.svg?branch=master)](https://travis-ci.org/notspiff/audiodecoder.timidity) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/notspiff/audiodecoder.timidity?svg=true)](https://ci.appveyor.com/project/notspiff/audiodecoder-timidity) + +## Build instructions + +When building the addon you have to use the correct branch depending on which version of Kodi you're building against. +For example, if you're building the `master` branch of Kodi you should checkout the `master` branch of this repository. +Also make sure you follow this README from the branch in question. + +### Linux + +The following instructions assume you will have built Kodi already in the `kodi-build` directory +suggested by the README. + +1. `git clone https://github.com/xbmc/xbmc.git` +2. `git clone https://github.com/notspiff/audiodecoder.timidity.git` +3. `cd audiodecoder.timidity && mkdir build && cd build` +4. `cmake -DADDONS_TO_BUILD=audiodecoder.timidity -DADDON_SRC_PREFIX=../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../xbmc/kodi-build/addons -DPACKAGE_ZIP=1 ../../xbmc/cmake/addons` +5. `make` + +The addon files will be placed in `../../xbmc/kodi-build/addons` so if you build Kodi from source and run it directly +the addon will be available as a system addon. diff -Nru kodi-audiodecoder-timidity-1.1.0/src/TimidityCodec.cpp kodi-audiodecoder-timidity-2.0.1/src/TimidityCodec.cpp --- kodi-audiodecoder-timidity-1.1.0/src/TimidityCodec.cpp 2016-11-03 16:23:52.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/src/TimidityCodec.cpp 2018-01-18 11:33:04.000000000 +0000 @@ -18,238 +18,204 @@ * */ -#include "libXBMC_addon.h" +#include +#include +#include +#include -ADDON::CHelper_libXBMC_addon *XBMC = NULL; - -extern "C" { -#include "timidity_codec.h" -#include "kodi_audiodec_dll.h" -#include "AEChannelData.h" +#include +#if !defined(_WIN32) #include +#endif -char soundfont[1024] = {0}; +extern "C" { +#include "timidity_codec.h" +} -//-- Create ------------------------------------------------------------------- -// Called on load. Addon should fully initalize or return error status -//----------------------------------------------------------------------------- -ADDON_STATUS ADDON_Create(void* hdl, void* props) +class CMyAddon : public kodi::addon::CAddonBase { - if (!XBMC) - XBMC = new ADDON::CHelper_libXBMC_addon; +public: + CMyAddon() : m_usedAmount(0) {} + virtual ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) override; - if (!XBMC->RegisterMe(hdl)) + void DecreaseUsedAmount() { - delete XBMC, XBMC=NULL; - return ADDON_STATUS_PERMANENT_FAILURE; + if (m_usedAmount > 0) + m_usedAmount--; } - return ADDON_STATUS_NEED_SETTINGS; -} +private: + int m_usedAmount; +}; -//-- Stop --------------------------------------------------------------------- -// This dll must cease all runtime activities -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -void ADDON_Stop() -{ -} +/*****************************************************************************************************/ -//-- Destroy ------------------------------------------------------------------ -// Do everything before unload of this add-on -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -void ADDON_Destroy() +class CTimidityCodec : public kodi::addon::CInstanceAudioDecoder, + private CDllHelper { - XBMC=NULL; -} +public: + CTimidityCodec(KODI_HANDLE instance, CMyAddon* addon, bool useChild); + virtual ~CTimidityCodec(); + + virtual bool Init(const std::string& filename, unsigned int filecache, + int& channels, int& samplerate, + int& bitspersample, int64_t& totaltime, + int& bitrate, AEDataFormat& format, + std::vector& channellist) override; + virtual int ReadPCM(uint8_t* buffer, int size, int& actualsize) override; + virtual int64_t Seek(int64_t time) override; + +private: + std::string m_usedLibName; + CMyAddon* m_addon; + bool m_useChild; + std::string m_soundfont; + MidiSong* m_song; + int m_pos; + + int (*Timidity_Init)(int rate, int bits_per_sample, int channels, const char * soundfont_file, const char* cfgfile); + void (*Timidity_Cleanup)(); + int (*Timidity_GetLength)(MidiSong *song); + MidiSong *(*Timidity_LoadSong)(char *fn); + void (*Timidity_FreeSong)(MidiSong *song); + int (*Timidity_FillBuffer)(MidiSong* song, void *buf, unsigned int size); + unsigned long (*Timidity_Seek)(MidiSong *song, unsigned long iTimePos); + char *(*Timidity_ErrorMsg)(); +}; -//-- HasSettings -------------------------------------------------------------- -// Returns true if this add-on use settings -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -bool ADDON_HasSettings() -{ - return true; -} +/*****************************************************************************************************/ -//-- GetStatus --------------------------------------------------------------- -// Returns the current Status of this visualisation -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -ADDON_STATUS ADDON_GetStatus() +ADDON_STATUS CMyAddon::CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) { + addonInstance = new CTimidityCodec(instance, this, ++m_usedAmount > 1); return ADDON_STATUS_OK; } -//-- GetSettings -------------------------------------------------------------- -// Return the settings for XBMC to display -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -unsigned int ADDON_GetSettings(ADDON_StructSetting ***sSet) -{ - return 0; -} - -//-- FreeSettings -------------------------------------------------------------- -// Free the settings struct passed from XBMC -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- - -void ADDON_FreeSettings() -{ -} +/*****************************************************************************************************/ -//-- SetSetting --------------------------------------------------------------- -// Set a specific Setting value (called from XBMC) -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -ADDON_STATUS ADDON_SetSetting(const char *strSetting, const void* value) +CTimidityCodec::CTimidityCodec(KODI_HANDLE instance, CMyAddon* addon, bool useChild) + : CInstanceAudioDecoder(instance), + m_addon(addon), + m_useChild(useChild), + m_song(nullptr) { - if (strcmp(strSetting,"soundfont") == 0) - strcpy(soundfont, (const char*)value); + if (m_useChild) + { + std::string source = kodi::GetAddonPath(StringUtils::Format("%stimidity%s", LIBRARY_PREFIX, LIBRARY_SUFFIX)); + m_usedLibName = kodi::GetTempAddonPath(StringUtils::Format("%stimidity-%p%s", LIBRARY_PREFIX, this, LIBRARY_SUFFIX)); + if (!kodi::vfs::CopyFile(source, m_usedLibName)) + { + kodi::Log(ADDON_LOG_ERROR, "Failed to create libtimidity copy"); + return; + } + } + else + m_usedLibName = kodi::GetAddonPath(StringUtils::Format("%stimidity%s", LIBRARY_PREFIX, LIBRARY_SUFFIX)); - return ADDON_STATUS_OK; + m_soundfont = kodi::GetSettingString("soundfont"); } -//-- Announce ----------------------------------------------------------------- -// Receive announcements from XBMC -// !!! Add-on master function !!! -//----------------------------------------------------------------------------- -void ADDON_Announce(const char *flag, const char *sender, const char *message, const void *data) +CTimidityCodec::~CTimidityCodec() { -} + if (m_song) + Timidity_FreeSong(m_song); -struct TimidityContext -{ - MidiSong* song; - size_t pos; -}; + if (m_useChild) + kodi::vfs::DeleteFile(m_usedLibName); -#define SET_IF(ptr, value) \ -{ \ - if ((ptr)) \ - *(ptr) = (value); \ + m_addon->DecreaseUsedAmount(); } -void* Init(const char* strFile, unsigned int filecache, int* channels, - int* samplerate, int* bitspersample, int64_t* totaltime, - int* bitrate, AEDataFormat* format, const AEChannel** channelinfo) +bool CTimidityCodec::Init(const std::string& filename, unsigned int filecache, + int& channels, int& samplerate, + int& bitspersample, int64_t& totaltime, + int& bitrate, AEDataFormat& format, + std::vector& channellist) { - if (strlen(soundfont) == 0) - return NULL; + if (m_soundfont.empty()) + return false; + + if (!LoadDll(m_usedLibName)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_Init)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_Cleanup)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_GetLength)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_LoadSong)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_FreeSong)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_FillBuffer)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_Seek)) return false; + if (!REGISTER_DLL_SYMBOL(Timidity_ErrorMsg)) return false; int res; - if (strstr(soundfont,".sf2")) - res = Timidity_Init(48000, 16, 2, soundfont, NULL); // real soundfont + if (m_soundfont.find(".sf2") != std::string::npos) + res = Timidity_Init(48000, 16, 2, m_soundfont.c_str(), nullptr); // real soundfont else - res = Timidity_Init(48000, 16, 2, NULL, soundfont); // config file + res = Timidity_Init(48000, 16, 2, nullptr, m_soundfont.c_str()); // config file if (res != 0) - return NULL; + return false; - void* file = XBMC->OpenFile(strFile, 0); - if (!file) - return NULL; + kodi::vfs::CFile file; + if (!file.OpenFile(filename)) + return false; - int len = XBMC->GetFileLength(file); + int len = file.GetLength(); uint8_t* data = new uint8_t[len]; if (!data) - { - XBMC->CloseFile(file); - return NULL; - } - XBMC->ReadFile(file, data, len); - XBMC->CloseFile(file); + return false; - const char* tempfile = tmpnam(NULL); + file.Read(data, len); + + const char* tempfile = tmpnam(nullptr); FILE* f = fopen(tempfile,"wb"); if (!f) { delete[] data; - return NULL; + return false; } fwrite(data, 1, len, f); fclose(f); delete[] data; - TimidityContext* result = new TimidityContext; - if (!result) - return NULL; - - result->song = Timidity_LoadSong((char*)tempfile); + m_song = Timidity_LoadSong((char*)tempfile); unlink(tempfile); - if (!result->song) - { - delete result; - return NULL; - } + if (!m_song) + return false; - result->pos = 0; + m_pos = 0; - SET_IF(channels, 2) - SET_IF(samplerate, 48000) - SET_IF(bitspersample, 16) - SET_IF(totaltime, Timidity_GetLength(result->song)) - SET_IF(format, AE_FMT_S16NE) - static enum AEChannel map[3] = { - AE_CH_FL, AE_CH_FR, AE_CH_NULL - }; - SET_IF(channelinfo, map) - SET_IF(bitrate, 0) + channels = 2; + samplerate = 48000; + bitspersample = 16; + totaltime = Timidity_GetLength(m_song); + format = AE_FMT_S16NE; + channellist = { AE_CH_FL, AE_CH_FR }; + bitrate = 0; - return result; + return true; } -int ReadPCM(void* context, uint8_t* pBuffer, int size, int *actualsize) +int CTimidityCodec::ReadPCM(uint8_t* buffer, int size, int& actualsize) { - if (!context || !pBuffer || !actualsize) - return 1; + if (!buffer) + return -1; - TimidityContext* ctx = (TimidityContext*)context; + if (m_pos > Timidity_GetLength(m_song)/1000*48000*4) + return -1; - if (ctx->pos > Timidity_GetLength(ctx->song)/1000*48000*4) + actualsize = Timidity_FillBuffer(m_song, buffer, size); + if (actualsize == 0) return -1; - *actualsize = Timidity_FillBuffer(ctx->song, pBuffer, size); - ctx->pos += *actualsize; + m_pos += actualsize; return 0; } -int64_t Seek(void* context, int64_t time) +int64_t CTimidityCodec::Seek(int64_t time) { - if (!context) - return 0; - - TimidityContext* ctx = (TimidityContext*)context; - - return Timidity_Seek(ctx->song, time); + return Timidity_Seek(m_song, time); } -bool DeInit(void* context) -{ - if (!context) - return true; - - TimidityContext* ctx = (TimidityContext*)context; - - Timidity_FreeSong(ctx->song); - delete ctx; - - return true; -} - -bool ReadTag(const char* strFile, char* title, char* artist, - int* length) -{ - return true; -} - -int TrackCount(const char* strFile) -{ - return 1; -} -} +ADDONCREATOR(CMyAddon) diff -Nru kodi-audiodecoder-timidity-1.1.0/.travis.yml kodi-audiodecoder-timidity-2.0.1/.travis.yml --- kodi-audiodecoder-timidity-1.1.0/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ kodi-audiodecoder-timidity-2.0.1/.travis.yml 2018-01-18 11:33:04.000000000 +0000 @@ -0,0 +1,50 @@ +language: cpp + +# +# Define the build matrix +# +# Travis defaults to building on Ubuntu Precise when building on +# Linux. We need Trusty in order to get up to date versions of +# cmake and g++. +# +env: + global: + - app_id=audiodecoder.timidity + +matrix: + include: + - os: linux + dist: trusty + sudo: required + compiler: gcc + - os: linux + dist: trusty + sudo: required + compiler: clang + - os: osx + osx_image: xcode7.3 + - os: osx + osx_image: xcode6.1 + +# +# Some of the OS X images don't have cmake, contrary to what people +# on the Internet say +# +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then which cmake || brew update ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then which cmake || brew install cmake ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew upgrade cmake || true; fi + +# +# The addon source is automatically checked out in $TRAVIS_BUILD_DIR, +# we'll put the Kodi source on the same level +# +before_script: + - cd $TRAVIS_BUILD_DIR/.. + - git clone --depth=1 https://github.com/xbmc/xbmc.git + - cd ${app_id} && mkdir build && cd build + - mkdir -p definition/${app_id} + - echo ${app_id} $TRAVIS_BUILD_DIR $TRAVIS_COMMIT > definition/${app_id}/${app_id}.txt + - cmake -DADDONS_TO_BUILD=${app_id} -DADDON_SRC_PREFIX=$TRAVIS_BUILD_DIR/.. -DADDONS_DEFINITION_DIR=$TRAVIS_BUILD_DIR/build/definition -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/../xbmc/addons -DPACKAGE_ZIP=1 $TRAVIS_BUILD_DIR/../xbmc/cmake/addons + +script: make