mirror of https://github.com/procxx/kepka.git
Divided song volume and video volume, video volume control implemented.
This commit is contained in:
parent
034657dd2c
commit
8da39356dc
|
@ -538,6 +538,9 @@ struct Data {
|
|||
|
||||
int32 DebugLoggingFlags = 0;
|
||||
|
||||
float64 SongVolume = 0.9;
|
||||
float64 VideoVolume = 0.9;
|
||||
|
||||
// config
|
||||
int32 ChatSizeMax = 200;
|
||||
int32 MegagroupSizeMax = 1000;
|
||||
|
@ -606,6 +609,9 @@ DefineVar(Global, bool, ScreenIsLocked);
|
|||
|
||||
DefineVar(Global, int32, DebugLoggingFlags);
|
||||
|
||||
DefineVar(Global, float64, SongVolume);
|
||||
DefineVar(Global, float64, VideoVolume);
|
||||
|
||||
// config
|
||||
DefineVar(Global, int32, ChatSizeMax);
|
||||
DefineVar(Global, int32, MegagroupSizeMax);
|
||||
|
|
|
@ -217,6 +217,9 @@ DeclareVar(bool, ScreenIsLocked);
|
|||
|
||||
DeclareVar(int32, DebugLoggingFlags);
|
||||
|
||||
DeclareVar(float64, SongVolume);
|
||||
DeclareVar(float64, VideoVolume);
|
||||
|
||||
// config
|
||||
DeclareVar(int32, ChatSizeMax);
|
||||
DeclareVar(int32, MegagroupSizeMax);
|
||||
|
|
|
@ -541,6 +541,7 @@ namespace {
|
|||
dbiHiddenPinnedMessages = 0x39,
|
||||
dbiDialogsMode = 0x40,
|
||||
dbiModerateMode = 0x41,
|
||||
dbiVideoVolume = 0x42,
|
||||
|
||||
dbiEncryptedWithSalt = 333,
|
||||
dbiEncrypted = 444,
|
||||
|
@ -1308,7 +1309,15 @@ namespace {
|
|||
stream >> v;
|
||||
if (!_checkStreamStatus(stream)) return false;
|
||||
|
||||
cSetSongVolume(snap(v / 1e6, 0., 1.));
|
||||
Global::SetSongVolume(snap(v / 1e6, 0., 1.));
|
||||
} break;
|
||||
|
||||
case dbiVideoVolume: {
|
||||
qint32 v;
|
||||
stream >> v;
|
||||
if (!_checkStreamStatus(stream)) return false;
|
||||
|
||||
Global::SetVideoVolume(snap(v / 1e6, 0., 1.));
|
||||
} break;
|
||||
|
||||
default:
|
||||
|
@ -1532,7 +1541,7 @@ namespace {
|
|||
_writeMap(WriteMapFast);
|
||||
}
|
||||
|
||||
uint32 size = 17 * (sizeof(quint32) + sizeof(qint32));
|
||||
uint32 size = 18 * (sizeof(quint32) + sizeof(qint32));
|
||||
size += sizeof(quint32) + Serialize::stringSize(cAskDownloadPath() ? QString() : cDownloadPath()) + Serialize::bytearraySize(cAskDownloadPath() ? QByteArray() : cDownloadPathBookmark());
|
||||
size += sizeof(quint32) + sizeof(qint32) + (cRecentEmojisPreload().isEmpty() ? cGetRecentEmojis().size() : cRecentEmojisPreload().size()) * (sizeof(uint64) + sizeof(ushort));
|
||||
size += sizeof(quint32) + sizeof(qint32) + cEmojiVariants().size() * (sizeof(uint32) + sizeof(uint64));
|
||||
|
@ -1561,7 +1570,8 @@ namespace {
|
|||
data.stream << quint32(dbiDownloadPath) << (cAskDownloadPath() ? QString() : cDownloadPath()) << (cAskDownloadPath() ? QByteArray() : cDownloadPathBookmark());
|
||||
data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage());
|
||||
data.stream << quint32(dbiDialogLastPath) << cDialogLastPath();
|
||||
data.stream << quint32(dbiSongVolume) << qint32(qRound(cSongVolume() * 1e6));
|
||||
data.stream << quint32(dbiSongVolume) << qint32(qRound(Global::SongVolume() * 1e6));
|
||||
data.stream << quint32(dbiVideoVolume) << qint32(qRound(Global::VideoVolume() * 1e6));
|
||||
data.stream << quint32(dbiAutoDownload) << qint32(cAutoDownloadPhoto()) << qint32(cAutoDownloadAudio()) << qint32(cAutoDownloadGif());
|
||||
data.stream << quint32(dbiDialogsMode) << qint32(Global::DialogsModeEnabled() ? 1 : 0) << static_cast<qint32>(Global::DialogsMode());
|
||||
data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0);
|
||||
|
|
|
@ -291,6 +291,7 @@ _loader(new AudioPlayerLoaders(&_loaderThread)) {
|
|||
connect(this, SIGNAL(unsuppressSong()), _fader, SLOT(onUnsuppressSong()));
|
||||
connect(this, SIGNAL(suppressAll()), _fader, SLOT(onSuppressAll()));
|
||||
connect(this, SIGNAL(songVolumeChanged()), _fader, SLOT(onSongVolumeChanged()));
|
||||
connect(this, SIGNAL(videoVolumeChanged()), _fader, SLOT(onVideoVolumeChanged()));
|
||||
connect(this, SIGNAL(loaderOnStart(const AudioMsgId&,qint64)), _loader, SLOT(onStart(const AudioMsgId&,qint64)));
|
||||
connect(this, SIGNAL(loaderOnCancel(const AudioMsgId&)), _loader, SLOT(onCancel(const AudioMsgId&)));
|
||||
connect(&_faderThread, SIGNAL(started()), _fader, SLOT(onInit()));
|
||||
|
@ -571,7 +572,7 @@ void AudioPlayer::pauseresume(AudioMsgId::Type type, bool fast) {
|
|||
float64 suppressGain = 1.;
|
||||
switch (type) {
|
||||
case AudioMsgId::Type::Voice: suppressGain = suppressAllGain; break;
|
||||
case AudioMsgId::Type::Song: suppressGain = suppressSongGain * cSongVolume(); break;
|
||||
case AudioMsgId::Type::Song: suppressGain = suppressSongGain * Global::SongVolume(); break;
|
||||
}
|
||||
|
||||
switch (current->playbackState.state) {
|
||||
|
@ -623,7 +624,7 @@ void AudioPlayer::seek(int64 position) {
|
|||
float64 suppressGain = 1.;
|
||||
switch (type) {
|
||||
case AudioMsgId::Type::Voice: suppressGain = suppressAllGain; break;
|
||||
case AudioMsgId::Type::Song: suppressGain = suppressSongGain * cSongVolume(); break;
|
||||
case AudioMsgId::Type::Song: suppressGain = suppressSongGain * Global::SongVolume(); break;
|
||||
}
|
||||
auto audio = current->audio;
|
||||
|
||||
|
@ -887,15 +888,17 @@ void AudioPlayerFader::onTimer() {
|
|||
if (emitSignals & EmitPositionUpdated) emit playPositionUpdated(data->audio);
|
||||
if (emitSignals & EmitNeedToPreload) emit needToPreload(data->audio);
|
||||
};
|
||||
auto suppressGainForMusic = suppressSongGain * cSongVolume();
|
||||
auto suppressGainForMusic = suppressSongGain * Global::SongVolume();
|
||||
auto suppressGainForMusicChanged = suppressSongChanged || _songVolumeChanged;
|
||||
for (int i = 0; i < AudioSimultaneousLimit; ++i) {
|
||||
updatePlayback(AudioMsgId::Type::Voice, i, suppressAllGain, suppressAudioChanged);
|
||||
updatePlayback(AudioMsgId::Type::Song, i, suppressGainForMusic, suppressGainForMusicChanged);
|
||||
}
|
||||
updatePlayback(AudioMsgId::Type::Video, 0, suppressGainForMusic, suppressGainForMusicChanged);
|
||||
auto suppressGainForVideo = suppressSongGain * Global::VideoVolume();
|
||||
auto suppressGainForVideoChanged = suppressSongChanged || _videoVolumeChanged;
|
||||
updatePlayback(AudioMsgId::Type::Video, 0, suppressGainForVideo, suppressGainForVideoChanged);
|
||||
|
||||
_songVolumeChanged = false;
|
||||
_songVolumeChanged = _videoVolumeChanged = false;
|
||||
|
||||
if (!hasFading) {
|
||||
if (!hasPlaying) {
|
||||
|
@ -1067,6 +1070,11 @@ void AudioPlayerFader::onSongVolumeChanged() {
|
|||
onTimer();
|
||||
}
|
||||
|
||||
void AudioPlayerFader::onVideoVolumeChanged() {
|
||||
_videoVolumeChanged = true;
|
||||
onTimer();
|
||||
}
|
||||
|
||||
void AudioPlayerFader::resumeDevice() {
|
||||
QMutexLocker lock(&_pauseMutex);
|
||||
_pauseFlag = false;
|
||||
|
|
|
@ -100,6 +100,7 @@ signals:
|
|||
void suppressAll();
|
||||
|
||||
void songVolumeChanged();
|
||||
void videoVolumeChanged();
|
||||
|
||||
private:
|
||||
bool fadedStop(AudioMsgId::Type type, bool *fadedStart = 0);
|
||||
|
@ -237,6 +238,7 @@ public slots:
|
|||
void onUnsuppressSong();
|
||||
void onSuppressAll();
|
||||
void onSongVolumeChanged();
|
||||
void onVideoVolumeChanged();
|
||||
|
||||
private:
|
||||
enum {
|
||||
|
@ -252,7 +254,7 @@ private:
|
|||
QMutex _pauseMutex;
|
||||
bool _pauseFlag, _paused;
|
||||
|
||||
bool _suppressAll, _suppressAllAnim, _suppressSong, _suppressSongAnim, _songVolumeChanged;
|
||||
bool _suppressAll, _suppressAllAnim, _suppressSong, _suppressSongAnim, _songVolumeChanged, _videoVolumeChanged;
|
||||
anim::fvalue _suppressAllGain, _suppressSongGain;
|
||||
uint64 _suppressAllStart, _suppressSongStart;
|
||||
|
||||
|
|
|
@ -294,8 +294,8 @@ void AudioPlayerLoaders::loadData(AudioMsgId audio, qint64 position) {
|
|||
|
||||
switch (type) {
|
||||
case AudioMsgId::Type::Voice: alSourcef(m->source, AL_GAIN, internal::audioSuppressGain()); break;
|
||||
case AudioMsgId::Type::Song: alSourcef(m->source, AL_GAIN, internal::audioSuppressSongGain() * cSongVolume()); break;
|
||||
case AudioMsgId::Type::Video: alSourcef(m->source, AL_GAIN, internal::audioSuppressSongGain() * cSongVolume()); break;
|
||||
case AudioMsgId::Type::Song: alSourcef(m->source, AL_GAIN, internal::audioSuppressSongGain() * Global::SongVolume()); break;
|
||||
case AudioMsgId::Type::Video: alSourcef(m->source, AL_GAIN, internal::audioSuppressSongGain() * Global::VideoVolume()); break;
|
||||
}
|
||||
if (!internal::audioCheckError()) {
|
||||
setStoppedState(m, AudioPlayerStoppedAtError);
|
||||
|
|
|
@ -43,6 +43,9 @@ Controller::Controller(QWidget *parent) : TWidget(parent)
|
|||
_fadeAnimation->show();
|
||||
_fadeAnimation->setFinishedCallback(func(this, &Controller::fadeFinished));
|
||||
_fadeAnimation->setUpdatedCallback(func(this, &Controller::fadeUpdated));
|
||||
|
||||
_volumeController->setVolume(Global::VideoVolume());
|
||||
|
||||
connect(_playPauseResume, SIGNAL(clicked()), this, SIGNAL(playPressed()));
|
||||
connect(_fullScreenToggle, SIGNAL(clicked()), this, SIGNAL(toFullScreenPressed()));
|
||||
connect(_playback, SIGNAL(seekProgress(int64)), this, SLOT(onSeekProgress(int64)));
|
||||
|
@ -173,5 +176,9 @@ void Controller::paintEvent(QPaintEvent *e) {
|
|||
App::roundRect(p, rect(), st::medviewSaveMsg, MediaviewSaveCorners);
|
||||
}
|
||||
|
||||
void Controller::mousePressEvent(QMouseEvent *e) {
|
||||
e->accept(); // Don't pass event to the MediaView.
|
||||
}
|
||||
|
||||
} // namespace Clip
|
||||
} // namespace Media
|
||||
|
|
|
@ -65,6 +65,7 @@ private slots:
|
|||
protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
private:
|
||||
template <typename Callback>
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Clip {
|
|||
VolumeController::VolumeController(QWidget *parent) : TWidget(parent) {
|
||||
resize(st::mediaviewVolumeSize);
|
||||
setCursor(style::cur_pointer);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void VolumeController::setVolume(float64 volume) {
|
||||
|
@ -57,12 +58,33 @@ void VolumeController::paintEvent(QPaintEvent *e) {
|
|||
}
|
||||
|
||||
void VolumeController::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (_downCoord < 0) {
|
||||
return;
|
||||
}
|
||||
int delta = e->pos().x() - _downCoord;
|
||||
int left = (width() - st::mediaviewVolumeIcon.width()) / 2;
|
||||
float64 startFrom = snap((_downCoord - left) / float64(st::mediaviewVolumeIcon.width()), 0., 1.);
|
||||
float64 add = delta / float64(4 * st::mediaviewVolumeIcon.width());
|
||||
auto newVolume = snap(startFrom + add, 0., 1.);
|
||||
changeVolume(newVolume);
|
||||
}
|
||||
|
||||
void VolumeController::mousePressEvent(QMouseEvent *e) {
|
||||
_downCoord = snap(e->pos().x(), 0, width());
|
||||
int left = (width() - st::mediaviewVolumeIcon.width()) / 2;
|
||||
auto newVolume = snap((_downCoord - left) / float64(st::mediaviewVolumeIcon.width()), 0., 1.);
|
||||
changeVolume(newVolume);
|
||||
}
|
||||
|
||||
void VolumeController::changeVolume(float64 newVolume) {
|
||||
if (newVolume != _volume) {
|
||||
setVolume(newVolume);
|
||||
emit volumeChanged(_volume);
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeController::mouseReleaseEvent(QMouseEvent *e) {
|
||||
_downCoord = -1;
|
||||
}
|
||||
|
||||
void VolumeController::enterEvent(QEvent *e) {
|
||||
|
|
|
@ -47,8 +47,10 @@ private:
|
|||
update();
|
||||
}
|
||||
void setOver(bool over);
|
||||
void changeVolume(float64 newVolume);
|
||||
|
||||
float64 _volume = 0.;
|
||||
int _downCoord = -1; // < 0 means mouse is not pressed
|
||||
|
||||
bool _over = false;
|
||||
FloatAnimation _a_over;
|
||||
|
|
|
@ -554,7 +554,9 @@ void MediaView::close() {
|
|||
}
|
||||
|
||||
void MediaView::activateControls() {
|
||||
if (!_menu) _controlsHideTimer.start(int(st::mvWaitHide));
|
||||
if (!_menu && !_mousePressed) {
|
||||
_controlsHideTimer.start(int(st::mvWaitHide));
|
||||
}
|
||||
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) {
|
||||
_controlsState = ControlsShowing;
|
||||
_controlsAnimStarted = getms();
|
||||
|
@ -567,7 +569,7 @@ void MediaView::activateControls() {
|
|||
}
|
||||
|
||||
void MediaView::onHideControls(bool force) {
|
||||
if (!force && (!_dropdown.isHidden() || _menu)) return;
|
||||
if (!force && (!_dropdown.isHidden() || _menu || _mousePressed)) return;
|
||||
if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) return;
|
||||
_controlsState = ControlsHiding;
|
||||
_controlsAnimStarted = getms();
|
||||
|
@ -1301,7 +1303,8 @@ void MediaView::onVideoSeekFinished(int64 position) {
|
|||
}
|
||||
|
||||
void MediaView::onVideoVolumeChanged(float64 volume) {
|
||||
|
||||
Global::SetVideoVolume(volume);
|
||||
emit audioPlayer()->videoVolumeChanged();
|
||||
}
|
||||
|
||||
void MediaView::onVideoToFullScreen() {
|
||||
|
@ -2244,12 +2247,21 @@ bool MediaView::event(QEvent *e) {
|
|||
}
|
||||
|
||||
bool MediaView::eventFilter(QObject *obj, QEvent *e) {
|
||||
if (e->type() == QEvent::MouseMove && obj->isWidgetType()) {
|
||||
auto type = e->type();
|
||||
if ((type == QEvent::MouseMove || type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease) && obj->isWidgetType()) {
|
||||
if (isAncestorOf(static_cast<QWidget*>(obj))) {
|
||||
auto mousePosition = mapFromGlobal(static_cast<QMouseEvent*>(e)->globalPos());
|
||||
bool moved = (mousePosition != _lastMouseMovePos);
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(e);
|
||||
auto mousePosition = mapFromGlobal(mouseEvent->globalPos());
|
||||
bool activate = (mousePosition != _lastMouseMovePos);
|
||||
_lastMouseMovePos = mousePosition;
|
||||
if (moved) activateControls();
|
||||
if (type == QEvent::MouseButtonPress) {
|
||||
_mousePressed = true;
|
||||
activate = true;
|
||||
} else if (type == QEvent::MouseButtonRelease) {
|
||||
_mousePressed = false;
|
||||
activate = true;
|
||||
}
|
||||
if (activate) activateControls();
|
||||
}
|
||||
}
|
||||
return TWidget::eventFilter(obj, e);
|
||||
|
|
|
@ -280,6 +280,7 @@ private:
|
|||
uint64 _controlsAnimStarted = 0;
|
||||
QTimer _controlsHideTimer;
|
||||
anim::fvalue a_cOpacity;
|
||||
bool _mousePressed = false;
|
||||
|
||||
PopupMenu *_menu = nullptr;
|
||||
Dropdown _dropdown;
|
||||
|
|
|
@ -79,7 +79,7 @@ void PlayerWidget::paintEvent(QPaintEvent *e) {
|
|||
p.setOpacity(o * 1. + (1. - o) * st::playerInactiveOpacity);
|
||||
int32 top = _volumeRect.y() + (_volumeRect.height() - st::playerVolume.pxHeight()) / 2;
|
||||
int32 left = _volumeRect.x() + (_volumeRect.width() - st::playerVolume.pxWidth()) / 2;
|
||||
int32 mid = left + qRound(st::playerVolume.pxWidth() * cSongVolume());
|
||||
int32 mid = left + qRound(st::playerVolume.pxWidth() * Global::SongVolume());
|
||||
int32 right = left + st::playerVolume.pxWidth();
|
||||
if (rtl()) {
|
||||
left = width() - left;
|
||||
|
@ -164,7 +164,7 @@ void PlayerWidget::mousePressEvent(QMouseEvent *e) {
|
|||
} else if (_over == OverVolume) {
|
||||
_down = OverVolume;
|
||||
_downCoord = pos.x() - _volumeRect.x();
|
||||
cSetSongVolume(snap((_downCoord - ((_volumeRect.width() - st::playerVolume.pxWidth()) / 2)) / float64(st::playerVolume.pxWidth()), 0., 1.));
|
||||
Global::SetSongVolume(snap((_downCoord - ((_volumeRect.width() - st::playerVolume.pxWidth()) / 2)) / float64(st::playerVolume.pxWidth()), 0., 1.));
|
||||
emit audioPlayer()->songVolumeChanged();
|
||||
rtlupdate(_volumeRect);
|
||||
} else if (_over == OverPlayback) {
|
||||
|
@ -401,8 +401,8 @@ void PlayerWidget::updateSelected() {
|
|||
int32 delta = (pos.x() - _volumeRect.x()) - _downCoord;
|
||||
float64 startFrom = snap((_downCoord - ((_volumeRect.width() - st::playerVolume.pxWidth()) / 2)) / float64(st::playerVolume.pxWidth()), 0., 1.);
|
||||
float64 add = delta / float64(4 * st::playerVolume.pxWidth()), result = snap(startFrom + add, 0., 1.);
|
||||
if (result != cSongVolume()) {
|
||||
cSetSongVolume(result);
|
||||
if (result != Global::SongVolume()) {
|
||||
Global::SetSongVolume(result);
|
||||
emit audioPlayer()->songVolumeChanged();
|
||||
rtlupdate(_volumeRect);
|
||||
}
|
||||
|
|
|
@ -148,8 +148,6 @@ bool gDialogsReceived = false;
|
|||
|
||||
int gOtherOnline = 0;
|
||||
|
||||
float64 gSongVolume = 0.9;
|
||||
|
||||
SavedPeers gSavedPeers;
|
||||
SavedPeersByTime gSavedPeersByTime;
|
||||
|
||||
|
|
|
@ -291,8 +291,6 @@ DeclareSetting(bool, DialogsReceived);
|
|||
|
||||
DeclareSetting(int, OtherOnline);
|
||||
|
||||
DeclareSetting(float64, SongVolume);
|
||||
|
||||
class PeerData;
|
||||
typedef QMap<PeerData*, QDateTime> SavedPeers;
|
||||
typedef QMultiMap<QDateTime, PeerData*> SavedPeersByTime;
|
||||
|
|
Loading…
Reference in New Issue