diff options
Diffstat (limited to 'src/project.cc')
-rw-r--r-- | src/project.cc | 218 |
1 files changed, 205 insertions, 13 deletions
diff --git a/src/project.cc b/src/project.cc index 5ad809b..86100bc 100644 --- a/src/project.cc +++ b/src/project.cc @@ -30,6 +30,82 @@ #include <iostream> +AudioFile::AudioFile(Instrument& instrument, int id) + : id(id) + , instrument(instrument) +{ +} + +int AudioFile::getId() const +{ + return id; +} + +QString AudioFile::getFile() const +{ + return file; +} + +void AudioFile::setFile(const QString& file) +{ + if(this->file == file) + { + return; + } + + { + Project::RAIIBulkUpdate bulkUpdate(instrument.getProject()); + this->file = file; + } +} + +QString AudioFile::getAbsoluteFile() const +{ + if(file.left(1) != "/") + { + // Prepend root path + return instrument.getProject().getRawFileRoot() + "/" + file; + } + + return file; +} + +QString AudioFile::getName() const +{ + return name; +} + +void AudioFile::setName(const QString& name) +{ + if(this->name == name) + { + return; + } + + { + Project::RAIIBulkUpdate bulkUpdate(instrument.getProject()); + this->name = name; + } +} + +int AudioFile::getChannelMapId() const +{ + return channel_map_id; +} + +void AudioFile::setChannelMapId(int channel_map_id) +{ + if(this->channel_map_id == channel_map_id) + { + return; + } + + { + Project::RAIIBulkUpdate bulkUpdate(instrument.getProject()); + this->channel_map_id = channel_map_id; + } +} + Instrument::Instrument(Project& project, int id) : id(id) , project(project) @@ -81,22 +157,53 @@ void Instrument::setMasterFile(const QString& master_file) } } -AudioFileList Instrument::getFileList() const +AudioFile& Instrument::getAudioFile(int id) +{ + for(auto& audio_file : audio_files) + { + if(audio_file.getId() == id) + { + return audio_file; + } + } + + Q_ASSERT(false); // No such audio_file id. +} + +int Instrument::createAudioFile() { - return file_list; + Project::RAIIBulkUpdate bulkUpdate(project); + + audio_files.emplace_back(*this, project.next_id); + ++project.next_id; + + return audio_files.back().getId(); } -void Instrument::setFileList(const AudioFileList& file_list) +void Instrument::deleteAudioFile(int id) { - if(this->file_list == file_list) + Project::RAIIBulkUpdate bulkUpdate(project); + + for(auto it = audio_files.begin(); it != audio_files.end(); ++it) { - return; + if((*it).getId() == id) + { + audio_files.erase(it); + return; + } } + Q_ASSERT(false); // No such audio_file id. +} + +QList<int> Instrument::getAudioFileList() const +{ + QList<int> audio_file_list; + for(auto& audio_file : audio_files) { - Project::RAIIBulkUpdate bulkUpdate(project); - this->file_list = file_list; + audio_file_list.push_back(audio_file.getId()); } + return audio_file_list; } std::size_t Instrument::getAttackLength() const @@ -238,29 +345,46 @@ void Instrument::setPrefix(const QString& prefix) } } -QString Instrument::getExportPath() const +Project& Instrument::getProject() { - return export_path; + return project; } -void Instrument::setExportPath(const QString& export_path) +Channel::Channel(Project& project, int id) + : id(id) + , project(project) { - if(this->export_path == export_path) +} + +int Channel::getId() const +{ + return id; +} + +QString Channel::getChannelName() const +{ + return channel_name; +} + +void Channel::setChannelName(const QString& channel_name) +{ + if(this->channel_name == channel_name) { return; } { Project::RAIIBulkUpdate bulkUpdate(project); - this->export_path = export_path; + this->channel_name = channel_name; } } -Project& Instrument::getProject() +Project& Channel::getProject() { return project; } + void Project::bulkUpdateBegin() { ++update_count; @@ -323,6 +447,24 @@ void Project::setRawFileRoot(const QString& raw_file_root) } } +QString Project::getExportPath() const +{ + return export_path; +} + +void Project::setExportPath(const QString& export_path) +{ + if(this->export_path == export_path) + { + return; + } + + { + Project::RAIIBulkUpdate bulkUpdate(*this); + this->export_path = export_path; + } +} + Instrument& Project::getInstrument(int id) { for(auto& instrument : instruments) @@ -372,11 +514,61 @@ QList<int> Project::getInstrumentList() const return instrument_list; } +Channel& Project::getChannel(int id) +{ + for(auto& channel : channels) + { + if(channel.getId() == id) + { + return channel; + } + } + + Q_ASSERT(false); // No such channel id. +} + +int Project::createChannel() +{ + RAIIBulkUpdate bulkUpdate(*this); + + channels.emplace_back(*this, next_id); + ++next_id; + + return channels.back().getId(); +} + +void Project::deleteChannel(int id) +{ + RAIIBulkUpdate bulkUpdate(*this); + + for(auto it = channels.begin(); it != channels.end(); ++it) + { + if((*it).getId() == id) + { + channels.erase(it); + return; + } + } + + Q_ASSERT(false); // No such channel id. +} + +QList<int> Project::getChannelList() const +{ + QList<int> channel_list; + for(auto& channel : channels) + { + channel_list.push_back(channel.getId()); + } + return channel_list; +} + void Project::reset() { RAIIBulkUpdate bulkUpdate(*this); setRawFileRoot(""); setProjectName(""); instruments.clear(); + channels.clear(); next_id = 0; } |