Skip to content

Commit

Permalink
Merge branch 'next' of https://github.com/jeff0S/sws into next
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff0S committed Mar 30, 2015
2 parents 146153f + f4aaf62 commit c6b4df3
Show file tree
Hide file tree
Showing 16 changed files with 656 additions and 563 deletions.
217 changes: 115 additions & 102 deletions Breeder/BR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,107 @@
#include "../SnM/SnM.h"
#include "../reaper/localize.h"

/******************************************************************************
* Globals *
******************************************************************************/
static COMMAND_T* g_nextActionApplyer = NULL;
static int g_nextActionToApply = 0;
static int g_nextActionLoCmd = 0;
static int g_nextActionHiCmd = 0;
static set<int> g_nextActionApplyers;

/******************************************************************************
* Command hook *
******************************************************************************/
bool BR_GlobalActionHook (int cmd, int val, int valhw, int relmode, HWND hwnd)
{
if (g_nextActionApplyer)
{
COMMAND_T* nextActionApplyer = g_nextActionApplyer;
g_nextActionApplyer = NULL; // due to reentrancy, set as NULL before running the command

g_nextActionToApply = cmd;
if (nextActionApplyer->doCommand) nextActionApplyer->doCommand(nextActionApplyer);
else if (nextActionApplyer->onAction) nextActionApplyer->onAction(nextActionApplyer, val, valhw, relmode, hwnd);
g_nextActionToApply = 0;

return true;
}
return false;
}

bool BR_SwsActionHook (COMMAND_T* ct, int flagOrRelmode, HWND hwnd)
{
int cmd = ct->accel.accel.cmd;

// Action applies next action
if (cmd >= g_nextActionLoCmd && cmd <= g_nextActionHiCmd && g_nextActionApplyers.find(cmd) != g_nextActionApplyers.end())
{
g_nextActionApplyer = SWSGetCommandByID(cmd);
return true;
}

// Action is continuous action
if (ContinuousActionHook(ct, cmd, flagOrRelmode, hwnd))
return true;

return false;
}

int BR_GetNextActionToApply ()
{
return g_nextActionToApply;
}

/******************************************************************************
* Csurf *
******************************************************************************/
void BR_CSurfSetPlayState (bool play, bool pause, bool rec)
{
static const vector<void(*)(bool,bool,bool)>* s_functions = NULL;
if (!s_functions) RegisterCsurfPlayState(false, NULL, &s_functions);

if (s_functions->size() > 0)
{
for (size_t i = 0; i < s_functions->size(); ++i)
{
if (void(*func)(bool,bool,bool) = s_functions->at(i))
func(play, pause, rec);
}
RegisterCsurfPlayState(false, NULL, NULL, true);
}
}

int BR_CSurfExtended(int call, void* parm1, void* parm2, void* parm3)
{
if (call == CSURF_EXT_RESET)
{
LoudnessUpdate();
}
else if (call == CSURF_EXT_SETSENDVOLUME || call == CSURF_EXT_SETSENDPAN)
{
if (parm1 && parm2)
{
BR_EnvType type = (call == CSURF_EXT_SETSENDPAN) ? PAN : VOLUME;
GetSetLastAdjustedSend(true, (MediaTrack**)&parm1, (int*)parm2, &type);
}
}
return 0;
}

/******************************************************************************
* Continuous actions *
******************************************************************************/
void BR_RegisterContinuousActions ()
{
SetEnvPointMouseValueInit();
PlaybackAtMouseCursorInit ();
MoveGridToMouseInit();
}

/******************************************************************************
* Commands *
******************************************************************************/
//!WANT_LOCALIZE_1ST_STRING_BEGIN:sws_actions
static COMMAND_T g_commandTable[] =
{
Expand Down Expand Up @@ -474,6 +575,9 @@ static COMMAND_T g_commandTable[] =
{ { DEFACCEL, "SWS/BR: Set \"Apply trim when adding volume/pan envelopes\" to \"Always\"" }, "BR_OPTIONS_ENV_TRIM_ALWAYS", TrimNewVolPanEnvs, NULL, 0, IsTrimNewVolPanEnvsOn},
{ { DEFACCEL, "SWS/BR: Set \"Apply trim when adding volume/pan envelopes\" to \"In read/write\"" }, "BR_OPTIONS_ENV_TRIM_READWRITE", TrimNewVolPanEnvs, NULL, 1, IsTrimNewVolPanEnvsOn},
{ { DEFACCEL, "SWS/BR: Set \"Apply trim when adding volume/pan envelopes\" to \"Never\"" }, "BR_OPTIONS_ENV_TRIM_NEVER", TrimNewVolPanEnvs, NULL, 2, IsTrimNewVolPanEnvsOn},
{ { DEFACCEL, "SWS/BR: Toggle \"Display media item take name\"" }, "BR_OPTIONS_DISPLAY_ITEM_TAKE_NAME", ToggleDisplayItemLabels, NULL, 0, IsDisplayDisplayItemLabelsOn},
{ { DEFACCEL, "SWS/BR: Toggle \"Display media item pitch/playrate if set\"" }, "BR_OPTIONS_DISPLAY_ITEM_PITCH_RATE", ToggleDisplayItemLabels, NULL, 2, IsDisplayDisplayItemLabelsOn},
{ { DEFACCEL, "SWS/BR: Toggle \"Display media item gain if set\"" }, "BR_OPTIONS_DISPLAY_ITEM_GAIN", ToggleDisplayItemLabels, NULL, 4, IsDisplayDisplayItemLabelsOn},

{ { DEFACCEL, "SWS/BR: Cycle through record modes" }, "BR_CYCLE_RECORD_MODES", CycleRecordModes},

Expand Down Expand Up @@ -722,6 +826,9 @@ static COMMAND_T g_commandTable[] =
};
//!WANT_LOCALIZE_1ST_STRING_END

/******************************************************************************
* BR init/exit *
******************************************************************************/
int BR_Init ()
{
SWSRegisterCommands(g_commandTable);
Expand All @@ -732,6 +839,14 @@ int BR_Init ()
ProjStateInit();
VersionCheckInit();

// Keep "apply next action" registration mechanism here (no need for separate module until more actions are added)
g_nextActionApplyers.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_VIS_ENVS")); // Make sure these actions are registered
g_nextActionApplyers.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_REC_ENVS")); // consequentially so their cmds end up
g_nextActionApplyers.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_VIS_ENVS_NOSEL")); // consequential to optimize BR_SwsActionHook
g_nextActionApplyers.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_REC_ENVS_NOSEL"));
g_nextActionLoCmd = (g_nextActionApplyers.size() > 0) ? *g_nextActionApplyers.begin() : 0;
g_nextActionHiCmd = (g_nextActionApplyers.size() > 0) ? *g_nextActionApplyers.rbegin() : 0;

return 1;
}

Expand All @@ -744,106 +859,4 @@ void BR_Exit ()
VersionCheckExit();

ME_StopMidiTakePreview(NULL, 0, 0, 0, NULL); // in case any kind of preview is happening right now, make sure it's stopped
}

void BR_RegisterContinuousActions ()
{
SetEnvPointMouseValueInit();
PlaybackAtMouseCursorInit ();
MoveGridToMouseInit();
}

int BR_GetSetActionToApply (bool set, int cmd)
{
static int s_cmd = 0;
if (set)
s_cmd = cmd;
return s_cmd;
}

bool BR_GlobalActionHook (int cmd, int val, int valhw, int relmode, HWND hwnd)
{
static COMMAND_T* s_actionToRun = NULL;
static int s_lowCmd = 0;
static int s_highCmd = 0;
static set<int> s_actions;

static bool s_init = false;
if (!s_init)
{
s_actions.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_VIS_ENVS"));
s_actions.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_REC_ENVS"));
s_actions.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_VIS_ENVS_NOSEL"));
s_actions.insert(NamedCommandLookup("_BR_NEXT_CMD_SEL_TK_REC_ENVS_NOSEL"));
s_lowCmd = (s_actions.size() > 0) ? *s_actions.begin() : 0;
s_highCmd = (s_actions.size() > 0) ? *s_actions.rbegin() : 0;
s_init = true;
}

bool swallow = false;
if (cmd >= s_lowCmd && cmd <= s_highCmd && s_actions.find(cmd) != s_actions.end())
{
s_actionToRun = SWSGetCommandByID(cmd);
swallow = true;
}
else if (s_actionToRun && BR_GetSetActionToApply(false, 0) != 0)
{
COMMAND_T* actionToRun = s_actionToRun;
s_actionToRun = NULL; // due to reentrancy, mark this as NULL before running the command

BR_GetSetActionToApply(true, cmd);
if (actionToRun->doCommand) actionToRun->doCommand(actionToRun);
else if (actionToRun->onAction) actionToRun->onAction(actionToRun, val, valhw, relmode, hwnd);
BR_GetSetActionToApply(true, 0);

swallow = true;
}
return swallow;
}

bool BR_SwsActionHook (COMMAND_T* ct, int flagOrRelmode, HWND hwnd)
{
return ContinuousActionHook(ct, flagOrRelmode, hwnd);
}

void BR_CSurfSetPlayState (bool play, bool pause, bool rec)
{
static const vector<void(*)(bool,bool,bool)>* s_functions = NULL;
if (!s_functions) RegisterCsurfPlayState(false, NULL, &s_functions);

if (s_functions->size() > 0)
{
for (size_t i = 0; i < s_functions->size(); ++i)
{
if (void(*func)(bool,bool,bool) = s_functions->at(i))
func(play, pause, rec);
}
RegisterCsurfPlayState(false, NULL, NULL, true);
}
}

int BR_CSurfExtended(int call, void* parm1, void* parm2, void* parm3)
{
if (call == CSURF_EXT_RESET)
{
LoudnessUpdate();
}
else if (call == CSURF_EXT_SETSENDVOLUME || call == CSURF_EXT_SETSENDPAN)
{
if (parm1 && parm2)
{
int type = (call == CSURF_EXT_SETSENDPAN) ? PAN : VOLUME;
GetSetLastAdjustedSend(true, (MediaTrack**)&parm1, (int*)parm2, &type);
}
}
return 0;
}

const char* BR_GetIniFile ()
{
static WDL_FastString s_iniPath;
if (s_iniPath.GetLength() == 0)
s_iniPath.SetFormatted(SNM_MAX_PATH, "%s/BR.ini", GetResourcePath());

return s_iniPath.Get();
}
32 changes: 23 additions & 9 deletions Breeder/BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@
******************************************************************************/
#pragma once

int BR_Init ();
void BR_Exit ();
void BR_RegisterContinuousActions ();
int BR_GetSetActionToApply (bool set, int cmd);
bool BR_GlobalActionHook (int cmd, int val, int valhw, int relmode, HWND hwnd);
bool BR_SwsActionHook (COMMAND_T* ct, int flagOrRelmode, HWND hwnd);
void BR_CSurfSetPlayState (bool play, bool pause, bool rec);
int BR_CSurfExtended (int call, void* parm1, void* parm2, void* parm3);
const char* BR_GetIniFile ();
/******************************************************************************
* Command hook *
******************************************************************************/
bool BR_GlobalActionHook (int cmd, int val, int valhw, int relmode, HWND hwnd);
bool BR_SwsActionHook (COMMAND_T* ct, int flagOrRelmode, HWND hwnd);
int BR_GetNextActionToApply ();

/******************************************************************************
* Csurf *
******************************************************************************/
void BR_CSurfSetPlayState (bool play, bool pause, bool rec);
int BR_CSurfExtended (int call, void* parm1, void* parm2, void* parm3);

/******************************************************************************
* Continuous actions *
******************************************************************************/
void BR_RegisterContinuousActions ();

/******************************************************************************
* BR init/exit *
******************************************************************************/
int BR_Init ();
void BR_Exit ();
28 changes: 14 additions & 14 deletions Breeder/BR_ContextualToolbars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ int BR_ContextualToolbar::FindTcpToolbar (BR_MouseInfo& mouseInfo, BR_Contextua
{
context = TCP_ENVELOPE;

int type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);
BR_EnvType type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);
if (type == VOLUME || type == VOLUME_PREFX) context = (this->GetMouseAction(TCP_ENVELOPE_VOLUME) == INHERIT_PARENT) ? TCP_ENVELOPE : TCP_ENVELOPE_VOLUME;
else if (type == PAN || type == PAN_PREFX) context = (this->GetMouseAction(TCP_ENVELOPE_PAN) == INHERIT_PARENT) ? TCP_ENVELOPE : TCP_ENVELOPE_PAN;
else if (type == WIDTH || type == WIDTH_PREFX) context = (this->GetMouseAction(TCP_ENVELOPE_WIDTH) == INHERIT_PARENT) ? TCP_ENVELOPE : TCP_ENVELOPE_WIDTH;
Expand Down Expand Up @@ -919,7 +919,7 @@ int BR_ContextualToolbar::FindArrangeToolbar (BR_MouseInfo& mouseInfo, BR_Contex
if (mouseInfo.IsTakeEnvelope())
{
context = ARRANGE_TRACK_TAKE_ENVELOPE;
int type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);
BR_EnvType type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);

if (type == VOLUME || type == VOLUME_PREFX) context = (this->GetMouseAction(ARRANGE_TRACK_TAKE_ENVELOPE_VOLUME) == INHERIT_PARENT) ? ARRANGE_TRACK_TAKE_ENVELOPE : ARRANGE_TRACK_TAKE_ENVELOPE_VOLUME;
else if (type == PAN || type == PAN_PREFX) context = (this->GetMouseAction(ARRANGE_TRACK_TAKE_ENVELOPE_PAN) == INHERIT_PARENT) ? ARRANGE_TRACK_TAKE_ENVELOPE : ARRANGE_TRACK_TAKE_ENVELOPE_PAN;
Expand All @@ -941,7 +941,7 @@ int BR_ContextualToolbar::FindArrangeToolbar (BR_MouseInfo& mouseInfo, BR_Contex
else
{
context = ARRANGE_ENVELOPE_TRACK;
int type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);
BR_EnvType type = GetEnvType(mouseInfo.GetEnvelope(), NULL, NULL);

if (type == VOLUME || type == VOLUME_PREFX) context = (this->GetMouseAction(ARRANGE_ENVELOPE_TRACK_VOLUME) == INHERIT_PARENT) ? ARRANGE_ENVELOPE_TRACK : ARRANGE_ENVELOPE_TRACK_VOLUME;
else if (type == PAN || type == PAN_PREFX) context = (this->GetMouseAction(ARRANGE_ENVELOPE_TRACK_PAN) == INHERIT_PARENT) ? ARRANGE_ENVELOPE_TRACK : ARRANGE_ENVELOPE_TRACK_PAN;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ bool BR_ContextualToolbar::GetReaperToolbar (int id, int* mouseAction, int* togg
defaultName.AppendFormatted(512, "%s %d", "Toolbar", toolbarId);
}

GetPrivateProfileString(section.Get(), "title", __localizeFunc(defaultName.Get(), "MENU_349", 0), toolbarName, toolbarNameSz, GetReaperMenuIniPath().Get());
GetPrivateProfileString(section.Get(), "title", __localizeFunc(defaultName.Get(), "MENU_349", 0), toolbarName, toolbarNameSz, GetReaperMenuIni());
}
}

Expand Down Expand Up @@ -1733,10 +1733,10 @@ BR_ContextualToolbar* BR_ContextualToolbarsManager::GetContextualToolbar (int id
char contextAutoClose[size];
char contextPosition[size];
char options[size];
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_CONTEXTS, id).Get(), "", contextToolbars, size, BR_GetIniFile());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_AUTOCLOSE, id).Get(), "", contextAutoClose, size, BR_GetIniFile());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_POSITION, id).Get(), "", contextPosition, size, BR_GetIniFile());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_OPTIONS, id).Get(), "", options, size, BR_GetIniFile());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_CONTEXTS, id).Get(), "", contextToolbars, size, GetIniFileBR());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_AUTOCLOSE, id).Get(), "", contextAutoClose, size, GetIniFileBR());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_POSITION, id).Get(), "", contextPosition, size, GetIniFileBR());
GetPrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_OPTIONS, id).Get(), "", options, size, GetIniFileBR());

contextualToolbar->ImportConfig(contextToolbars, contextAutoClose, contextPosition, options);
}
Expand All @@ -1757,10 +1757,10 @@ void BR_ContextualToolbarsManager::SetContextualToolbar (int id, BR_ContextualTo
WDL_FastString options;
currentContextualToolbar->ExportConfig(contextToolbars, contextAutoClose, contextPosition, options);

WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_CONTEXTS, id).Get(), contextToolbars.Get(), BR_GetIniFile());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_AUTOCLOSE, id).Get(), contextAutoClose.Get(), BR_GetIniFile());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_POSITION, id).Get(), contextPosition.Get(), BR_GetIniFile());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_OPTIONS, id).Get(), options.Get(), BR_GetIniFile());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_CONTEXTS, id).Get(), contextToolbars.Get(), GetIniFileBR());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_AUTOCLOSE, id).Get(), contextAutoClose.Get(), GetIniFileBR());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_POSITION, id).Get(), contextPosition.Get(), GetIniFileBR());
WritePrivateProfileString(INI_SECTION, this->GetKeyForPreset(INI_KEY_OPTIONS, id).Get(), options.Get(), GetIniFileBR());
}
}

Expand Down Expand Up @@ -2227,7 +2227,7 @@ BR_ContextualToolbar* BR_ContextualToolbarsWnd::GetCurrentContextualToolbar ()
void BR_ContextualToolbarsWnd::OnInitDlg ()
{
char currentPresetStr[64];
GetPrivateProfileString(INI_SECTION, INI_KEY_CURRENT_PRESET, "0", currentPresetStr, sizeof(currentPresetStr), BR_GetIniFile());
GetPrivateProfileString(INI_SECTION, INI_KEY_CURRENT_PRESET, "0", currentPresetStr, sizeof(currentPresetStr), GetIniFileBR());
m_currentPreset = atoi(currentPresetStr);
if (m_currentPreset < 0 || m_currentPreset > PRESET_COUNT)
m_currentPreset = 0;
Expand Down Expand Up @@ -2532,7 +2532,7 @@ void BR_ContextualToolbarsWnd::OnDestroy ()
{
char currentPresetStr[512];
_snprintfSafe(currentPresetStr, sizeof(currentPresetStr), "%d", m_currentPreset);
WritePrivateProfileString(INI_SECTION, INI_KEY_CURRENT_PRESET, currentPresetStr, BR_GetIniFile());
WritePrivateProfileString(INI_SECTION, INI_KEY_CURRENT_PRESET, currentPresetStr, GetIniFileBR());
}

void BR_ContextualToolbarsWnd::GetMinSize (int* w, int* h)
Expand Down
12 changes: 7 additions & 5 deletions Breeder/BR_ContinuousActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,19 @@ int ContinuousActionTooltips ()
return g_tooltips;
}

bool ContinuousActionHook (COMMAND_T* ct, int flagOrRelmode, HWND hwnd)
bool ContinuousActionHook (COMMAND_T* ct, int cmd, int flagOrRelmode, HWND hwnd)
{
bool swallow = false;
int cmd = ct->accel.accel.cmd;
if (cmd >= g_continuousCmdLo && cmd <= g_continuousCmdHi) // instead of searching the list every time, first check if cmd is even within range of the list
{
// Check if the action is continuous and then let it pass if it was sent for the first time or when run through timer
if (BR_ContinuousAction* action = g_actions.Get(FindActionFromCmd(g_actions, cmd)))
swallow = (g_actionInProgress) ? (flagOrRelmode != ACTION_FLAG || g_actionInProgress->ct->accel.accel.cmd != cmd) : (!ContinuousActionInit(true, ct, hwnd, action));
{
return (g_actionInProgress)
? (flagOrRelmode != ACTION_FLAG || g_actionInProgress->ct->accel.accel.cmd != cmd)
: (!ContinuousActionInit(true, ct, hwnd, action));
}
}
return swallow;
return false;
}

void ContinuousActionsExit ()
Expand Down
Loading

0 comments on commit c6b4df3

Please sign in to comment.