Skip to content

Commit

Permalink
Merge branch 'read-error-debug-msg'
Browse files Browse the repository at this point in the history
* read-error-debug-msg:
  LIB: MorphPlan: report load errors do debug log and stderr, but don't fail
  LIB: MorphGrid: improve read error debug output
  LIB: MorphLFO: improve read error debug output
  LIB: MorphLinear: improve read error debug output
  LIB: MorphOutput: improve read error debug output
  LIB: MorphKeyTrack: improve read error debug output
  LIB: MorphSource: improve read error debug output
  LIB: MorphWavSource: improve read error debug output
  LIB: MorphEnvelope: improve read error debug output
  LIB: MorphOperator: provide helper function to report read errors
  LIB: InFile: provide helper functions to debug read errors

Signed-off-by: Stefan Westerfeld <[email protected]>
  • Loading branch information
swesterfeld committed Apr 30, 2024
2 parents d9783f2 + bb6edbb commit eed337b
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 49 deletions.
25 changes: 24 additions & 1 deletion lib/sminfile.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html

#include "sminfile.hh"
#include "smutils.hh"
#include <assert.h>
#include <glib.h>

Expand Down Expand Up @@ -366,11 +367,33 @@ InFile::open_blob()
* \returns current event name
*/
string
InFile::event_name()
InFile::event_name() const
{
return current_event_str;
}

string
InFile::event_type() const
{
switch (current_event)
{
case Event::FLOAT: return "float";
case Event::INT: return "int";
case Event::BOOL: return "bool";
case Event::STRING: return "string";
case Event::FLOAT_BLOCK: return "float_block";
case Event::UINT16_BLOCK: return "uint16_block";
case Event::BLOB: return "blob";
case Event::BLOB_REF: return "blob_ref";
case Event::NONE: return "none";
case Event::END_OF_FILE: return "end_of_file";
case Event::BEGIN_SECTION: return "begin_section";
case Event::END_SECTION: return "end_section";
case Event::READ_ERROR: return "read_error";
}
return string_printf ("unknown_type_%d\n", current_event);
}

/**
* Get float data of the current event (only if the event is a FLOAT).
*
Expand Down
3 changes: 2 additions & 1 deletion lib/sminfile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public:
return file != NULL;
}
Event event();
std::string event_name();
std::string event_name() const;
std::string event_type() const;
float event_float();
int event_int();
bool event_bool();
Expand Down
6 changes: 3 additions & 3 deletions lib/smmorphenvelope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ MorphEnvelope::save (OutFile& out_file)
bool
MorphEnvelope::load (InFile& ifile)
{
bool read_ok = true;
while (ifile.event() != InFile::END_OF_FILE)
{
if (read_property_event (ifile) || m_config.curve.load ("curve", ifile))
Expand All @@ -81,12 +82,11 @@ MorphEnvelope::load (InFile& ifile)
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

MorphOperator::OutputType
Expand Down
23 changes: 12 additions & 11 deletions lib/smmorphgrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ MorphGrid::save (OutFile& out_file)
bool
MorphGrid::load (InFile& ifile)
{
bool read_ok = true;
map<string, pair<int, int> > delta_db_map;

load_map.clear();
Expand Down Expand Up @@ -113,8 +114,7 @@ MorphGrid::load (InFile& ifile)
}
else
{
g_printerr ("bad int\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else if (ifile.event() == InFile::FLOAT)
Expand All @@ -132,14 +132,16 @@ MorphGrid::load (InFile& ifile)
}
}
map<string, pair<int, int> >::const_iterator it = delta_db_map.find (ifile.event_name());
if (it == delta_db_map.end())
if (it != delta_db_map.end())
{
g_printerr ("bad float\n");
return false;
const int x = it->second.first;
const int y = it->second.second;
m_config.input_node[x][y].delta_db = ifile.event_float();
}
else
{
report_bad_event (read_ok, ifile);
}
const int x = it->second.first;
const int y = it->second.second;
m_config.input_node[x][y].delta_db = ifile.event_float();
}
else if (ifile.event() == InFile::STRING)
{
Expand All @@ -149,12 +151,11 @@ MorphGrid::load (InFile& ifile)
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

void
Expand Down
6 changes: 3 additions & 3 deletions lib/smmorphkeytrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MorphKeyTrack::save (OutFile& out_file)
bool
MorphKeyTrack::load (InFile& ifile)
{
bool read_ok = true;
while (ifile.event() != InFile::END_OF_FILE)
{
if (read_property_event (ifile) || m_config.curve.load ("curve", ifile))
Expand All @@ -53,12 +54,11 @@ MorphKeyTrack::load (InFile& ifile)
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

MorphOperator::OutputType
Expand Down
9 changes: 4 additions & 5 deletions lib/smmorphlfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ MorphLFO::save (OutFile& out_file)
bool
MorphLFO::load (InFile& ifile)
{
bool read_ok = true;
while (ifile.event() != InFile::END_OF_FILE)
{
if (read_property_event (ifile) || m_config.curve.load ("curve", ifile))
Expand All @@ -124,18 +125,16 @@ MorphLFO::load (InFile& ifile)
}
else
{
g_printerr ("bad bool\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

MorphOperator::OutputType
Expand Down
13 changes: 6 additions & 7 deletions lib/smmorphlinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ MorphLinear::save (OutFile& out_file)
bool
MorphLinear::load (InFile& ifile)
{
bool read_ok = true;

load_left = "";
load_right = "";

Expand Down Expand Up @@ -91,8 +93,7 @@ MorphLinear::load (InFile& ifile)
}
else
{
g_printerr ("bad string\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else if (ifile.event() == InFile::BOOL)
Expand All @@ -109,18 +110,16 @@ MorphLinear::load (InFile& ifile)
}
else
{
g_printerr ("bad bool\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

void
Expand Down
9 changes: 9 additions & 0 deletions lib/smmorphoperator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ MorphOperator::read_properties_post_load (OpNameMap& op_name_map)
}
}

void
MorphOperator::report_bad_event (bool& read_ok, const InFile& in_file)
{
string msg = string_printf ("%s: bad event while loading: %s %s\n", type_name().c_str(), in_file.event_type().c_str(), in_file.event_name().c_str());
g_printerr ("%s", msg.c_str());
sm_debug ("%s", msg.c_str());
read_ok = false;
}

MorphOperatorConfig::~MorphOperatorConfig()
{
}
Expand Down
1 change: 1 addition & 0 deletions lib/smmorphoperator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public:
void write_properties (OutFile& out_file);
bool read_property_event (InFile& in_file);
void read_properties_post_load (OpNameMap& op_name_map);
void report_bad_event (bool& read_ok, const InFile& in_file);

MorphPlan *morph_plan();

Expand Down
9 changes: 4 additions & 5 deletions lib/smmorphoutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ MorphOutput::save (OutFile& out_file)
bool
MorphOutput::load (InFile& ifile)
{
bool read_ok = true;
load_channel_op_names.clear();

while (ifile.event() != InFile::END_OF_FILE)
Expand All @@ -154,18 +155,16 @@ MorphOutput::load (InFile& ifile)
}
else
{
g_printerr ("bad string\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

void
Expand Down
9 changes: 8 additions & 1 deletion lib/smmorphplan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ MorphPlan::load_internal (GenericIn *in, ExtraParameters *params)

GenericIn *in = MMapIn::open_vector (blob_data);
InFile blob_infile (in);
load_op->load (blob_infile);
bool read_ok = load_op->load (blob_infile);
if (!read_ok)
{
string msg = string_printf ("%s: something went wrong during load\n", load_op->type_name().c_str());
g_printerr ("%s", msg.c_str());
sm_debug ("%s", msg.c_str());
// don't abort loading - ignore load errors here, at least doing things as good as we can
}

delete in; // close memory file handle

Expand Down
9 changes: 4 additions & 5 deletions lib/smmorphsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ MorphSource::save (OutFile& out_file)
bool
MorphSource::load (InFile& ifile)
{
bool read_ok = true;
while (ifile.event() != InFile::END_OF_FILE)
{
if (ifile.event() == InFile::STRING)
Expand All @@ -79,18 +80,16 @@ MorphSource::load (InFile& ifile)
}
else
{
g_printerr ("bad string\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

MorphOperator::OutputType
Expand Down
12 changes: 5 additions & 7 deletions lib/smmorphwavsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ MorphWavSource::save (OutFile& out_file)
bool
MorphWavSource::load (InFile& ifile)
{
bool read_ok = true;
while (ifile.event() != InFile::END_OF_FILE)
{
if (read_property_event (ifile))
Expand All @@ -198,8 +199,7 @@ MorphWavSource::load (InFile& ifile)
}
else
{
g_printerr ("bad int\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else if (ifile.event() == InFile::STRING)
Expand All @@ -214,18 +214,16 @@ MorphWavSource::load (InFile& ifile)
}
else
{
g_printerr ("bad string\n");
return false;
report_bad_event (read_ok, ifile);
}
}
else
{
g_printerr ("bad event\n");
return false;
report_bad_event (read_ok, ifile);
}
ifile.next_event();
}
return true;
return read_ok;
}

MorphOperator::OutputType
Expand Down

0 comments on commit eed337b

Please sign in to comment.