turn volume slider into mix slider
it's far more useful
This commit is contained in:
parent
a6d06d3728
commit
64b8a8f714
4 changed files with 49 additions and 13 deletions
|
|
@ -199,6 +199,10 @@ void DivFilePlayer::mix(float** buf, int chans, unsigned int size) {
|
|||
return;
|
||||
}
|
||||
|
||||
float actualVolume=volume+1.0f;
|
||||
if (actualVolume<0.0f) actualVolume=0.0f;
|
||||
if (actualVolume>1.0f) actualVolume=1.0f;
|
||||
|
||||
if (wantBlock!=DIV_NO_BLOCK) {
|
||||
cacheCV.notify_one();
|
||||
}
|
||||
|
|
@ -234,7 +238,7 @@ void DivFilePlayer::mix(float** buf, int chans, unsigned int size) {
|
|||
x[5]*t1[1]+
|
||||
x[6]*t1[2]+
|
||||
x[7]*t1[3]
|
||||
)*volume;
|
||||
)*actualVolume;
|
||||
|
||||
for (int j=0; j<chans; j++) {
|
||||
buf[j][i]=s;
|
||||
|
|
@ -257,7 +261,7 @@ void DivFilePlayer::mix(float** buf, int chans, unsigned int size) {
|
|||
x[5]*t1[1]+
|
||||
x[6]*t1[2]+
|
||||
x[7]*t1[3]
|
||||
)*volume;
|
||||
)*actualVolume;
|
||||
}
|
||||
|
||||
// advance
|
||||
|
|
@ -463,6 +467,14 @@ void DivFilePlayer::setVolume(float vol) {
|
|||
volume=vol;
|
||||
}
|
||||
|
||||
bool DivFilePlayer::getActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
void DivFilePlayer::setActive(bool active) {
|
||||
isActive=active;
|
||||
}
|
||||
|
||||
DivFilePlayer::DivFilePlayer():
|
||||
discardBuf(NULL),
|
||||
blocks(NULL),
|
||||
|
|
@ -474,11 +486,12 @@ DivFilePlayer::DivFilePlayer():
|
|||
wantBlock(DIV_NO_BLOCK),
|
||||
outRate(44100),
|
||||
rateAccum(0),
|
||||
volume(1.0f),
|
||||
volume(0.0f),
|
||||
playing(false),
|
||||
fileError(false),
|
||||
quitThread(false),
|
||||
threadHasQuit(false),
|
||||
isActive(false),
|
||||
cacheThread(NULL) {
|
||||
memset(&si,0,sizeof(SF_INFO));
|
||||
sincTable=DivFilterTables::getSincTable8();
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class DivFilePlayer {
|
|||
bool fileError;
|
||||
bool quitThread;
|
||||
bool threadHasQuit;
|
||||
bool isActive;
|
||||
|
||||
std::thread* cacheThread;
|
||||
std::mutex cacheMutex;
|
||||
|
|
@ -89,6 +90,8 @@ class DivFilePlayer {
|
|||
void setOutputRate(int rate);
|
||||
float getVolume();
|
||||
void setVolume(float vol);
|
||||
bool getActive();
|
||||
void setActive(bool active);
|
||||
|
||||
DivFilePlayer();
|
||||
~DivFilePlayer();
|
||||
|
|
|
|||
|
|
@ -3287,6 +3287,18 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
}
|
||||
}
|
||||
|
||||
// calculate volume of reference file player (so we can attenuate the rest according to the mix slider)
|
||||
// -1 to 0: player volume goes from 0% to 100%
|
||||
// 0 to +1: tracker volume goes from 100% to 0%
|
||||
float refPlayerVol=1.0f;
|
||||
if (curFilePlayer!=NULL) {
|
||||
// only if the player window is open
|
||||
if (curFilePlayer->getActive()) {
|
||||
refPlayerVol=1.0f-curFilePlayer->getVolume();
|
||||
if (refPlayerVol>1.0f) refPlayerVol=1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// now mix everything (resolve patchbay)
|
||||
for (unsigned int i: song.patchbay) {
|
||||
// there are 4096 portsets. each portset may have up to 16 outputs (subports).
|
||||
|
|
@ -3308,7 +3320,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
// chip outputs
|
||||
if (srcPortSet<song.systemLen && playing && !halted) {
|
||||
if (srcSubPort<disCont[srcPortSet].dispatch->getOutputCount()) {
|
||||
float vol=song.systemVol[srcPortSet]*disCont[srcPortSet].dispatch->getPostAmp()*song.masterVol;
|
||||
float vol=song.systemVol[srcPortSet]*disCont[srcPortSet].dispatch->getPostAmp()*song.masterVol*refPlayerVol;
|
||||
|
||||
// apply volume and panning
|
||||
switch (destSubPort&3) {
|
||||
|
|
|
|||
|
|
@ -23,15 +23,16 @@
|
|||
#include "IconsFontAwesome4.h"
|
||||
|
||||
void FurnaceGUI::drawRefPlayer() {
|
||||
DivFilePlayer* fp=e->getFilePlayer();
|
||||
if (nextWindow==GUI_WINDOW_REF_PLAYER) {
|
||||
refPlayerOpen=true;
|
||||
ImGui::SetNextWindowFocus();
|
||||
nextWindow=GUI_WINDOW_NOTHING;
|
||||
}
|
||||
fp->setActive(refPlayerOpen);
|
||||
if (!refPlayerOpen) return;
|
||||
if (ImGui::Begin("Music Player",&refPlayerOpen,globalWinFlags,_("Music Player"))) {
|
||||
DivFilePlayer* fp=e->getFilePlayer();
|
||||
|
||||
if (ImGui::Begin("Music Player",&refPlayerOpen,globalWinFlags,_("Music Player"))) {
|
||||
bool playPosNegative=false;
|
||||
ssize_t playPos=fp->getPos();
|
||||
if (playPos<0) {
|
||||
|
|
@ -85,23 +86,30 @@ void FurnaceGUI::drawRefPlayer() {
|
|||
}
|
||||
popToggleColors();
|
||||
e->setFilePlayerSync(filePlayerSync);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(_("Mix:"));
|
||||
|
||||
float vol=fp->getVolume();
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
if (ImGui::SliderFloat("##Volume",&vol,0.0f,1.0f)) {
|
||||
if (vol<0.0f) vol=0.0f;
|
||||
if (ImGui::SliderFloat("##Volume",&vol,-1.0f,1.0f,_("<-- Tracker / Reference -->"))) {
|
||||
if (vol<-1.0f) vol=-1.0f;
|
||||
if (vol>1.0f) vol=1.0f;
|
||||
fp->setVolume(vol);
|
||||
}
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||
fp->setVolume(0.0f);
|
||||
}
|
||||
|
||||
//ImGui::Text("Memory usage: %" PRIu64 "K",fp->getMemUsage()>>10);
|
||||
|
||||
if (!refPlayerOpen) {
|
||||
fp->stop();
|
||||
e->setFilePlayerSync(false);
|
||||
}
|
||||
}
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_REF_PLAYER;
|
||||
ImGui::End();
|
||||
|
||||
|
||||
if (!refPlayerOpen) {
|
||||
fp->stop();
|
||||
e->setFilePlayerSync(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue