Browse Source

Sequencer: Save file to tmp file before overwriting original.

tags/non-daw-v1.3.0
Jonathan Moore Liles 3 years ago
parent
commit
1a07dda5d9
1 changed files with 45 additions and 27 deletions
  1. +45
    -27
      sequencer/src/sequence.C

+ 45
- 27
sequencer/src/sequence.C View File

@@ -371,51 +371,69 @@ sequence::load ( const char *name )
void
sequence::save ( const char *name ) const
{
smf f;
char *tmp = NULL;

/* open for writing */
f.open( name, smf::WRITE );
{
const char *filename = basename(name);
char *dir = (char*)malloc( (strlen(name) - strlen(filename)) + 1 );
strncpy( dir, name, strlen(name) - strlen(filename) );
asprintf( &tmp, "%s#%s", dir, filename );
free(dir);
}
{
smf f;

f.write_header( 2 );
/* open for writing */
f.open( tmp, smf::WRITE );

DMESSAGE( "saving playlist" );
f.write_header( 2 );

f.open_track( NULL, -1 );
DMESSAGE( "saving playlist" );

DMESSAGE( "saving song info" );
f.open_track( NULL, -1 );

f.write_song_info( song.play_mode, phrase::phrases(), pattern::patterns(), this->name(), notes() );
DMESSAGE( "saving song info" );

for ( int i = 0; i < _rd->num; ++i )
{
char pat[256];
f.write_song_info( song.play_mode, phrase::phrases(), pattern::patterns(), this->name(), notes() );

phrase *p = phrase::phrase_by_number( _rd->phrases[ i ] );
for ( int i = 0; i < _rd->num; ++i )
{
char pat[256];

snprintf( pat, 256, "%d: %s", p->number(), p->name() );
phrase *p = phrase::phrase_by_number( _rd->phrases[ i ] );

f.write_meta_event( smf::CUEPOINT, pat );
}
snprintf( pat, 256, "%d: %s", p->number(), p->name() );

f.close_track( 0 );
f.write_meta_event( smf::CUEPOINT, pat );
}

DMESSAGE( "saving phrases" );
f.close_track( 0 );

for ( int i = 0; i < phrase::phrases(); i++ )
{
phrase *p = phrase::phrase_by_number( i + 1 );
DMESSAGE( "saving phrases" );

p->dump( &f );
}
for ( int i = 0; i < phrase::phrases(); i++ )
{
phrase *p = phrase::phrase_by_number( i + 1 );

DMESSAGE( "saving patterns" );
p->dump( &f );
}

for ( int i = 0; i < pattern::patterns(); i++ )
{
pattern *p = pattern::pattern_by_number( i + 1 );
DMESSAGE( "saving patterns" );

p->dump( &f );
for ( int i = 0; i < pattern::patterns(); i++ )
{
pattern *p = pattern::pattern_by_number( i + 1 );

p->dump( &f );
}
}

rename(tmp,name);

free(tmp);
}




Loading…
Cancel
Save