Page 1 of 1
bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 1:27 pm
by eduard
I use audacity with mod-script-pipe, and noticed this issue because on my ubuntu audacity started with interface in Romanian language.
But I have the same behavior on windows, if I switch the language of the Interface between english and romanian.
I import a track in audacity and read using a python script the tracks
TOPIPE.write('GetInfo: Type=Tracks' + EOL)
With language=English I get this:
[
{ "name":"radio", "focused":0, "selected":1, "kind":"wave", "start":0, "end":30.0466, "pan":0, "gain":1, "channels":1, "solo":0, "mute":0, "VZoomMin":-1, "VZoomMax":1 } ]
BatchCommand finished: OK
with language=Romanian I get this
{ "name":"radio", "focused":0, "selected":1, "kind":"wave", "start":0, "end":30,0466, "pan":0, "gain":1, "channels":1, "solo":0, "mute":0, "VZoomMin":-1, "VZoomMax":1 }]
BatchCommand finished: OK
The difference between the two is in this part
english ------> "end":30.0466
romanian --------> "end":30,0466
The comma (,) is used as a decimal separator in romanian.
This trigger error during json.loads()
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:
I think the easiest fix would be to enclose the value in double quotes.
Thanks
Re: bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 2:40 pm
by steve
Thanks for the report.
There's several other places this occurs too, such as clip start / end times, vertical zoom, and several others.
A possible solution would be for each occurrence (in the Audacity code), to wrap the values in:
Example:
Now
Code: Select all
[
{ "name":"Audio Track", "focused":1, "selected":1, "kind":"wave", "start":0, "end":29,3854, "pan":0, "gain":0,281838, "channels":1, "solo":0, "mute":0, "VZoomMin":-1, "VZoomMax":1 } ]
With "Internat::ToString"
Code: Select all
[
{ "name":"Audio Track", "focused":1, "selected":1, "kind":"wave", "start":0, "end":"29.385397", "pan":0, "gain":0,281838, "channels":1, "solo":0, "mute":0, "VZoomMin":-0,461539, "VZoomMax":0,769231 } ]
Would that solve the problem for you?
Re: bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 3:07 pm
by steve
I recall that you build Audacity yourself, so here's the fix if you wish to modify your version of Audacity.
In each case in GetInfoCommand.cpp where you see a line:
Code: Select all
context.AddItem( <floating point value> );
rewrite the line as:
Code: Select all
context.AddItem( Internat::ToString(<floating point value>) );
For example, in bool GetInfoCommand::SendTracks(const CommandContext & context)
change:
Code: Select all
context.AddItem( "wave", "kind" );
context.AddItem( t->GetStartTime(), "start" );
context.AddItem( t->GetEndTime(), "end" );
to:
Code: Select all
context.AddItem( "wave", "kind" );
context.AddItem( Internat::ToString(t->GetStartTime()), "start" );
context.AddItem( Internat::ToString(t->GetEndTime()), "end" );
Re: bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 6:07 pm
by eduard
I made those changes, and how the times are quoted.
Thanks for the response.
Regards,
Razvan
Re: bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 8:13 pm
by steve
The "solution" that I proposed in my previous post has disadvantages for Nyquist Macros, but hopefully it's sufficient for you in the short term.
Re: bug 2.3.2 mod-script-pipe
Posted: Thu Jun 20, 2019 10:15 pm
by steve
Here's a better fix.
This retains the dot as the decimal separator, but does not quote the numeric values, so it does not interfere with Nyquist.
Code: Select all
diff --git a/src/commands/CommandTargets.cpp b/src/commands/CommandTargets.cpp
index 490d3fb..c171827 100644
--- a/src/commands/CommandTargets.cpp
+++ b/src/commands/CommandTargets.cpp
@@ -32,6 +32,9 @@ capture the more lengthy output from some commands.
#include "../widgets/AudacityMessageBox.h"
#include "../widgets/wxPanelWrapper.h"
+#include <locale>
+#include <sstream>
+
void CommandMessageTarget::StartArray()
{
wxString Padding;
@@ -78,11 +81,18 @@ void CommandMessageTarget::AddBool(const bool value, const wxString &name){
Update( wxString::Format( "%s\"%s\":\"%s\"", (mCounts.back()>0)?", ":"", name,value?"true":"false"));
mCounts.back() += 1;
}
+
void CommandMessageTarget::AddItem(const double value, const wxString &name){
+ std::stringstream str;
+ std::locale nolocale("");
+ str.imbue(nolocale);
+
if( name.empty() )
- Update( wxString::Format( "%s%g", (mCounts.back()>0)?", ":"", value));
+ str << ((mCounts.back()>0)? ", " : "") << value;
else
- Update( wxString::Format( "%s\"%s\":%g", (mCounts.back()>0)?", ":"", name,value));
+ str << ((mCounts.back()>0)? ", " : "") << "\"" << name << "\"" << ":" << value;
+
+ Update( str.str() );
mCounts.back() += 1;
}
Re: bug 2.3.2 mod-script-pipe
Posted: Fri Jun 21, 2019 6:39 am
by eduard
yes, by putting the float values between double quotes, solved it for me.
(I don't use Nyquist)
Thanks for the prompt help Steve