From 12ad6495fa332ea499485082272f796c4b08c83c Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 11 Jan 2020 22:04:07 +0800 Subject: Bring back i18n support. Address compiler warnings in QDialSkualptureStyle. Introduced build BUILD_PORTABLE, replacing QMP_BUILD_MODE in the QMake project. The QMake project is now fully covered by the CMake project and officially deprecated. --- CMakeLists.txt | 5 +- core/qmpmidiread.cpp | 2 +- qmidiplayer-desktop/CMakeLists.txt | 8 + qmidiplayer-desktop/main.cpp | 12 +- qmidiplayer-desktop/qdialskulpturestyle.cpp | 43 +- qmidiplayer-desktop/qmphelpwindow.cpp | 3 +- qmidiplayer-desktop/qmphelpwindow.hpp | 2 - qmidiplayer-desktop/qmpplugin.cpp | 9 +- qmidiplayer-desktop/translations/qmp_zh_CN.ts | 631 ++++++++++++++++++-------- 9 files changed, 496 insertions(+), 219 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b92872..e789ec8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) include(FindPkgConfig) -find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(Qt5 REQUIRED COMPONENTS Widgets LinguistTools) find_package(Threads REQUIRED) pkg_search_module(fluidsynth REQUIRED fluidsynth>=2.0.0) pkg_search_module(rtmidi REQUIRED rtmidi) @@ -18,6 +18,9 @@ option(BUILD_VISUALIZATION "Build visualization plugin" ON) if(WIN32) option(BUILD_BACKTRACE "Build backtrace library" OFF) endif() +if(UNIX) + option(BUILD_PORTABLE "Instruct the built binary not to search system directories" OFF) +endif() add_subdirectory(core) add_subdirectory(qmidiplayer-desktop) diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp index 697a5bd..c7d11f2 100644 --- a/core/qmpmidiread.cpp +++ b/core/qmpmidiread.cpp @@ -221,7 +221,7 @@ uint32_t CSMFReader::read_chunk(int is_header) else if(strncmp(hdr,"MTrk",4)) { - error(0,"Wrong track chunk header. Ignoring the whole chunk"); + error(0,"Wrong track chunk header. Ignoring the entire chunk."); uint32_t chnklen=read_u32();fseek(f,chnklen,SEEK_CUR);return 0; } else return read_track(),1; diff --git a/qmidiplayer-desktop/CMakeLists.txt b/qmidiplayer-desktop/CMakeLists.txt index 87741f8..ca2b6b7 100644 --- a/qmidiplayer-desktop/CMakeLists.txt +++ b/qmidiplayer-desktop/CMakeLists.txt @@ -60,6 +60,9 @@ include_directories(${PROJECT_SOURCE_DIR}/include/) cmake_host_system_information(RESULT build_host QUERY HOSTNAME) add_definitions(-DBUILD_MACHINE=${build_host}) +if(UNIX AND NOT BUILD_PORTABLE) + add_definitions(-DNON_PORTABLE -DINSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) +endif() add_executable(qmidiplayer ${qmpdesktop_SOURCES} @@ -74,6 +77,10 @@ target_link_libraries(qmidiplayer ${CMAKE_DL_LIBS} ) +file(GLOB qmpdesktop_TS_FILES translations/*.ts) +qt5_create_translation(qmpdesktop_QM_FILES ${qmpdesktop_SOURCES} ${qmpdesktop_TS_FILES}) +add_custom_target(translations ALL DEPENDS ${qmpdesktop_QM_FILES}) + install(TARGETS qmidiplayer) install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/qmidiplayer) @@ -84,3 +91,4 @@ install(FILES ${PROJECT_SOURCE_DIR}/img/qmidiplyr.png DESTINATION ${CMAKE_INSTAL install(FILES ${PROJECT_SOURCE_DIR}/img/qmidiplyr.svg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps) install(FILES menu/qmidiplayer DESTINATION ${CMAKE_INSTALL_PREFIX}/share/menu) install(FILES qmidiplayer.mime DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mime/packages) +install(FILES ${qmpdesktop_QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/qmidiplayer/translations) diff --git a/qmidiplayer-desktop/main.cpp b/qmidiplayer-desktop/main.cpp index b1c9149..9f1d593 100644 --- a/qmidiplayer-desktop/main.cpp +++ b/qmidiplayer-desktop/main.cpp @@ -44,11 +44,19 @@ int main(int argc,char **argv) QLibraryInfo::location(QLibraryInfo::TranslationsPath)); a.installTranslator(&qtTranslator); QTranslator qmpTranslator; - qmpTranslator.load("qmp_"+QLocale::system().name()); +#ifndef NON_PORTABLE + qmpTranslator.load("qmp_"+QLocale::system().name(), + QCoreApplication::applicationDirPath()+"/translations/"); +#else +#define strify(s) #s + qmpTranslator.load("qmp_"+QLocale::system().name(), + QString(strify(INSTALL_PREFIX))+"/share/qmidiplayer/translations"); +#undef strify +#endif a.installTranslator(&qmpTranslator); QCommandLineParser clp; - clp.setApplicationDescription("A cross-platform MIDI player."); + clp.setApplicationDescription(QCoreApplication::translate("main","A cross-platform MIDI player.")); clp.addHelpOption(); clp.addVersionOption(); clp.addPositionalArgument("file",QCoreApplication::translate("main","midi files to play (optional)."),"[files...]"); diff --git a/qmidiplayer-desktop/qdialskulpturestyle.cpp b/qmidiplayer-desktop/qdialskulpturestyle.cpp index 33c80de..7650edb 100644 --- a/qmidiplayer-desktop/qdialskulpturestyle.cpp +++ b/qmidiplayer-desktop/qdialskulpturestyle.cpp @@ -134,27 +134,23 @@ paintDialBase(QPainter *painter, const QStyleOption *option) dial_color = option->palette.color(QPalette::Window); } qreal t = option->state & QStyle::State_Enabled ? 2.0 : 1.5; - if (1) { - // ###: work around Qt 4.3.0 bug? (this works for 4.3.1) - QConicalGradient border_gradient(r.center(), angle); - border_gradient.setColorAt(0.0, dial_color.lighter(120)); - border_gradient.setColorAt(0.2, dial_color); - border_gradient.setColorAt(0.5, dial_color.darker(130)); - border_gradient.setColorAt(0.8, dial_color); - border_gradient.setColorAt(1.0, dial_color.lighter(120)); - painter->setPen(QPen(border_gradient, t)); - } else { - painter->setPen(QPen(Qt::red, t)); - } + // ###: work around Qt 4.3.0 bug? (this works for 4.3.1) + QConicalGradient border_gradient(r.center(), angle); + border_gradient.setColorAt(0.0, dial_color.lighter(120)); + border_gradient.setColorAt(0.2, dial_color); + border_gradient.setColorAt(0.5, dial_color.darker(130)); + border_gradient.setColorAt(0.8, dial_color); + border_gradient.setColorAt(1.0, dial_color.lighter(120)); + painter->setPen(QPen(border_gradient, t)); #if 0 QLinearGradient dial_gradient(r.topLeft(), r.bottomLeft()); dial_gradient.setColorAt(0.0, dial_color.darker(105)); dial_gradient.setColorAt(0.5, dial_color.lighter(102)); dial_gradient.setColorAt(1.0, dial_color.lighter(105)); #elif 1 - QLinearGradient dial_gradient(option->direction == Qt::LeftToRight ? r.topLeft() : r.topRight(), option->direction == Qt::LeftToRight ? r.bottomRight() : r.bottomLeft()); + QLinearGradient dial_gradient(option->direction == Qt::LeftToRight ? r.topLeft() : r.topRight(), option->direction == Qt::LeftToRight ? r.bottomRight() : r.bottomLeft()); // QLinearGradient dial_gradient(r.topLeft(), r.bottomLeft()); - if (true || option->state & QStyle::State_Enabled) { + if (option->state & QStyle::State_Enabled) { #if 1 dial_gradient.setColorAt(0.0, dial_color.darker(106)); dial_gradient.setColorAt(1.0, dial_color.lighter(104)); @@ -213,7 +209,11 @@ paintCachedDialBase(QPainter *painter, const QStyleOptionSlider *option) state &= ~(QStyle::State_MouseOver | QStyle::State_HasFocus | QStyle::State_KeyboardFocusChange); } // state &= ~(QStyle::State_HasFocus); - pixmapName.sprintf("scp-qdb-%x-%x-%llx-%x", state, option->direction, option->palette.cacheKey(), d); + pixmapName = QString("scp-qdb-%1-%2-%3-%4") + .arg(state, 0, 16) + .arg(option->direction, 0, 16) + .arg(option->palette.cacheKey(), 0, 16) + .arg(d, 0, 16); } paintIndicatorCached(painter, option, paintDialBase, useCache, pixmapName); } @@ -356,18 +356,23 @@ paintCachedGrip(QPainter *painter, const QStyleOption *option) useCache = false; } if (useCache) { - uint state = uint(option->state) & (QStyle::State_Enabled | QStyle::State_On | QStyle::State_MouseOver | QStyle::State_Sunken | QStyle::State_HasFocus); + QStyle::State state = option->state & (QStyle::State_Enabled | QStyle::State_On | QStyle::State_MouseOver | QStyle::State_Sunken | QStyle::State_HasFocus); if (!(state & QStyle::State_Enabled)) { state &= ~(QStyle::State_MouseOver | QStyle::State_HasFocus); } state &= ~(QStyle::State_HasFocus); - QByteArray colorName = option->palette.color(QPalette::Button).name().toLatin1(); - pixmapName.sprintf("scp-isg-%x-%x-%s-%x-%x", state, option->direction, colorName.constData(), option->rect.width(), option->rect.height()); + QByteArray colorName = option->palette.color(QPalette::Button).name().toLatin1(); + pixmapName = QString("scp-isg-%1-%2-%3-%4-%5") + .arg(state, 0, 16) + .arg(option->direction, 0, 16) + .arg(QString(colorName)) + .arg(option->rect.width(), 0, 16) + .arg(option->rect.height(), 0, 16); } paintIndicatorCached(painter,option, [=](QPainter *painter,const QStyleOption *option){ QStyleOption opt(*option); - opt.rect.moveTo(0,0); + opt.rect.moveTo(0, 0); paintGrip(painter,&opt); }, useCache,pixmapName); diff --git a/qmidiplayer-desktop/qmphelpwindow.cpp b/qmidiplayer-desktop/qmphelpwindow.cpp index 2faed61..325fc57 100644 --- a/qmidiplayer-desktop/qmphelpwindow.cpp +++ b/qmidiplayer-desktop/qmphelpwindow.cpp @@ -1,6 +1,7 @@ #include #include "qmphelpwindow.hpp" #include "ui_qmphelpwindow.h" +#define strify(s) #s static const char *months="JanFebMarAprMayJunJulAugSepOctNovDec"; std::string parseDate(const char *date) @@ -38,7 +39,7 @@ void qmpHelpWindow::on_textBrowser_sourceChanged(const QUrl &src) s.replace("RT_FLUIDSYNTH_VERSION",fluid_version_str()); s.replace("APP_VERSION",APP_VERSION); s.replace("BUILD_DATE",parseDate(__DATE__).c_str()); - s.replace("BUILD_MACHINE",sss(BUILD_MACHINE)); + s.replace("BUILD_MACHINE",strify(BUILD_MACHINE)); ui->textBrowser->setHtml(s); } } diff --git a/qmidiplayer-desktop/qmphelpwindow.hpp b/qmidiplayer-desktop/qmphelpwindow.hpp index 4e1ca4c..2cde49d 100644 --- a/qmidiplayer-desktop/qmphelpwindow.hpp +++ b/qmidiplayer-desktop/qmphelpwindow.hpp @@ -6,8 +6,6 @@ #ifndef BUILD_MACHINE #define BUILD_MACHINE UNKNOWN #endif -#define ss(s) #s -#define sss(s) ss(s) namespace Ui { class qmpHelpWindow; diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp index 8f16573..19d14b5 100644 --- a/qmidiplayer-desktop/qmpplugin.cpp +++ b/qmidiplayer-desktop/qmpplugin.cpp @@ -55,13 +55,16 @@ void qmpPluginManager::scanPlugins(const std::vector &pp) { QDirIterator *dir; std::vector cpluginpaths(pp); -#ifdef QMP_BUILD_UNIX_PACKAGE - dir=new QDirIterator("/usr/lib/qmidiplayer/"); +#ifdef NON_PORTABLE +#define strify(s) #s + QString pdir=QString(strify(INSTALL_PREFIX))+"/lib/qmidiplayer/"; +#undef strify + dir=new QDirIterator(pdir); while(dir->hasNext()) { dir->next(); if(dir->fileInfo().suffix()=="so") - cpluginpaths.push_back(std::string("/usr/lib/qmidiplayer/")+dir->fileName().toStdString()); + cpluginpaths.push_back((pdir+dir->fileName()).toStdString()); } delete dir; #endif diff --git a/qmidiplayer-desktop/translations/qmp_zh_CN.ts b/qmidiplayer-desktop/translations/qmp_zh_CN.ts index f7f79df..c9e0800 100644 --- a/qmidiplayer-desktop/translations/qmp_zh_CN.ts +++ b/qmidiplayer-desktop/translations/qmp_zh_CN.ts @@ -1,6 +1,42 @@ - + + + QFileEdit + + + Select a file + 选择文件 + + + + main + + + A cross-platform MIDI player. + + + + + midi files to play (optional). + + + + + Load a plugin from <plugin library>. + + + + + Load all files from the same folder. + + + + + Keep console window open. + + + qmpChannelEditor @@ -23,11 +59,6 @@ > - - - Yamaha Grand Piano - - BK: 0 @@ -38,19 +69,24 @@ PC: 0 + + + Yamaha Grand Piano + + Filters 滤波器 - - Res. 64 + + Cut. 64 - - Cut. 64 + + Res. 64 @@ -58,31 +94,46 @@ Effects 效果 + + + Rev. 64 + + Chr. 64 - - Rev. 64 - + + Mixer + 混音 - - Envelope + + Vol. 127 - - Dec. 64 + + Pan. C + + + Envelope + 包络 + Atk. 64 + + + Dec. 64 + + Rel. 64 @@ -91,12 +142,7 @@ Vibrato - - - - - Dep. 64 - + 振音 @@ -104,23 +150,13 @@ - - Del. 64 - - - - - Mixer - 混音 - - - - Pan. C + + Dep. 64 - - Vol. 127 + + Del. 64 @@ -137,60 +173,130 @@ 通道 - A - 活动 + 活动 - M - 静音 + 静音 - S - 独奏 + 独奏 - Device - 输出设备 + 输出设备 - Preset - 乐器 - - - - ... - + 乐器 - + Save 保存播放列表 - + Load 打开播放列表 - + Unmute All 取消全部静音 - + Unsolo All 取消全部独奏 + + + Channel + + + + + qmpCustomizeWindow + + + Customize widgets + + + + + > + + + + + < + + + + + Items can be sorted by drag and drop. + + + + + qmpDevPropDialog + + + External Output Device Setup + 外部输出设备设置 + + + + Device + 输出设备 + + + + Connected? + 已连接 + + + + Device Initialization File + 设备配置文件 + + + + + + + + + + - + + + + + qmpDevicePriorityDialog + + + Select MIDI Output Devices + 选择MIDI输出设备 + + + + Move Up + 上移 + + + + Move Down + 下移 + qmpEfxWindow + Effects 效果 @@ -200,58 +306,68 @@ 混响 - + + + Enabled + 启用 + + + Room 房间大小 - + Damp 衰减 - + Width 声场 - - + + Level 音量 - + Chorus 和声 - + + LFO + + + + + Si&ne + 正弦波(&n) + + + Feedback 和声数量 - + Rate 频率 - + Depth 延迟 - - LFO - - - - Sine - 正弦 + 正弦 - + Trian&gle 三角波(&g) @@ -268,6 +384,7 @@ qmpInfoWindow + File Information 文件信息 @@ -320,71 +437,96 @@ - + somefile.mid - + <html><head/><body><p>Poly</p></body></html> <html><head/><body><p>复音</p></body></html> - + + + 00000 + + + + + ? + + + + + + 00:00 + + + + + Vol. + 音量 + + Channels - 通道 + 通道 - Playlist - 播放列表 + 播放列表 - Effects - 效果 + 效果 - Visualization - 可视化 + 可视化 - Master - 主音量 + 主音量 - - - 00:00 - - - - - ? - - - - File Information - 文件信息 + 文件信息 - Render to Wave - 输出到wav文件 + 输出到wav文件 + + + + Render to wave + 输出wav文件 - + Panic 关闭所有音符 + + + Restart fluidsynth + 重新载入FluidSynth + + + + Error + 错误 + + + + %1 is not a valid midi file. + %1是无效的midi文件。 + qmpPlistWindow + Playlist 播放列表 @@ -400,15 +542,15 @@ - - + + Repeat Off 循环关 - - + + Shuffle Off 随机关 @@ -433,30 +575,30 @@ 清空 - - + + Repeat One 循环当前 - - + + Repeat All 循环全部 - - + + Shuffle On 随机开 - + Save playlist 保存播放列表 - + Load playlist 加载播放列表 @@ -469,24 +611,37 @@ 乐器选择 - + Bank 乐器库 - + Preset 乐器 - + + Bank MSB + + + + + Bank LSB + + + + + Patch + + + OK - 确定 + 确定 - Cancel - 取消 + 取消 @@ -502,290 +657,386 @@ MIDI选项 - Default Output Device - 默认输出设备 + 默认输出设备 - - Internal FluidSynth - - - - + Disable Midi Mapping 只使用默认输出设备 - + Send SysEx 发送SysEx指令 - + Wait for remaining voices before stopping 停止前等待复音数降为0 - + Text Encoding - MIDI内文本编码 + 文本编码 - + Unicode - + Big5 - + Big5-HKSCS - + CP949 - + EUC-JP - + EUC-KR - + GB18030 - + KOI8-R - + KOI8-U - + Macintosh - + Shift-JIS - + + Select MIDI output devices + 选择MIDI输出设备 + + + + + ... + + + + + External MIDI output device setup + 外部MIDI设备设置 + + + Synth 合成器 - + Audio Buffer Count 音频缓冲区数量 - + Audio Buffer Size 音频缓冲区大小 - - + + 64 - + 128 - + 256 - + 512 - + 1024 - + 2048 - + 4096 - + 8192 - - Audio Frequency - 采样频率 + + Sample Rate + 采样率 - + 2 - + 4 - + 8 - + 16 - + 32 - - Audio Driver - 音频驱动 - - - + 16bits - + float - + 22050 - + 44100 - + 48000 - + 96000 - + + Sample Format + 采样格式 + + + + Show label beside icon in toolbar buttons + 工具栏按钮中显示文字标签 + + + + Icon Theme + 图标主题 + + + + Auto + 自动 + + + + Dark + 暗色 + + + + Light + 亮色 + + + + Customize toolbar + 自定义工具栏 + + + + + Customize + 设置 + + + + Customize actions + 自定义右键菜单 + + + + Plugins + 插件 + + + + Name + 名称 + + + + Version + 版本 + + + Audio Frequency + 采样频率 + + + + Audio Driver + 音频驱动 + + Audio Format - 音频格式 + 音频格式 - + Max Polyphony 最大复音数 - + Auto bank select mode 自动确定乐器库选择方式 - + Bank select mode 乐器库选择方式 - + Ignored - + CC#0 - + CC#32 - + CC#0*128+CC#32 - + CPU Cores 合成器线程数 - + Soundfonts 音源 - + + + E + 启用 + + + + + Path + 路径 + + + Behavior 行为设定 - + Restore last playlist on startup 启动时,恢复上次的播放列表 - + Load files in the same folder 添加同一文件夹下的所有文件 - + Save dialog status 保存对话框状态 - + Save parameters in effects window 保存效果窗口内的设定 - + Persistent fluidsynth instance 单一fluidsynth实例 + + + No soundfont loaded + 未选择soundfont + + + + Internal fluidsynth is the only available MIDI output but it has no soundfont set. Would you like to setup soundfonts now? You may have to reload the internal synth afterwards. + 仅有FluidSynth输出可用,但未选择其使用的soundfont。需要现在进行设置吗?(设置完毕后需要重新加载FluidSynth。) + -- cgit v1.2.3