diff --git a/main.cc b/main.cc index 4558b5c..4ac0054 100644 --- a/main.cc +++ b/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 diff --git a/sync.cc b/sync.cc index 8337752..2a4e0ec 100644 --- a/sync.cc +++ b/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 { diff --git a/sync.hh b/sync.hh index ebfe2a8..af3bfca 100644 --- a/sync.hh +++ b/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