-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
padreEnvelopeProcessor: fixes/tweaks #1202
padreEnvelopeProcessor: fixes/tweaks #1202
Conversation
Ah, this is because SWS is built targeting macOS 10.5. We can use C++11 syntax and features now but the standard library is ultimately limited to what's available in macOS 10.5's libstdc++. Apple started to add support for C++11 in 10.7's Line 14 in 629a566
|
Reading Directly write into char* buffer of std::string: so using |
Right. The standard didn't guarantee it, but I'm pretty sure the pre-C++11 libstdc++ does (though it uses copy-on-write, which shouldn't be an issue here).
EDIT: Double-checked from macOS 10.5's libstdc++'s source code (basic_string.h & basic_string.tcc). (Alternatively we could bump the min. macOS version to 10.7 and switch to libc++, use a |
ef957fe
to
6f6303f
Compare
Thanks! Phew, turned out more complicated (for me) than expected, but it finally builds now at least. 😄 |
ObjectState/TrackSends.cpp
Outdated
catch (_bad_get_env_chunk_big) { | ||
|
||
DisplayStoreSendEnvError(tr, "AUXVOL"); | ||
AUXVOLstr = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AUXVOLstr
is already initialized to an empty string by its constructor. There is no need re-assign it a new empty value.
ObjectState/TrackSends.cpp
Outdated
@@ -432,3 +454,25 @@ void TrackSends::GetChunk(WDL_FastString* chunk) | |||
for (int i = 0; i < m_sends.GetSize(); i++) | |||
m_sends.Get(i)->GetChunk(chunk); | |||
} | |||
|
|||
void TrackSends::DisplayStoreSendEnvError(MediaTrack* tr, const char* envName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of taking a const char* and doing string comparison with strncmp
, this could take an Enum (integer comparison).
Also, maybe this could take the exception (const bad_get_env_chunk_big &ex
) and display its message (ex.what()
) to further explain what the error is about (100 MiB buffer limit reached vs memory allocation failed).
ObjectState/TrackSends.cpp
Outdated
msg.append(__LOCALIZE("Error storing send mute envelope!", "sws_mbox")); | ||
} | ||
|
||
MessageBox(g_hwndParent, msg.c_str(), __LOCALIZE("SWS Snapshots - Error", "sws_mbox"), MB_OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message can be built using only the one stringstream.
std::ostringstream ss;
ss << "Track " << static_cast<int>(GetMediaTrackInfo_Value(tr, "IP_TRACKNUMBER")) << ":\n";
switch(envType) {
case AUXVOL:
ss << __LOCALIZE("Error storing send volume envelope!", "sws_mbox");
break;
case AUXPAN:
ss << __LOCALIZE("Error storing send pan envelope!", "sws_mbox");
break;
// ...
}
MessageBox(..., ss.str().c_str(), ...);
Padre/padreEnvelopeProcessor.cpp
Outdated
// account for take playrate, #1158 | ||
if (take) | ||
{ | ||
double playrate = GetMediaItemTakeInfo_Value(take, "D_PLAYRATE"); | ||
dFreq = dFreq / playrate; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be unrelated to the buffer size fix, and should probably be split in a separate commit.
EDIT: Could be written as:
if(take) // account for take playrate, #1158
dFreq /= GetMediaItemTakeInfo_Value(take, "D_PLAYRATE");
Utility/UtilityFunctions.cpp
Outdated
// throws _bad_get_env_chunk_big on failure | ||
// until maybe it gets enhanced one day | ||
// https://forum.cockos.com/showthread.php?p=2142245#post2142245 | ||
std::string _GetEnvelopeStateChunkBig(TrackEnvelope* envelope, bool isUndo /*= false*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this should just be called GetEnvelopeStateChunkBig
. The leading underscore makes it look like it's some kind of private/special/internal use/secret function that shouldn't be used outside of its compilation unit.
Maybe namespacing would be a better option here if there is a risk of name conflict.
Utility/UtilityFunctions.cpp
Outdated
_bad_get_env_chunk_big exExceeding100MiB("_GetEnvelopeStateChunkBig() exception (> 100 MiB)"); | ||
_bad_get_env_chunk_big exBad_alloc("_GetEnvelopeStateChunkBig() exception (bad_alloc)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to construct the exception object(s) ahead of time. This would do job just as well (avoiding doing more work unless an exception is actually being thrown–which is already a slow process):
throw bad_get_env_chunk_big("The envelope chunk size exceeded the 100 MiB limit");
Utility/UtilityFunctions.cpp
Outdated
|
||
if (buffer.size() > 100 << 20) { // 100 MiB | ||
throw exExceeding100MiB; | ||
std::cout << "_GetEnvelopeStateChunkBig() exception (> 100 MiB)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This std::cout
(and the one below) will never be reached (dead code).
Utility/UtilityFunctions.hpp
Outdated
private: | ||
std::string msg; | ||
public: | ||
explicit _bad_get_env_chunk_big(const std::string& message) {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message is lost here, and what()
will always return an empty string. You could make use of std::runtime_error (instead of essentially duplicating what it does):
class bad_get_env_chunk_big : public std::runtime_error {
public:
using runtime_error::runtime_error;
};
ObjectState/TrackSends.cpp
Outdated
@@ -29,6 +29,8 @@ | |||
#include "../reaper/localize.h" | |||
#include "../SnM/SnM_Dlg.h" | |||
#include "TrackSends.h" | |||
#include "Utility/UtilityFunctions.hpp" | |||
#include <sstream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sstream is already included in stdafx.h, the precompiled header (it's only precompiled on Windows).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UtilityFunctions.hpp/.cpp could serve as a place for collection of all future utility functions in one place (independent of contributor) and it also could be considered condensing some of the existing ones there.
👍 for contributor-independent functions and classes, but I find "UtilityFunctions" rather vague and catch-all. How about a new envelope.cpp or similar to be a bit more structured?
6f6303f
to
1460bdf
Compare
Thanks for the comprehensive review!
Hm..fine on Win/Linux, no luck on Mac: Any alternative suggestion? |
Adding |
1460bdf
to
05e6486
Compare
Thanks.
I had some difficulties with this:
Now takes the exception string instead
Used The rest is done according to your review (I think/hope). edit: |
I'll check tomorrow but I'm pretty sure the langpack generation tool only supports string literals. Alternatively EDIT: Confirmed. BuildUtils/BuildLangPack.cpp and https://github.com/reaper-oss/sws/wiki/How-to-write-localizable-code%3F.
namespace envUtil {
class bad_get_env_chunk_big;
};
void DisplayStoreSendEnvError(MediaTrack* tr, EnvTypes envName, const envUtil::bad_get_env_chunk_big &); However, because static void DisplayStoreSendEnvError(MediaTrack* tr, EnvTypes envType, const envUtil::bad_get_env_chunk_big &ex)
{
}
// code that uses it below (or add a prototype for the function before said code) |
The only thought to declare it in the header was avoiding using forward declarations / having to put the function somewhere in the middle (both I found a bit cluttery) ;D |
05e6486
to
5f82324
Compare
Done.
Done. Also changed Btw. why did you suggest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. why did you suggest envelope.hpp/cpp - lowercase?
Somehow I have in mind filenames always upper case, any rule you follow here?
Force of habit–I rarely deal with camel cased filenames for source files outside of SWS. I should probably have suggested Envelope.cpp for consistency as most source files in this repository use upper camel case (except those that don't 😄 ).
5f82324
to
0246a6c
Compare
done #1202 (review) |
take LFO generator: - allow for generating more envelope points (use envelope::GetEnvelopeStateChunkBig() instead of PadreGetEnvelopeState()) reaper-oss#1158 (partly) padreUtils: - remove GetEnvelopeState() +add files: envelope.hpp/.cpp (place for general envelope utility functions), #include in stdafx.h, update CMakeLists.txt +Snapshots: - TrackSends: use envelope::GetEnvelopeStateChunkBig() (instead of GetEnvelopeStateChunk())
0246a6c
to
db89dad
Compare
…github.com/nofishonfriday/sws into sws-2019-09, PR reaper-oss#1202 * 'fix-padre-lfo+get-envelope-state-chunk-big' of https://github.com/nofishonfriday/sws: padreEnvelopeProcessor: take LFO generator: account for take playrate, reaper-oss#1158 padreEnvelopeProcessor: fixes/tweaks
take LFO generator:
fixes Bug: LFO Generator can't handle take envelopes with too much points:"Could not retrieve envelope object state!" #1158
padreUtils:
+Snapshots:
+add files: envelope.hpp/.cpp (place for contributor independent utility functions), update CMakeLists.txt
rationale for adding
UtilityFunctions.hpp/.cpp:envelope.hpp/.cppCurrently (general) utility functions are spread in various places in SWS:
sws_util / wol_Util / SnM_Util / XenUtils / ...
I thought I'd rather not add to this by adding my own NF_Util.
So in the past I've added functions to e.g. sws_util, but I don't consider it good style as these are not 'my' files.
UtilityFunctions.hpp/.cpp could serve as a place for collection of all future utility functions in one place (independent of contributor) and it also could be considered condensing some of the existing ones there.
Wasn't sure about a good function naming convention there.
I've underscored (to differ from Reaper API functions) but not prefixed (e.g. with NF_) because of a possible contributor independent collection (see above), contributor name prefix seems not obligatory imo.
Open to discussion/suggestions!
edit:
I see the builds failed. :(
Well, it does build here, need to investigate..
edit2:
https://travis-ci.com/reaper-oss/sws/jobs/236430802#L542
https://stackoverflow.com/questions/16861535/stdstring-has-no-member-named-front
Confused, I thought we're using C++11(+) now?
The other build errors I have solved I think.