Sync - Saving curve data
This commit is contained in:
parent
3cf9e5c3ac
commit
7105b7e7d1
3 changed files with 63 additions and 0 deletions
2
main.cc
2
main.cc
|
@ -209,6 +209,8 @@ void T_Main::makeUI( )
|
|||
if ( BeginMainMenuBar( ) ) {
|
||||
if ( BeginMenu( "File" ) ) {
|
||||
if ( MenuItem( "Save curves" , "C-s" , false , sync.curvesModified( ) ) ) {
|
||||
// FIXME: confirmation dialog if file changed
|
||||
sync.saveCurves( );
|
||||
}
|
||||
if ( MenuItem( "Reload curves" , "C-R" , false , sync.curvesModified( ) ) ) {
|
||||
// FIXME: confirmation dialog
|
||||
|
|
58
sync.cc
58
sync.cc
|
@ -190,6 +190,25 @@ void T_SyncTime::setDuration(
|
|||
}
|
||||
|
||||
|
||||
/*= T_SyncSegment ============================================================*/
|
||||
|
||||
M_LSHIFT_OP( T_StringBuilder , T_SyncSegment::E_SegmentType )
|
||||
{
|
||||
switch ( value ) {
|
||||
case T_SyncSegment::LINEAR:
|
||||
obj << "linear";
|
||||
break;
|
||||
case T_SyncSegment::RAMP:
|
||||
obj << "ramp";
|
||||
break;
|
||||
case T_SyncSegment::SMOOTH:
|
||||
obj << "smooth";
|
||||
break;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/*= T_SyncCurves =============================================================*/
|
||||
|
||||
int32_t T_SyncCurves::indexOf(
|
||||
|
@ -623,6 +642,10 @@ T_SyncCurve const* T_SyncManager::getCurve(
|
|||
|
||||
void T_SyncManager::curvesChanged_( )
|
||||
{
|
||||
if ( saving_ ) {
|
||||
saving_ = false;
|
||||
return;
|
||||
}
|
||||
if ( modified_ ) {
|
||||
fileChanged_ = true;
|
||||
} else {
|
||||
|
@ -682,6 +705,41 @@ bool T_SyncManager::loadCurves(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool T_SyncManager::saveCurves( )
|
||||
{
|
||||
T_StringBuilder sb;
|
||||
sb << "(duration " << time_.uDuration << ' ' << time_.iDuration
|
||||
<< ")\n";
|
||||
for ( auto const& curve : curves_.curves.values( ) ) {
|
||||
sb << "\n(" << curve.name << '\n';
|
||||
for ( auto const& s : curve.segments ) {
|
||||
sb << "\t(segment " << s.type << "\n\t\t(values";
|
||||
for ( auto v : s.values ) {
|
||||
sb << ' ' << v;
|
||||
}
|
||||
sb << ")\n\t\t(durations";
|
||||
for ( auto d : s.durations ) {
|
||||
sb << ' ' << d;
|
||||
}
|
||||
sb << ")\n\t)\n";
|
||||
}
|
||||
sb << ")\n";
|
||||
}
|
||||
|
||||
saving_ = true;
|
||||
printf( "Saving curves...\n" );
|
||||
try {
|
||||
T_File out{ "curves.srd" , E_FileMode::OVERWRITE };
|
||||
out.write( sb.data( ) , sb.size( ) );
|
||||
} catch ( ebcl::X_StreamError const& e ) {
|
||||
printf( "... ERR %s\n" , e.what( ) );
|
||||
return false;
|
||||
}
|
||||
printf( "... OK\n" );
|
||||
fileChanged_ = modified_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void T_SyncManager::addReloadUndoData_(
|
||||
void* const data ) const noexcept
|
||||
{
|
||||
|
|
3
sync.hh
3
sync.hh
|
@ -43,6 +43,7 @@ struct T_SyncSegment
|
|||
T_Array< float > values;
|
||||
T_Array< uint32_t > durations; // n(values) - 1 items
|
||||
};
|
||||
M_LSHIFT_OP( T_StringBuilder , T_SyncSegment::E_SegmentType );
|
||||
|
||||
// An input curve
|
||||
struct T_SyncCurve
|
||||
|
@ -358,6 +359,7 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
|||
{ return fileChanged_; }
|
||||
|
||||
bool loadCurves( bool undoable = true );
|
||||
bool saveCurves( );
|
||||
|
||||
private:
|
||||
void curvesChanged_( );
|
||||
|
@ -419,6 +421,7 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
|||
private:
|
||||
ebcl::T_SRDParserConfig pConfig_; // Parser config for curves
|
||||
T_WatchedFiles watcher_; // Curves file watcher
|
||||
bool saving_{ false }; // True if file is being saved
|
||||
bool modified_; // Locally modified
|
||||
bool fileChanged_; // File modified
|
||||
|
||||
|
|
Loading…
Reference in a new issue