diff --git a/cmake/modules/BuildPlugin.cmake b/cmake/modules/BuildPlugin.cmake index 1722e3dce..a527b8472 100644 --- a/cmake/modules/BuildPlugin.cmake +++ b/cmake/modules/BuildPlugin.cmake @@ -9,7 +9,7 @@ MACRO(BUILD_PLUGIN PLUGIN_NAME) CMAKE_PARSE_ARGUMENTS(PLUGIN "" "" "MOCFILES;EMBEDDED_RESOURCES;UICFILES;LINK" ${ARGN}) SET(PLUGIN_SOURCES ${PLUGIN_UNPARSED_ARGUMENTS}) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include) + INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/include") ADD_DEFINITIONS(-DPLUGIN_NAME=${PLUGIN_NAME}) @@ -22,7 +22,7 @@ MACRO(BUILD_PLUGIN PLUGIN_NAME) FILE(GLOB EXPANDED "${ARG}") LIST(SORT EXPANDED) FOREACH(ITEM ${EXPANDED}) - LIST(APPEND NEW_ARGS ${ITEM}) + LIST(APPEND NEW_ARGS "${ITEM}") ENDFOREACH() ENDFOREACH() SET(PLUGIN_EMBEDDED_RESOURCES ${NEW_ARGS}) @@ -38,11 +38,11 @@ MACRO(BUILD_PLUGIN PLUGIN_NAME) ENDFOREACH(f) IF(LMMS_BUILD_APPLE) - LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) + LINK_DIRECTORIES("${CMAKE_BINARY_DIR}") LINK_LIBRARIES(${QT_LIBRARIES}) ENDIF(LMMS_BUILD_APPLE) IF(LMMS_BUILD_WIN32) - LINK_DIRECTORIES(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) + LINK_DIRECTORIES("${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}") LINK_LIBRARIES(${QT_LIBRARIES}) ENDIF(LMMS_BUILD_WIN32) IF(LMMS_BUILD_MSYS AND CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -65,12 +65,12 @@ MACRO(BUILD_PLUGIN PLUGIN_NAME) INSTALL(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION "${PLUGIN_DIR}") IF(LMMS_BUILD_APPLE) - SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-bundle_loader ${CMAKE_BINARY_DIR}/lmms") + SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-bundle_loader \"${CMAKE_BINARY_DIR}/lmms\"") ADD_DEPENDENCIES(${PLUGIN_NAME} lmms) ENDIF(LMMS_BUILD_APPLE) IF(LMMS_BUILD_WIN32 AND STRIP) SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES PREFIX "") - ADD_CUSTOM_COMMAND(TARGET ${PLUGIN_NAME} POST_BUILD COMMAND ${STRIP} $) + ADD_CUSTOM_COMMAND(TARGET ${PLUGIN_NAME} POST_BUILD COMMAND ${STRIP} "$") ENDIF() SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${RCC_OUT} ${plugin_MOC_out}") diff --git a/cmake/modules/FindSndio.cmake b/cmake/modules/FindSndio.cmake index bf5b24c39..3fcd71360 100644 --- a/cmake/modules/FindSndio.cmake +++ b/cmake/modules/FindSndio.cmake @@ -19,14 +19,16 @@ if(SNDIO_LIBRARY) get_filename_component(SNDIO_LIBRARY_DIR ${SNDIO_LIBRARY} PATH) endif(SNDIO_LIBRARY) -check_library_exists(sndio sio_open "${SNDIO_LIBRARY_DIR}" HAVE_SNDIO) -if(HAVE_SNDIO) - message(STATUS "Found sndio: ${SNDIO_LIBRARY}") -else(HAVE_SNDIO) - message(STATUS "sndio not found") +check_library_exists(sndio sio_open "${SNDIO_LIBRARY_DIR}" HAVE_SIO_OPEN) + +find_path(SNDIO_INCLUDE_DIR sndio.h) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SNDIO DEFAULT_MSG SNDIO_LIBRARY SNDIO_INCLUDE_DIR HAVE_SIO_OPEN) + +if(SNDIO_FOUND) + set(SNDIO_INCLUDE_DIRS "${SNDIO_INCLUDE_DIR}") + set(SNDIO_LIBRARIES "${SNDIO_LIBRARY}") endif(HAVE_SNDIO) -set(SNDIO_FOUND ${HAVE_SNDIO}) -find_path(SNDIO_INCLUDES sndio.h) - -mark_as_advanced(SNDIO_INCLUDES SNDIO_LIBRARY) +mark_as_advanced(SNDIO_INCLUDE_DIR SNDIO_LIBRARY SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES) diff --git a/data/locale/sv.ts b/data/locale/sv.ts index 3b75e54c0..6f0120deb 100644 --- a/data/locale/sv.ts +++ b/data/locale/sv.ts @@ -3939,7 +3939,7 @@ Besök https://lmms.io/documentation/ för dokumentation (Engelska). &View - %Visa + &Visa Toggle metronome @@ -9950,4 +9950,4 @@ The LED in the lower right corner of the waveform editor determines whether the Utgångsförstärkning - \ No newline at end of file + diff --git a/include/AudioFileDevice.h b/include/AudioFileDevice.h index 7b6b81eab..e7177b30f 100644 --- a/include/AudioFileDevice.h +++ b/include/AudioFileDevice.h @@ -56,6 +56,10 @@ protected: return m_outputFile.isOpen(); } + inline int outputFileHandle() const + { + return m_outputFile.handle(); + } private: QFile m_outputFile; diff --git a/include/DrumSynth.h b/include/DrumSynth.h index 22d7d3071..f7e9b1d4c 100644 --- a/include/DrumSynth.h +++ b/include/DrumSynth.h @@ -30,22 +30,24 @@ #include #include "lmms_basics.h" +class QString; + class DrumSynth { public: DrumSynth() {}; - int GetDSFileSamples(const char *dsfile, int16_t *&wave, int channels, sample_rate_t Fs); + int GetDSFileSamples(QString dsfile, int16_t *&wave, int channels, sample_rate_t Fs); private: float LoudestEnv(void); int LongestEnv(void); void UpdateEnv(int e, long t); - void GetEnv(int env, const char *sec, const char *key, const char *ini); + void GetEnv(int env, const char *sec, const char *key, QString ini); float waveform(float ph, int form); - int GetPrivateProfileString(const char *sec, const char *key, const char *def, char *buffer, int size, const char *file); - int GetPrivateProfileInt(const char *sec, const char *key, int def, const char *file); - float GetPrivateProfileFloat(const char *sec, const char *key, float def, const char *file); + int GetPrivateProfileString(const char *sec, const char *key, const char *def, char *buffer, int size, QString file); + int GetPrivateProfileInt(const char *sec, const char *key, int def, QString file); + float GetPrivateProfileFloat(const char *sec, const char *key, float def, QString file); }; diff --git a/include/ImportFilter.h b/include/ImportFilter.h index 304de5fa4..1b6fe2b59 100644 --- a/include/ImportFilter.h +++ b/include/ImportFilter.h @@ -78,6 +78,11 @@ protected: return m_file.read( _data, _len ); } + inline QByteArray readAllData() + { + return m_file.readAll(); + } + inline void ungetChar( char _ch ) { m_file.ungetChar( _ch ); diff --git a/include/IoHelper.h b/include/IoHelper.h new file mode 100644 index 000000000..687e000d1 --- /dev/null +++ b/include/IoHelper.h @@ -0,0 +1,72 @@ +/* + * IoHelper.h - helper functions for file I/O + * + * Copyright (c) 2018 Hyunjin Song + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#include "lmmsconfig.h" + +#include + + +#ifdef _WIN32 +#include + +std::wstring toWString(const std::string& s) +{ + std::wstring ret; + int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), + s.length(), nullptr, 0); + if (len == 0) + { + return ret; + } + ret.resize(len); + MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s.length(), &ret[0], len); + return ret; +} +#endif + +#ifdef LMMS_BUILD_WIN32 +#include +#define F_OPEN_UTF8(a, b) _wfopen(toWString(a).data(), L##b) +#else +#ifdef LMMS_HAVE_UNISTD_H +#include +#endif +#define F_OPEN_UTF8(a, b) fopen((a).data(), b) +#endif + +int fileToDescriptor(FILE* f, bool closeFile = true) +{ + int fh; + if (f == NULL) {return -1;} + +#ifdef LMMS_BUILD_WIN32 + fh = _dup(_fileno(f)); +#else + fh = dup(fileno(f)); +#endif + + if (closeFile) {fclose(f);} + return fh; +} diff --git a/include/MainApplication.h b/include/MainApplication.h index d3acb95ca..4edf55d5e 100644 --- a/include/MainApplication.h +++ b/include/MainApplication.h @@ -3,7 +3,7 @@ * * Copyright (c) 2017-2017 Tres Finocchiaro * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/include/SampleBuffer.h b/include/SampleBuffer.h index 01c685fda..974da669f 100644 --- a/include/SampleBuffer.h +++ b/include/SampleBuffer.h @@ -270,15 +270,15 @@ private: void convertIntToFloat ( int_sample_t * & _ibuf, f_cnt_t _frames, int _channels); void directFloatWrite ( sample_t * & _fbuf, f_cnt_t _frames, int _channels); - f_cnt_t decodeSampleSF( const char * _f, sample_t * & _buf, + f_cnt_t decodeSampleSF( QString _f, sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _sample_rate ); #ifdef LMMS_HAVE_OGGVORBIS - f_cnt_t decodeSampleOGGVorbis( const char * _f, int_sample_t * & _buf, + f_cnt_t decodeSampleOGGVorbis( QString _f, int_sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _sample_rate ); #endif - f_cnt_t decodeSampleDS( const char * _f, int_sample_t * & _buf, + f_cnt_t decodeSampleDS( QString _f, int_sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _sample_rate ); diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index cb36db03f..392a2ad45 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,5 +1,5 @@ -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") SET(CMAKE_DEBUG_POSTFIX "") # Enable C++11 diff --git a/plugins/LadspaEffect/swh/CMakeLists.txt b/plugins/LadspaEffect/swh/CMakeLists.txt index fb8b03400..7703aaa6d 100644 --- a/plugins/LadspaEffect/swh/CMakeLists.txt +++ b/plugins/LadspaEffect/swh/CMakeLists.txt @@ -8,13 +8,6 @@ ELSE() SET(PIC_FLAGS "-fPIC -DPIC") ENDIF() -# Additional link flags -IF(LMMS_BUILD_WIN32 AND MINGW_PREFIX) - SET(LINK_FLAGS "${LINK_FLAGS} -shared -Wl,-no-undefined -Wl,-Bsymbolic -lm") -ELSEIF(LMMS_BUILD_APPLE) - SET(LINK_FLAGS "${LINK_FLAGS} -Bsymbolic -lm") -ENDIF() - # Additional compile flags SET(COMPILE_FLAGS "${COMPILE_FLAGS} -O3 -Wall") SET(COMPILE_FLAGS "${COMPILE_FLAGS} -fomit-frame-pointer -funroll-loops -ffast-math -c -fno-strict-aliasing") @@ -44,6 +37,9 @@ FOREACH(_item ${XML_SOURCES}) IF(NOT ("${_plugin}" STREQUAL "vocoder_1337")) TARGET_LINK_LIBRARIES("${_plugin}" -lfftw3f) ENDIF() + IF(NOT MSVC) + TARGET_LINK_LIBRARIES("${_plugin}" m) + ENDIF() SET_TARGET_PROPERTIES("${_plugin}" PROPERTIES PREFIX "") SET_TARGET_PROPERTIES("${_plugin}" PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}") diff --git a/plugins/LadspaEffect/tap/CMakeLists.txt b/plugins/LadspaEffect/tap/CMakeLists.txt index 0ae8ae54e..e0740bd5e 100644 --- a/plugins/LadspaEffect/tap/CMakeLists.txt +++ b/plugins/LadspaEffect/tap/CMakeLists.txt @@ -15,13 +15,8 @@ FOREACH(_item ${PLUGIN_SOURCES}) IF(LMMS_BUILD_WIN32 AND NOT CMAKE_BUILD_TYPE MATCHES "Deb") ADD_CUSTOM_COMMAND(TARGET "${_plugin}" POST_BUILD COMMAND "${STRIP}" \"$\") ENDIF() - IF(LMMS_BUILD_APPLE) - SET_TARGET_PROPERTIES("${_plugin}" PROPERTIES LINK_FLAGS "${LINK_FLAGS} -Bsymbolic -lm") - ELSEIF(NOT LMMS_BUILD_OPENBSD) - SET_TARGET_PROPERTIES("${_plugin}" PROPERTIES LINK_FLAGS "${LINK_FLAGS} -shared -Wl,-no-undefined -Wl,-Bsymbolic -lm") - ENDIF() - IF(LMMS_BUILD_LINUX OR LMMS_BUILD_HAIKU) - SET_TARGET_PROPERTIES("${_plugin}" PROPERTIES LINK_FLAGS "${LINK_FLAGS}") + IF(NOT MSVC) + TARGET_LINK_LIBRARIES("${_plugin}" m) ENDIF() ENDFOREACH() diff --git a/plugins/MidiImport/MidiImport.cpp b/plugins/MidiImport/MidiImport.cpp index 833994e5e..1200c6f78 100644 --- a/plugins/MidiImport/MidiImport.cpp +++ b/plugins/MidiImport/MidiImport.cpp @@ -26,9 +26,12 @@ #include #include #include +#include #include #include +#include + #include "MidiImport.h" #include "TrackContainer.h" #include "InstrumentTrack.h" @@ -279,8 +282,6 @@ public: bool MidiImport::readSMF( TrackContainer* tc ) { - QString filename = file().fileName(); - closeFile(); const int preTrackSteps = 2; QProgressDialog pd( TrackContainer::tr( "Importing MIDI-file..." ), @@ -291,7 +292,11 @@ bool MidiImport::readSMF( TrackContainer* tc ) pd.setValue( 0 ); - Alg_seq_ptr seq = new Alg_seq(filename.toLocal8Bit(), true); + std::stringstream stream; + QByteArray arr = readAllData(); + stream.str(std::string(arr.constData(), arr.size())); + + Alg_seq_ptr seq = new Alg_seq(stream, true); seq->convert_to_beats(); pd.setMaximum( seq->tracks() + preTrackSteps ); diff --git a/plugins/ReverbSC/ReverbSC.cpp b/plugins/ReverbSC/ReverbSC.cpp index bfbd0390a..bae59471c 100644 --- a/plugins/ReverbSC/ReverbSC.cpp +++ b/plugins/ReverbSC/ReverbSC.cpp @@ -1,7 +1,7 @@ /* * ReverbSC.cpp - A native reverb based on an algorithm by Sean Costello * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/ReverbSC/ReverbSC.h b/plugins/ReverbSC/ReverbSC.h index ba987414b..0e697c197 100644 --- a/plugins/ReverbSC/ReverbSC.h +++ b/plugins/ReverbSC/ReverbSC.h @@ -3,7 +3,7 @@ * * Copyright (c) 2017 Paul Batchelor * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/ReverbSC/ReverbSCControlDialog.cpp b/plugins/ReverbSC/ReverbSCControlDialog.cpp index 6b41415d9..9c9f3f44a 100644 --- a/plugins/ReverbSC/ReverbSCControlDialog.cpp +++ b/plugins/ReverbSC/ReverbSCControlDialog.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 2017 Paul Batchelor * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/ReverbSC/ReverbSCControlDialog.h b/plugins/ReverbSC/ReverbSCControlDialog.h index 9f262a88f..0d9c1f51a 100644 --- a/plugins/ReverbSC/ReverbSCControlDialog.h +++ b/plugins/ReverbSC/ReverbSCControlDialog.h @@ -3,7 +3,7 @@ * * Copyright (c) 2017 Paul Batchelor * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/ReverbSC/ReverbSCControls.cpp b/plugins/ReverbSC/ReverbSCControls.cpp index ac6f8c689..0b9e337b4 100644 --- a/plugins/ReverbSC/ReverbSCControls.cpp +++ b/plugins/ReverbSC/ReverbSCControls.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 2017 Paul Batchelor * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/ReverbSC/ReverbSCControls.h b/plugins/ReverbSC/ReverbSCControls.h index 638bdade9..36cc16a7e 100644 --- a/plugins/ReverbSC/ReverbSCControls.h +++ b/plugins/ReverbSC/ReverbSCControls.h @@ -3,7 +3,7 @@ * * Copyright (c) 2017 Paul Batchelor * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/plugins/stk/mallets/mallets.cpp b/plugins/stk/mallets/mallets.cpp index 621d1e5c7..964e1ddd2 100644 --- a/plugins/stk/mallets/mallets.cpp +++ b/plugins/stk/mallets/mallets.cpp @@ -620,7 +620,7 @@ malletsSynth::malletsSynth( const StkFloat _pitch, { Stk::setSampleRate( _sample_rate ); Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath() - .toLatin1().constData() ); + .toLocal8Bit().constData() ); #ifndef LMMS_DEBUG Stk::showWarnings( false ); #endif @@ -670,7 +670,7 @@ malletsSynth::malletsSynth( const StkFloat _pitch, { Stk::setSampleRate( _sample_rate ); Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath() - .toLatin1().constData() ); + .toLocal8Bit().constData() ); #ifndef LMMS_DEBUG Stk::showWarnings( false ); #endif @@ -718,7 +718,7 @@ malletsSynth::malletsSynth( const StkFloat _pitch, { Stk::setSampleRate( _sample_rate ); Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath() - .toLatin1().constData() ); + .toLocal8Bit().constData() ); #ifndef LMMS_DEBUG Stk::showWarnings( false ); #endif diff --git a/plugins/vst_base/RemoteVstPlugin.cpp b/plugins/vst_base/RemoteVstPlugin.cpp index a51ac9d9a..174a80caa 100644 --- a/plugins/vst_base/RemoteVstPlugin.cpp +++ b/plugins/vst_base/RemoteVstPlugin.cpp @@ -88,6 +88,7 @@ struct ERect #include "lmms_basics.h" #include "Midi.h" #include "communication.h" +#include "IoHelper.h" #include "VstSyncData.h" @@ -678,9 +679,9 @@ void RemoteVstPlugin::init( const std::string & _plugin_file ) -static void close_check( int fd ) +static void close_check( FILE* fp ) { - if( close( fd ) ) + if( fclose( fp ) ) { perror( "close" ); } @@ -790,7 +791,7 @@ void RemoteVstPlugin::destroyEditor() bool RemoteVstPlugin::load( const std::string & _plugin_file ) { - if( ( m_libInst = LoadLibrary( _plugin_file.c_str() ) ) == NULL ) + if( ( m_libInst = LoadLibraryW( toWString(_plugin_file).c_str() ) ) == NULL ) { // give VstPlugin class a chance to start 32 bit version of RemoteVstPlugin if( GetLastError() == ERROR_BAD_EXE_FORMAT ) @@ -1072,13 +1073,13 @@ void RemoteVstPlugin::saveChunkToFile( const std::string & _file ) const int len = pluginDispatch( 23, 0, 0, &chunk ); if( len > 0 ) { - int fd = open( _file.c_str(), O_WRONLY | O_BINARY ); - if ( ::write( fd, chunk, len ) != len ) + FILE* fp = F_OPEN_UTF8( _file, "wb" ); + if ( fwrite( chunk, len, 1, fp ) != len ) { fprintf( stderr, "Error saving chunk to file.\n" ); } - close_check( fd ); + close_check( fp ); } } } @@ -1237,7 +1238,7 @@ void RemoteVstPlugin::savePreset( const std::string & _file ) if (!isPreset &&!chunky) uIntToFile = (unsigned int) m_plugin->numPrograms; pBank->numPrograms = endian_swap( uIntToFile ); - FILE * stream = fopen( _file.c_str(), "w" ); + FILE * stream = F_OPEN_UTF8( _file, "w" ); fwrite ( pBank, 1, 28, stream ); fwrite ( progName, 1, isPreset ? 28 : 128, stream ); if ( chunky ) { @@ -1289,7 +1290,7 @@ void RemoteVstPlugin::loadPresetFile( const std::string & _file ) unsigned int * pLen = new unsigned int[ 1 ]; unsigned int len = 0; sBank * pBank = (sBank*) new char[ sizeof( sBank ) ]; - FILE * stream = fopen( _file.c_str(), "r" ); + FILE * stream = F_OPEN_UTF8( _file, "r" ); if ( fread ( pBank, 1, 56, stream ) != 56 ) { fprintf( stderr, "Error loading preset file.\n" ); @@ -1390,12 +1391,12 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len ) { char * chunk = new char[_len]; - const int fd = open( _file.c_str(), O_RDONLY | O_BINARY ); - if ( ::read( fd, chunk, _len ) != _len ) + FILE* fp = F_OPEN_UTF8( _file, "rb" ); + if ( fread( chunk, 1, _len, fp ) != _len ) { fprintf( stderr, "Error loading chunk from file.\n" ); } - close_check( fd ); + close_check( fp ); pluginDispatch( effSetChunk, 0, _len, chunk ); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd3a37fcc..23be36820 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -139,7 +139,7 @@ SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS} ${SDL2_LIBRARY} ${PORTAUDIO_LIBRARIES} ${SOUNDIO_LIBRARY} - ${SNDIO_LIBRARY} + ${SNDIO_LIBRARIES} ${PULSEAUDIO_LIBRARIES} ${JACK_LIBRARIES} ${OGGVORBIS_LIBRARIES} diff --git a/src/core/DrumSynth.cpp b/src/core/DrumSynth.cpp index 3379f1aa7..cfa85ceb6 100644 --- a/src/core/DrumSynth.cpp +++ b/src/core/DrumSynth.cpp @@ -26,11 +26,13 @@ #include "DrumSynth.h" -#include +#include #include #include //sin(), exp(), etc. +#include + #ifdef LMMS_BUILD_WIN32 #define powf pow #endif @@ -117,7 +119,7 @@ void DrumSynth::UpdateEnv(int e, long t) } -void DrumSynth::GetEnv(int env, const char *sec, const char *key, const char *ini) +void DrumSynth::GetEnv(int env, const char *sec, const char *key, QString ini) { char en[256], s[8]; int i=0, o=0, ep=0; @@ -167,9 +169,9 @@ float DrumSynth::waveform(float ph, int form) } -int DrumSynth::GetPrivateProfileString(const char *sec, const char *key, const char *def, char *buffer, int size, const char *file) +int DrumSynth::GetPrivateProfileString(const char *sec, const char *key, const char *def, char *buffer, int size, QString file) { - ifstream is; + stringstream is; bool inSection = false; char *line; char *k, *b; @@ -177,7 +179,12 @@ int DrumSynth::GetPrivateProfileString(const char *sec, const char *key, const c line = (char*)malloc(200); - is.open (file, ifstream::in); + // Use QFile to handle unicode file name on Windows + // Previously we used ifstream directly + QFile f(file); + f.open(QIODevice::ReadOnly); + QByteArray dat = f.readAll().constData(); + is.str(string(dat.constData(), dat.size())); while (is.good()) { if (!inSection) { @@ -223,13 +230,12 @@ int DrumSynth::GetPrivateProfileString(const char *sec, const char *key, const c strncpy(buffer, def, size); } - is.close(); free(line); return len; } -int DrumSynth::GetPrivateProfileInt(const char *sec, const char *key, int def, const char *file) +int DrumSynth::GetPrivateProfileInt(const char *sec, const char *key, int def, QString file) { char tmp[16]; int i=0; @@ -240,7 +246,7 @@ int DrumSynth::GetPrivateProfileInt(const char *sec, const char *key, int def, c return i; } -float DrumSynth::GetPrivateProfileFloat(const char *sec, const char *key, float def, const char *file) +float DrumSynth::GetPrivateProfileFloat(const char *sec, const char *key, float def, QString file) { char tmp[16]; float f=0.f; @@ -257,7 +263,7 @@ float DrumSynth::GetPrivateProfileFloat(const char *sec, const char *key, float // an associative array or something once we have a datastructure to load in to. // llama -int DrumSynth::GetDSFileSamples(const char *dsfile, int16_t *&wave, int channels, sample_rate_t Fs) +int DrumSynth::GetDSFileSamples(QString dsfile, int16_t *&wave, int channels, sample_rate_t Fs) { //input file char sec[32]; diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index 9cde88cf5..76afa5599 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -175,11 +175,6 @@ void SampleBuffer::update( bool _keep_settings ) else if( !m_audioFile.isEmpty() ) { QString file = tryToMakeAbsolute( m_audioFile ); -#ifdef LMMS_BUILD_WIN32 - char * f = qstrdup( file.toLocal8Bit().constData() ); -#else - char * f = qstrdup( file.toUtf8().constData() ); -#endif int_sample_t * buf = NULL; sample_t * fbuf = NULL; ch_cnt_t channels = DEFAULT_CHANNELS; @@ -193,10 +188,13 @@ void SampleBuffer::update( bool _keep_settings ) } else { + // Use QFile to handle unicode file names on Windows + QFile f(file); + f.open(QIODevice::ReadOnly); SNDFILE * snd_file; SF_INFO sf_info; sf_info.format = 0; - if( ( snd_file = sf_open( f, SFM_READ, &sf_info ) ) != NULL ) + if( ( snd_file = sf_open_fd( f.handle(), SFM_READ, &sf_info, false ) ) != NULL ) { f_cnt_t frames = sf_info.frames; int rate = sf_info.samplerate; @@ -206,6 +204,7 @@ void SampleBuffer::update( bool _keep_settings ) } sf_close( snd_file ); } + f.close(); } if( !fileLoadError ) @@ -216,28 +215,26 @@ void SampleBuffer::update( bool _keep_settings ) // decoder first if filename extension matches "ogg" if( m_frames == 0 && fileInfo.suffix() == "ogg" ) { - m_frames = decodeSampleOGGVorbis( f, buf, channels, samplerate ); + m_frames = decodeSampleOGGVorbis( file, buf, channels, samplerate ); } #endif if( m_frames == 0 ) { - m_frames = decodeSampleSF( f, fbuf, channels, + m_frames = decodeSampleSF( file, fbuf, channels, samplerate ); } #ifdef LMMS_HAVE_OGGVORBIS if( m_frames == 0 ) { - m_frames = decodeSampleOGGVorbis( f, buf, channels, + m_frames = decodeSampleOGGVorbis( file, buf, channels, samplerate ); } #endif if( m_frames == 0 ) { - m_frames = decodeSampleDS( f, buf, channels, + m_frames = decodeSampleDS( file, buf, channels, samplerate ); } - - delete[] f; } if ( m_frames == 0 || fileLoadError ) // if still no frames, bail @@ -393,7 +390,7 @@ void SampleBuffer::normalizeSampleRate( const sample_rate_t _src_sr, -f_cnt_t SampleBuffer::decodeSampleSF( const char * _f, +f_cnt_t SampleBuffer::decodeSampleSF(QString _f, sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _samplerate ) @@ -404,7 +401,11 @@ f_cnt_t SampleBuffer::decodeSampleSF( const char * _f, f_cnt_t frames = 0; bool sf_rr = false; - if( ( snd_file = sf_open( _f, SFM_READ, &sf_info ) ) != NULL ) + + // Use QFile to handle unicode file names on Windows + QFile f(_f); + f.open(QIODevice::ReadOnly); + if( ( snd_file = sf_open_fd( f.handle(), SFM_READ, &sf_info, false ) ) != NULL ) { frames = sf_info.frames; @@ -430,6 +431,8 @@ f_cnt_t SampleBuffer::decodeSampleSF( const char * _f, "sample %s: %s", _f, sf_strerror( NULL ) ); #endif } + f.close(); + //write down either directly or convert i->f depending on file type if ( frames > 0 && _buf != NULL ) @@ -495,7 +498,7 @@ long qfileTellCallback( void * _udata ) -f_cnt_t SampleBuffer::decodeSampleOGGVorbis( const char * _f, +f_cnt_t SampleBuffer::decodeSampleOGGVorbis( QString _f, int_sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _samplerate ) @@ -591,7 +594,7 @@ f_cnt_t SampleBuffer::decodeSampleOGGVorbis( const char * _f, -f_cnt_t SampleBuffer::decodeSampleDS( const char * _f, +f_cnt_t SampleBuffer::decodeSampleDS( QString _f, int_sample_t * & _buf, ch_cnt_t & _channels, sample_rate_t & _samplerate ) diff --git a/src/core/audio/AudioFileWave.cpp b/src/core/audio/AudioFileWave.cpp index 45e46b838..8a590a8b8 100644 --- a/src/core/audio/AudioFileWave.cpp +++ b/src/core/audio/AudioFileWave.cpp @@ -27,6 +27,9 @@ #include "endian_handling.h" #include "Mixer.h" +#include +#include + AudioFileWave::AudioFileWave( OutputSettings const & outputSettings, const ch_cnt_t channels, bool & successful, @@ -72,13 +75,15 @@ bool AudioFileWave::startEncoding() m_si.format |= SF_FORMAT_PCM_16; break; } - m_sf = sf_open( -#ifdef LMMS_BUILD_WIN32 - outputFile().toLocal8Bit().constData(), -#else - outputFile().toUtf8().constData(), -#endif - SFM_WRITE, &m_si ); + + // Use file handle to handle unicode file name on Windows + m_sf = sf_open_fd( outputFileHandle(), SFM_WRITE, &m_si, false ); + + if (!m_sf) + { + qWarning("Error: AudioFileWave::startEncoding: %s", sf_strerror(nullptr)); + return false; + } // Prevent fold overs when encountering clipped data sf_command(m_sf, SFC_SET_CLIPPING, NULL, SF_TRUE); diff --git a/src/core/midi/MidiWinMM.cpp b/src/core/midi/MidiWinMM.cpp index a59ebc69e..ef60f3015 100644 --- a/src/core/midi/MidiWinMM.cpp +++ b/src/core/midi/MidiWinMM.cpp @@ -248,9 +248,13 @@ void MidiWinMM::closeDevices() m_outputSubs.clear(); QMapIterator i( m_inputDevices ); + + HMIDIIN hInDev; while( i.hasNext() ) { - midiInClose( i.next().key() ); + hInDev = i.next().key(); + midiInReset( hInDev ); + midiInClose( hInDev ); } QMapIterator o( m_outputDevices ); diff --git a/src/gui/MainApplication.cpp b/src/gui/MainApplication.cpp index 5210dd76c..994ae2771 100644 --- a/src/gui/MainApplication.cpp +++ b/src/gui/MainApplication.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 2017-2017 Tres Finocchiaro * - * This file is part of LMMS - http://lmms.io + * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 8f2fd4bad..35728d25e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -75,7 +75,7 @@ void disableAutoKeyAccelerators(QWidget* mainWindow) { using DisablerFunc = void(*)(QWidget*); QLibrary kf5WidgetsAddon("KF5WidgetsAddons", 5); - DisablerFunc setNoAccelerators = + DisablerFunc setNoAccelerators = reinterpret_cast(kf5WidgetsAddon.resolve("_ZN19KAcceleratorManager10setNoAccelEP7QWidget")); if(setNoAccelerators) { @@ -720,7 +720,7 @@ void MainWindow::clearKeyModifiers() void MainWindow::saveWidgetState( QWidget * _w, QDomElement & _de ) { - // If our widget is the main content of a window (e.g. piano roll, FxMixer, etc), + // If our widget is the main content of a window (e.g. piano roll, FxMixer, etc), // we really care about the position of the *window* - not the position of the widget within its window if( _w->parentWidget() != NULL && _w->parentWidget()->inherits( "QMdiSubWindow" ) ) @@ -728,7 +728,7 @@ void MainWindow::saveWidgetState( QWidget * _w, QDomElement & _de ) _w = _w->parentWidget(); } - // If the widget is a SubWindow, then we can make use of the getTrueNormalGeometry() method that + // If the widget is a SubWindow, then we can make use of the getTrueNormalGeometry() method that // performs the same as normalGeometry, but isn't broken on X11 ( see https://bugreports.qt.io/browse/QTBUG-256 ) SubWindow *asSubWindow = qobject_cast(_w); QRect normalGeom = asSubWindow != nullptr ? asSubWindow->getTrueNormalGeometry() : _w->normalGeometry(); @@ -757,7 +757,7 @@ void MainWindow::restoreWidgetState( QWidget * _w, const QDomElement & _de ) qMax( _w->minimumHeight(), _de.attribute( "height" ).toInt() ) ); if( _de.hasAttribute( "visible" ) && !r.isNull() ) { - // If our widget is the main content of a window (e.g. piano roll, FxMixer, etc), + // If our widget is the main content of a window (e.g. piano roll, FxMixer, etc), // we really care about the position of the *window* - not the position of the widget within its window if ( _w->parentWidget() != NULL && _w->parentWidget()->inherits( "QMdiSubWindow" ) ) @@ -856,7 +856,7 @@ void MainWindow::updateRecentlyOpenedProjectsMenu() for( QStringList::iterator it = rup.begin(); it != rup.end(); ++it ) { QFileInfo recentFile( *it ); - if ( recentFile.exists() && + if ( recentFile.exists() && *it != ConfigManager::inst()->recoveryFile() ) { if( recentFile.suffix().toLower() == "mpt" ) @@ -901,15 +901,15 @@ bool MainWindow::saveProject() { return( saveProjectAs() ); } - else + else if( this->guiSaveProject() ) { - this->guiSaveProject(); if( getSession() == Recover ) { sessionCleanup(); } + return true; } - return( true ); + return false; } @@ -955,14 +955,16 @@ bool MainWindow::saveProjectAs() } } } - this->guiSaveProjectAs( fname ); - if( getSession() == Recover ) + if( this->guiSaveProjectAs( fname ) ) { - sessionCleanup(); + if( getSession() == Recover ) + { + sessionCleanup(); + } + return true; } - return( true ); } - return( false ); + return false; } @@ -980,8 +982,7 @@ bool MainWindow::saveProjectAsNewVersion() do VersionedSaveDialog::changeFileNameVersion( fileName, true ); while ( QFile( fileName ).exists() ); - this->guiSaveProjectAs( fileName ); - return true; + return this->guiSaveProjectAs( fileName ); } }