Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Sep 24, 2024
1 parent f99bc38 commit c3f2fe9
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ jobs:
- name: Build with tests
run: cmake --build with_tests --config Release

- name: Test on Unix
if: matrix.os != 'windows-latest'
- name: Test on Ubuntu (TODO add MacOS)
if: matrix.os == 'ubuntu-24.04'
run: cd with_tests; QT_QPA_PLATFORM=offscreen ctest --build-config Release --verbose

- name: Test on Windows
Expand Down
1 change: 0 additions & 1 deletion include/justly/justly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void JUSTLY_EXPORT set_editor(const QAbstractItemView *table_view_pointer,
const QVariant &new_value);

void JUSTLY_EXPORT undo(const SongEditor *song_editor_pointer);
void JUSTLY_EXPORT redo(const SongEditor *song_editor_pointer);

void JUSTLY_EXPORT trigger_insert_after(const SongEditor *song_editor_pointer);
void JUSTLY_EXPORT trigger_insert_into(const SongEditor *song_editor_pointer);
Expand Down
10 changes: 0 additions & 10 deletions src/chord/ChordsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,6 @@ auto ChordsModel::setData(const QModelIndex &index, const QVariant &new_value,
return true;
}

void insert_chord(ChordsModel *chords_model_pointer, qsizetype chord_number,
const Chord &new_chord) {
Q_ASSERT(chords_model_pointer != nullptr);
auto &chords = chords_model_pointer->chords;

chords_model_pointer->begin_insert_rows(chord_number, 1);
chords.insert(chords.begin() + static_cast<int>(chord_number), new_chord);
chords_model_pointer->end_insert_rows();
}

void insert_chords(ChordsModel &chords_model, qsizetype first_chord_number,
const QList<Chord> &new_chords) {
auto &chords = chords_model.chords;
Expand Down
11 changes: 5 additions & 6 deletions src/note/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ void json_to_notes(QList<Note> &new_notes, const nlohmann::json &json_notes,
std::back_inserter(new_notes),
[](const nlohmann::json &json_note) -> Note {
Note note;
if (json_note.contains("instrument")) {
const auto &instrument_value = json_note["instrument"];
Q_ASSERT(instrument_value.is_string());
note.instrument_pointer = get_instrument_pointer(
QString::fromStdString(instrument_value.get<std::string>()));
}
Q_ASSERT(json_note.contains("instrument"));
const auto &instrument_value = json_note["instrument"];
Q_ASSERT(instrument_value.is_string());
note.instrument_pointer = get_instrument_pointer(
QString::fromStdString(instrument_value.get<std::string>()));
if (json_note.contains("interval")) {
note.interval = json_to_interval(json_note["interval"]);
}
Expand Down
4 changes: 1 addition & 3 deletions src/note/NotesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ NotesModel::NotesModel(ChordsModel *parent_chords_model_pointer_input,
}

auto NotesModel::rowCount(const QModelIndex & /*parent_index*/) const -> int {
if (notes_pointer == nullptr) {
return 0;
}
Q_ASSERT(notes_pointer != nullptr);
return static_cast<int>(notes_pointer->size());
}

Expand Down
6 changes: 0 additions & 6 deletions src/note/SetNotesCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ static void replace_note_cells(NotesModel& notes_model,
qsizetype first_note_number, NoteColumn left_column,
NoteColumn right_column,
const QList<Note> &new_notes) {
qInfo("here");
qInfo() << "left column" << left_column;
qInfo() << "right column" << right_column;
auto *notes_pointer = notes_model.notes_pointer;
Q_ASSERT(notes_pointer != nullptr);
auto number_of_notes = new_notes.size();
Expand All @@ -26,14 +23,11 @@ static void replace_note_cells(NotesModel& notes_model,
const auto &new_note = new_notes.at(replace_number);
for (auto note_column = left_column; note_column <= right_column;
note_column = static_cast<NoteColumn>(note_column + 1)) {
qInfo("here");
qInfo() << "column" << note_column;
switch (note_column) {
case note_instrument_column:
note.instrument_pointer = new_note.instrument_pointer;
break;
case note_interval_column:
qInfo() << QVariant::fromValue(new_note.interval).toString();
note.interval = new_note.interval;
break;
case note_beats_column:
Expand Down
3 changes: 1 addition & 2 deletions src/other/ItemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <QAbstractItemModel>
#include <QList>
#include <QObject>
#include <Qt>
#include <QtGlobal>

Expand Down Expand Up @@ -43,7 +42,7 @@ auto ItemModel::is_column_editable(int /*column_number*/) const -> bool {
void ItemModel::edited_cells(qsizetype first_row_number,
qsizetype number_of_rows, int left_column,
int right_column) {
emit dataChanged(
dataChanged(
index(first_row_number, left_column),
index(first_row_number + number_of_rows - 1, right_column),
{Qt::DisplayRole, Qt::EditRole});
Expand Down
36 changes: 21 additions & 15 deletions src/other/justly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QAbstractItemDelegate>
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QAction>
#include <QMetaObject>
#include <QMetaProperty> // IWYU pragma: keep
Expand All @@ -19,6 +20,7 @@
#include "chord/ChordsModel.hpp"
#include "instrument/Instrument.hpp"
#include "interval/Interval.hpp"
#include "justly/ChordColumn.hpp"
#include "note/NotesModel.hpp"
#include "percussion/PercussionsModel.hpp"
#include "percussion_instrument/PercussionInstrument.hpp"
Expand Down Expand Up @@ -96,28 +98,37 @@ auto get_table_view_pointer(const SongEditor *song_editor_pointer)
return song_editor_pointer->table_view_pointer;
}

auto get_chords_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel * {
auto get_chords_model_pointer(const SongEditor *song_editor_pointer)
-> QAbstractItemModel * {
Q_ASSERT(song_editor_pointer != nullptr);
return song_editor_pointer->chords_model_pointer;
};

auto get_notes_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel * {
auto get_notes_model_pointer(const SongEditor *song_editor_pointer)
-> QAbstractItemModel * {
Q_ASSERT(song_editor_pointer != nullptr);
return song_editor_pointer->notes_model_pointer;
};

auto get_percussions_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel * {
auto get_percussions_model_pointer(const SongEditor *song_editor_pointer)
-> QAbstractItemModel * {
return song_editor_pointer->percussions_model_pointer;
};

void trigger_edit_notes(SongEditor *song_editor_pointer, qsizetype chord_number) {
void trigger_edit_notes(SongEditor *song_editor_pointer,
qsizetype chord_number) {
Q_ASSERT(song_editor_pointer != nullptr);
song_editor_pointer->trigger_edit_notes(chord_number);
song_editor_pointer->table_view_pointer->doubleClicked(
song_editor_pointer->chords_model_pointer->index(chord_number,
chord_notes_column));
};

void trigger_edit_percussions(SongEditor *song_editor_pointer, qsizetype chord_number) {
void trigger_edit_percussions(SongEditor *song_editor_pointer,
qsizetype chord_number) {
Q_ASSERT(song_editor_pointer != nullptr);
song_editor_pointer->trigger_edit_percussions(chord_number);
song_editor_pointer->table_view_pointer->doubleClicked(
song_editor_pointer->chords_model_pointer->index(
chord_number, chord_percussions_column));
};

void trigger_back_to_chords(const SongEditor *song_editor_pointer) {
Expand Down Expand Up @@ -203,22 +214,17 @@ void set_editor(const QAbstractItemView *table_view_pointer,
cell_editor_pointer->setProperty(
cell_editor_meta_object->userProperty().name(), new_value);

auto *delegate_pointer =
table_view_pointer->itemDelegate();
auto *delegate_pointer = table_view_pointer->itemDelegate();
Q_ASSERT(delegate_pointer != nullptr);

delegate_pointer->setModelData(
cell_editor_pointer, table_view_pointer->model(), index);
delegate_pointer->setModelData(cell_editor_pointer,
table_view_pointer->model(), index);
}

void undo(const SongEditor *song_editor_pointer) {
Q_ASSERT(song_editor_pointer != nullptr);
song_editor_pointer->undo_stack_pointer->undo();
};
void redo(const SongEditor *song_editor_pointer) {
Q_ASSERT(song_editor_pointer != nullptr);
song_editor_pointer->undo_stack_pointer->redo();
};

void trigger_insert_after(const SongEditor *song_editor_pointer) {
Q_ASSERT(song_editor_pointer != nullptr);
Expand Down
26 changes: 12 additions & 14 deletions src/percussion/Percussion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,18 @@ void json_to_percussions(QList<Percussion> &new_percussions,
std::back_inserter(new_percussions),
[](const nlohmann::json &json_percussion) -> Percussion {
Percussion percussion;
if (json_percussion.contains("set")) {
const auto &percussion_set_value = json_percussion["set"];
Q_ASSERT(percussion_set_value.is_string());
percussion.percussion_set_pointer = get_percussion_set_pointer(
QString::fromStdString(percussion_set_value.get<std::string>()));
}
if (json_percussion.contains("instrument")) {
const auto &instrument_value =
json_percussion["instrument"];
Q_ASSERT(instrument_value.is_string());
percussion.percussion_instrument_pointer =
get_percussion_instrument_pointer(
QString::fromStdString(instrument_value.get<std::string>()));
}
Q_ASSERT(json_percussion.contains("set"));
const auto &percussion_set_value = json_percussion["set"];
Q_ASSERT(percussion_set_value.is_string());
percussion.percussion_set_pointer = get_percussion_set_pointer(
QString::fromStdString(percussion_set_value.get<std::string>()));
Q_ASSERT(json_percussion.contains("instrument"));
const auto &instrument_value =
json_percussion["instrument"];
Q_ASSERT(instrument_value.is_string());
percussion.percussion_instrument_pointer =
get_percussion_instrument_pointer(
QString::fromStdString(instrument_value.get<std::string>()));
if (json_percussion.contains("beats")) {
percussion.beats = json_to_rational(json_percussion["beats"]);
}
Expand Down
4 changes: 1 addition & 3 deletions src/percussion/PercussionsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ PercussionsModel::PercussionsModel(QUndoStack *undo_stack_pointer_input,

auto PercussionsModel::rowCount(const QModelIndex & /*parent_index*/) const
-> int {
if (percussions_pointer == nullptr) {
return 0;
}
Q_ASSERT(percussions_pointer != nullptr);
return static_cast<int>(percussions_pointer->size());
}

Expand Down
46 changes: 20 additions & 26 deletions src/song/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ SongEditor::SongEditor(QWidget *parent_pointer, Qt::WindowFlags flags)
play_action_pointer(new QAction(tr("&Play selection"), this)),
stop_playing_action_pointer(new QAction(tr("&Stop playing"), this)),
save_action_pointer(new QAction(tr("&Save"), this)),
open_action_pointer(new QAction(tr("&Open"), this)),
settings_pointer(get_settings_pointer()),
event_pointer(new_fluid_event()),
sequencer_pointer(new_fluid_sequencer2(0)),
Expand Down Expand Up @@ -348,8 +349,7 @@ SongEditor::SongEditor(QWidget *parent_pointer, Qt::WindowFlags flags)
auto *file_menu_pointer =
std::make_unique<QMenu>(tr("&File"), this).release();

auto *open_action_pointer =
std::make_unique<QAction>(tr("&Open"), file_menu_pointer).release();

file_menu_pointer->addAction(open_action_pointer);
connect(open_action_pointer, &QAction::triggered, this, [this]() {
if (undo_stack_pointer->isClean() || verify_discard_changes()) {
Expand Down Expand Up @@ -774,13 +774,16 @@ SongEditor::SongEditor(QWidget *parent_pointer, Qt::WindowFlags flags)

connect(table_view_pointer, &QAbstractItemView::doubleClicked, this,
[this](const QModelIndex &index) {
Q_ASSERT(current_model_type == chords_type);
auto row = index.row();
auto column = index.column();
if (column == chord_notes_column) {
trigger_edit_notes(row);
} else if (column == chord_percussions_column) {
trigger_edit_percussions(row);
if (current_model_type == chords_type) {
auto row = index.row();
auto column = index.column();
if (column == chord_notes_column) {
undo_stack_pointer->push(
std::make_unique<EditNotes>(this, row).release());
} else if (column == chord_percussions_column) {
undo_stack_pointer->push(
std::make_unique<EditPercussions>(this, row).release());
}
}
});

Expand Down Expand Up @@ -854,14 +857,9 @@ void SongEditor::set_model(QAbstractItemModel *model_pointer) const {
update_actions();
}

void SongEditor::trigger_edit_notes(qsizetype chord_number) {
undo_stack_pointer->push(
std::make_unique<EditNotes>(this, chord_number).release());
}

void SongEditor::trigger_edit_percussions(qsizetype chord_number) {
undo_stack_pointer->push(
std::make_unique<EditPercussions>(this, chord_number).release());
void SongEditor::is_chords_now(bool is_chords) const {
back_to_chords_action_pointer->setEnabled(!is_chords);
open_action_pointer->setEnabled(is_chords);
}

void SongEditor::edit_notes(qsizetype chord_number) {
Expand All @@ -874,7 +872,7 @@ void SongEditor::edit_notes(qsizetype chord_number) {
notes_model_pointer->parent_chord_number = chord_number;
notes_model_pointer->end_reset_model();
current_model_type = notes_type;
back_to_chords_action_pointer->setEnabled(true);
is_chords_now(false);
set_model(notes_model_pointer);
}

Expand All @@ -887,7 +885,7 @@ void SongEditor::edit_percussions(qsizetype chord_number) {
&chords_model_pointer->chords[chord_number].percussions;
percussions_model_pointer->end_reset_model();
current_model_type = percussion_type;
back_to_chords_action_pointer->setEnabled(true);
is_chords_now(false);
set_model(percussions_model_pointer);
}

Expand All @@ -899,7 +897,7 @@ void SongEditor::notes_to_chords() {
notes_model_pointer->end_reset_model();
current_model_type = chords_type;
current_chord_number = -1;
back_to_chords_action_pointer->setEnabled(false);
is_chords_now(true);
}

void SongEditor::percussions_to_chords() {
Expand All @@ -909,7 +907,7 @@ void SongEditor::percussions_to_chords() {
percussions_model_pointer->end_reset_model();
current_model_type = chords_type;
current_chord_number = -1;
back_to_chords_action_pointer->setEnabled(false);
is_chords_now(true);
}

void SongEditor::back_to_chords() {
Expand Down Expand Up @@ -1090,7 +1088,7 @@ void SongEditor::start_real_time() {
fluid_settings_setstr(settings_pointer, "audio.driver", "pulseaudio");
#else
fluid_settings_setstr(settings_pointer, "audio.driver",
default_driver.c_str());
default_driver.toStdString().c_str());
#endif

#ifndef NO_REALTIME_AUDIO
Expand Down Expand Up @@ -1404,10 +1402,6 @@ void SongEditor::open_file(const QString &filename) {
get_json_double(json_song, "starting_tempo"));
}

if (current_model_type != chords_type) {
back_to_chords();
}

const auto &chords = chords_model_pointer->chords;
if (!chords.empty()) {
Q_ASSERT(chords_model_pointer != nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/song/SongEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct SongEditor : public QMainWindow {

// io actions
QAction *const save_action_pointer;
QAction *const open_action_pointer;

// fluidsynth fields
fluid_settings_t *const settings_pointer;
Expand Down Expand Up @@ -119,9 +120,8 @@ struct SongEditor : public QMainWindow {
// mode methods
void connect_model(const QAbstractItemModel *model_pointer) const;
void set_model(QAbstractItemModel *model_pointer) const;
void trigger_edit_notes(qsizetype chord_number);
void edit_notes(qsizetype chord_number);
void trigger_edit_percussions(qsizetype chord_number);
void is_chords_now(bool is_chords) const;
void edit_percussions(qsizetype chord_number);
void notes_to_chords();
void percussions_to_chords();
Expand Down
Loading

0 comments on commit c3f2fe9

Please sign in to comment.