X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=midi_mapper.cpp;h=392fac4b82b89b7570fa736f4b5566bff935752d;hb=cf729d2ddd503b90413987bf94a928ae31efe0d0;hp=27e843ee33e7b2f2cfb02a3a6ed68656e8884d53;hpb=afe996bc7dfc8689ca356d00824fbfcd632f93a2;p=nageru diff --git a/midi_mapper.cpp b/midi_mapper.cpp index 27e843e..392fac4 100644 --- a/midi_mapper.cpp +++ b/midi_mapper.cpp @@ -64,6 +64,26 @@ bool load_midi_mapping_from_file(const string &filename, MIDIMappingProto *new_m return true; } +bool save_midi_mapping_to_file(const MIDIMappingProto &mapping_proto, const string &filename) +{ + // Save to disk. We use the text format because it's friendlier + // for a user to look at and edit. + int fd = open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0666); + if (fd == -1) { + perror(filename.c_str()); + return false; + } + io::FileOutputStream output(fd); // Takes ownership of fd. + if (!TextFormat::Print(mapping_proto, &output)) { + // TODO: Don't overwrite the old file (if any) on error. + output.Close(); + return false; + } + + output.Close(); + return true; +} + void MIDIMapper::set_midi_mapping(const MIDIMappingProto &new_mapping) { lock_guard lock(mapping_mu);