Skip to content

Commit

Permalink
beats inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Nov 9, 2024
1 parent b6f69f0 commit 1d47a72
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/named/Named.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "named/Named.hpp"

Named::Named(const char* name_input) : name(name_input) {

}
Named::Named(const char *name_input) : name(name_input) {}
5 changes: 3 additions & 2 deletions src/row/InsertRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ struct InsertRow : public QUndoCommand {
const int row_number;
const SubRow new_row;

InsertRow(RowsModel<SubRow> &rows_model_input, int row_number_input)
InsertRow(RowsModel<SubRow> &rows_model_input, int row_number_input,
SubRow new_row_input)
: rows_model(rows_model_input), row_number(row_number_input),
new_row(SubRow()){};
new_row(std::move(new_row_input)){};

void undo() override { rows_model.remove_rows(row_number, 1); };
void redo() override { rows_model.insert_row(row_number, new_row); };
Expand Down
30 changes: 21 additions & 9 deletions src/song/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ add_set_cells(QUndoStack &undo_stack, RowsModel<SubRow> &rows_model,

template <std::derived_from<Row> SubRow>
static void add_insert_row(QUndoStack &undo_stack,
RowsModel<SubRow> &rows_model, int row_number) {
RowsModel<SubRow> &rows_model, int row_number,
const SubRow &new_row) {
undo_stack.push(
new InsertRow<SubRow>( // NOLINT(cppcoreguidelines-owning-memory)
rows_model, row_number));
rows_model, row_number, new_row));
}

template <std::derived_from<Row> SubRow>
Expand Down Expand Up @@ -257,7 +258,8 @@ make_file_dialog(SongEditor &song_editor, const QString &caption,
}

template <std::derived_from<Row> SubRow>
[[nodiscard]] static auto get_rows(RowsModel<SubRow> &rows_model) -> QList<SubRow> & {
[[nodiscard]] static auto
get_rows(RowsModel<SubRow> &rows_model) -> QList<SubRow> & {
return get_reference(rows_model.rows_pointer);
};

Expand Down Expand Up @@ -598,11 +600,21 @@ static void insert_model_row(SongEditor &song_editor, int row_number) {
const auto current_model_type = song_editor.current_model_type;
auto &undo_stack = song_editor.undo_stack;
if (current_model_type == chords_type) {
add_insert_row(undo_stack, song_editor.chords_model, row_number);
} else if (current_model_type == pitched_notes_type) {
add_insert_row(undo_stack, song_editor.pitched_notes_model, row_number);
add_insert_row(undo_stack, song_editor.chords_model, row_number, Chord());
} else {
add_insert_row(undo_stack, song_editor.unpitched_notes_model, row_number);
const auto &chord_beats =
song_editor.song.chords[song_editor.current_chord_number].beats;
if (current_model_type == pitched_notes_type) {
PitchedNote new_pitched_note;
new_pitched_note.beats = chord_beats;
add_insert_row(undo_stack, song_editor.pitched_notes_model, row_number,
new_pitched_note);
} else {
UnpitchedNote new_unpitched_note;
new_unpitched_note.beats = chord_beats;
add_insert_row(undo_stack, song_editor.unpitched_notes_model, row_number,
new_unpitched_note);
}
}
}

Expand Down Expand Up @@ -889,10 +901,10 @@ SongEditor::SongEditor()
modulate(player, chord);
if (current_model_type == pitched_notes_type) {
play_notes(player, current_chord_number, chord.pitched_notes,
first_row_number, number_of_rows);
first_row_number, number_of_rows);
} else {
play_notes(player, current_chord_number, chord.unpitched_notes,
first_row_number, number_of_rows);
first_row_number, number_of_rows);
}
}
});
Expand Down

0 comments on commit 1d47a72

Please sign in to comment.