Skip to content

Commit

Permalink
Merge remote-tracking branch 'nofishonfriday/Fixes' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	whatsnew.txt
  • Loading branch information
swstim committed Sep 28, 2017
2 parents bb7fe36 + 3340de9 commit da31b5b
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 20 deletions.
17 changes: 15 additions & 2 deletions Breeder/BR_ReaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,23 @@ double NF_GetMediaItemMaxPeak(MediaItem* item)
return maxPeak;
}

double NF_GetMediaItemPeakRMS_Windowed(MediaItem* item)
{
double peakRMS = GetMediaItemPeakRMS_Windowed(item);
return peakRMS;
}

double NF_GetMediaItemPeakRMS_NonWindowed(MediaItem* item)
{
double peakRMSperChannel = GetMediaItemPeakRMS_NonWindowed(item);
return peakRMSperChannel;
}

double NF_GetMediaItemAverageRMS(MediaItem* item)
{
double avrgRMS = GetMediaItemAverageRMS(item);
return avrgRMS;
double averageRMS = GetMediaItemAverageRMS(item);
return averageRMS;

}

// #880
Expand Down
2 changes: 2 additions & 0 deletions Breeder/BR_ReaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ bool BR_Win32_WritePrivateProfileString (const char* sectionName, con

// #781
double NF_GetMediaItemMaxPeak(MediaItem* item);
double NF_GetMediaItemPeakRMS_Windowed(MediaItem* item);
double NF_GetMediaItemAverageRMS(MediaItem* item);
double NF_GetMediaItemPeakRMS_NonWindowed(MediaItem* item);

// #880
bool NF_AnalyzeTakeLoudness_IntegratedOnly(MediaItem_Take* take, double* lufsIntegratedOut);
Expand Down
18 changes: 13 additions & 5 deletions Misc/Adam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,6 @@ void AWDoAutoGroup(bool rec)

// #587 Auto Group in takes mode
else if (items.GetSize() > 1 && ((*(int*)GetConfigVar("autoxfade") == 0) || (*(int*)GetConfigVar("autoxfade") & 1)))
//else if (items.GetSize() > 1 && ((*(int*)GetConfigVar("autoxfade") & 1))) // takes mode
{
NFDoAutoGroupTakesMode();
}
Expand All @@ -991,15 +990,26 @@ void AWDoAutoGroup(bool rec)
// replication of X-Raym's "Group selected items according to their order in selection per track.lua"
void NFDoAutoGroupTakesMode()
{

PreventUIRefresh(1); // comment out for testing

NFTrackItemUtilities trackItemUtility;
// vector<int> v_selItemsOnTrack = trackItemUtility.NFGetIntVector();

// only group if more than one track is rec. armed
// otherwise it would group items to itself on same track
if (!trackItemUtility.isMoreThanOneTrackRecArmed())
return;

PreventUIRefresh(1); // comment out for testing

trackItemUtility.NFSaveSelectedItems();
trackItemUtility.NFSaveSelectedTracks();

Undo_BeginBlock();

// fix for p=1882461&postcount=422
if (g_AWAutoGroupRndColor)
Main_OnCommand(41332, 0); // set active take to one random color

trackItemUtility.NFUnselectAllTracks();
trackItemUtility.NFSelectTracksOfSelectedItems();

Expand Down Expand Up @@ -1029,8 +1039,6 @@ void NFDoAutoGroupTakesMode()
SetMediaItemSelected(item, true);
}
}
if (g_AWAutoGroupRndColor)
Main_OnCommand(40706, 0); // set items to one random color
Main_OnCommand(40032, 0); // Group items
}
trackItemUtility.NFRestoreSelectedItems();
Expand Down
101 changes: 93 additions & 8 deletions Misc/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,16 @@ double GetMediaItemMaxPeak(MediaItem* mi)
}
}

double GetMediaItemAverageRMS(MediaItem* mi)
double GetMediaItemPeakRMS_Windowed(MediaItem* mi)
{
double curAvrgRMS = -150.0;
double maxAvrgRMS = -150.0;
// double curPeakRMS = -150.0;
// double maxPeakRMS = -150.0;

// if MIDI item, don't scan
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;

/*
int iChannels = ((PCM_source*)mi)->GetNumChannels();
if (iChannels)
{
Expand All @@ -285,21 +286,105 @@ double GetMediaItemAverageRMS(MediaItem* mi)
a.iChannels = iChannels;
a.dRMSs = new double[iChannels];
// set window size
char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;
if (AnalyzeItem(mi, &a))
{
for (int i = 0; i < iChannels; i++) {
curAvrgRMS = VAL2DB(a.dRMSs[i]);
if (maxAvrgRMS < curAvrgRMS) {
maxAvrgRMS = curAvrgRMS;
curPeakRMS = VAL2DB(a.dRMSs[i]);
if (maxPeakRMS < curPeakRMS) {
maxPeakRMS = curPeakRMS;
}
}
}
delete[] a.dRMSs;
return maxAvrgRMS;
return maxPeakRMS;
} else {
return -150.0;
}
*/

ANALYZE_PCM a;
memset(&a, 0, sizeof(a));

char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;

if (AnalyzeItem(mi, &a)) {
return VAL2DB(a.dRMS);
} else {
return -150.0;
}
}

double GetMediaItemPeakRMS_NonWindowed(MediaItem* mi)
{
double curPeakRMS = -150.0;
double maxPeakRMS = -150.0;

// if MIDI item, don't scan
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;


int iChannels = ((PCM_source*)mi)->GetNumChannels();
if (iChannels)
{
ANALYZE_PCM a;
memset(&a, 0, sizeof(a));
a.iChannels = iChannels;
a.dRMSs = new double[iChannels];

/*
// set window size
char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;
*/

if (AnalyzeItem(mi, &a))
{
for (int i = 0; i < iChannels; i++) {
curPeakRMS = VAL2DB(a.dRMSs[i]);
if (maxPeakRMS < curPeakRMS) {
maxPeakRMS = curPeakRMS;
}
}
}

delete[] a.dRMSs;
return maxPeakRMS;
} else {
return -150.0;
}
}

double GetMediaItemAverageRMS(MediaItem* mi)
{
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;

ANALYZE_PCM a;
memset(&a, 0, sizeof(a));
a.dWindowSize = 0.0; // non-windowed


if (AnalyzeItem(mi, &a)) {
return VAL2DB(a.dRMS);
}
else {
return -150.0;
}
} // /#781
}
// /#781

void FindItemPeak(COMMAND_T*)
{
Expand Down
2 changes: 2 additions & 0 deletions Misc/Analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ bool AnalyzeItem(MediaItem* mi, ANALYZE_PCM* a);

// #781
double GetMediaItemMaxPeak(MediaItem*);
double GetMediaItemPeakRMS_Windowed(MediaItem*);
double GetMediaItemAverageRMS(MediaItem*);
double GetMediaItemPeakRMS_NonWindowed(MediaItem*);
10 changes: 6 additions & 4 deletions ReaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ APIdef g_apidefs[] =
{ APIFUNC(ULT_GetMediaItemNote), "const char*", "MediaItem*", "item", "[ULT] Get item notes.", },
{ APIFUNC(ULT_SetMediaItemNote), "void", "MediaItem*,const char*", "item,note", "[ULT] Set item notes.", },

// #781
{ APIFUNC(NF_GetMediaItemMaxPeak), "double", "MediaItem*", "item", "Returns the greatest max. peak value of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. Returns -150.0 if MIDI item or empty item.", },
{ APIFUNC(NF_GetMediaItemAverageRMS), "double", "MediaItem*", "item", "Returns the RMS peak level of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. Returns -150.0 if MIDI item or empty item.", },
// #781
{ APIFUNC(NF_GetMediaItemMaxPeak), "double", "MediaItem*", "item", "Returns the greatest max. peak value of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemPeakRMS_Windowed), "double", "MediaItem*", "item", "Returns the average RMS peak level of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Obeys 'Window size for peak RMS' setting in 'SWS: Set RMS analysis/normalize options' for calculation. Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemPeakRMS_NonWindowed), "double", "MediaItem*", "item", "Returns the greatest overall (non-windowed) RMS peak level of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemAverageRMS), "double", "MediaItem*", "item", "Returns the average overall (non-windowed) RMS level of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },

// #880
{ APIFUNC(NF_AnalyzeTakeLoudness_IntegratedOnly), "bool", "MediaItem_Take*,double*", "take,lufsIntegratedOut", "Does LUFS integrated analysis only. Faster than full loudness analysis (<a href=\"#NF_AnalyzeTakeLoudness\">NF_AnalyzeTakeLoudness</a>) . Use this if only LUFS integrated is required." },
Expand Down Expand Up @@ -297,4 +299,4 @@ bool RegisterExportedAPI(reaper_plugin_info_t* _rec)
}
}
return ok;
}
}
14 changes: 14 additions & 0 deletions nofish/nofish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ int NFTrackItemUtilities::GetMaxValfromIntVector(vector<int> intVector)
return maxVal;
}

bool NFTrackItemUtilities::isMoreThanOneTrackRecArmed()
{
int RecArmedTracks = 0;
for (int i = 0; i < GetNumTracks(); i++) {
MediaTrack* CurTrack = CSurf_TrackFromID(i + 1, false);
if (*(int*)GetSetMediaTrackInfo(CurTrack, "I_RECARM", NULL)) {
RecArmedTracks += 1;
if (RecArmedTracks > 1)
return true;
}
}
return false;
}

/*
const vector<int>& NFTrackItemUtilities::NFGetIntVector() const
{
Expand Down
2 changes: 2 additions & 0 deletions nofish/nofish.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class NFTrackItemUtilities

int GetMaxValfromIntVector(vector <int>);

bool isMoreThanOneTrackRecArmed();

private:
// vector <int> count_sel_items_on_track;

Expand Down
16 changes: 16 additions & 0 deletions reascript_vararg.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,22 @@ static void* __vararg_NF_GetMediaItemMaxPeak(void** arglist, int numparms)
return p;
}

static void* __vararg_NF_GetMediaItemPeakRMS_Windowed(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
double d = NF_GetMediaItemPeakRMS_Windowed((MediaItem*)arglist[0]);
if (p) *p=d;
return p;
}

static void* __vararg_NF_GetMediaItemPeakRMS_NonWindowed(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
double d = NF_GetMediaItemPeakRMS_NonWindowed((MediaItem*)arglist[0]);
if (p) *p=d;
return p;
}

static void* __vararg_NF_GetMediaItemAverageRMS(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
Expand Down
7 changes: 6 additions & 1 deletion whatsnew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ Fixes:
+Issue 897: Fix major issues with OSX 10.13 High Sierra
+Issue 877: Fix ReaConsole default shortcut on Linux and Windows
+Fix missing null terminator in CF_GetClipboard on Windows when clipboard length >= buffer size
+Fix NF_GetMediaItemAverageRMS() calculation
+Fix issue with action "SWS/AW/NF: Toggle assign random colors if auto group newly recorded items is enabled" (http://forum.cockos.com/showpost.php?p=1882461&postcount=422)

Add CF_GetClipboardBig ReaScript function. (Thanks cfillion!)
New ReaScript functions:
+CF_GetClipboardBig (Thanks cfillion!)
+NF_GetMediaItemPeakRMS_Windowed()
+NF_GetMediaItemPeakRMS_NonWindowed()

!v2.9.6 featured build (September 4, 2017)
Fixes:
Expand Down

0 comments on commit da31b5b

Please sign in to comment.