Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Sep 23, 2024
1 parent 6051e02 commit f99bc38
Show file tree
Hide file tree
Showing 19 changed files with 1,244 additions and 1,538 deletions.
22 changes: 14 additions & 8 deletions include/justly/justly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include <QString>
#include <QVariant>

#include "justly/JUSTLY_EXPORT.hpp"

struct SongEditor;
class QAbstractItemModel;
class QModelIndex;
class QTableView;
class QAbstractItemView;
class QWidget;

void JUSTLY_EXPORT register_converters();
Expand All @@ -18,12 +18,17 @@ void JUSTLY_EXPORT show_song_editor(SongEditor *song_editor_pointer);
void JUSTLY_EXPORT delete_song_editor(SongEditor *song_editor_pointer);

[[nodiscard]] auto JUSTLY_EXPORT
get_table_view_pointer(const SongEditor *song_editor_pointer) -> QTableView *;

void JUSTLY_EXPORT trigger_edit_notes(const SongEditor *song_editor_pointer, qsizetype chord_number);
get_table_view_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemView *;

void JUSTLY_EXPORT trigger_edit_percussions(const SongEditor *song_editor_pointer, qsizetype chord_number);
[[nodiscard]] auto JUSTLY_EXPORT
get_chords_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel *;
[[nodiscard]] auto JUSTLY_EXPORT
get_notes_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel *;
[[nodiscard]] auto JUSTLY_EXPORT
get_percussions_model_pointer(const SongEditor *song_editor_pointer) -> QAbstractItemModel *;

void JUSTLY_EXPORT trigger_edit_notes(SongEditor *song_editor_pointer, qsizetype chord_number);
void JUSTLY_EXPORT trigger_edit_percussions(SongEditor *song_editor_pointer, qsizetype chord_number);
void JUSTLY_EXPORT trigger_back_to_chords(const SongEditor *song_editor_pointer);

[[nodiscard]] auto JUSTLY_EXPORT get_gain(const SongEditor *song_editor_pointer)
Expand All @@ -48,8 +53,8 @@ void JUSTLY_EXPORT set_starting_tempo(const SongEditor *song_editor_pointer,
double new_value);

[[nodiscard]] auto JUSTLY_EXPORT create_editor(
const SongEditor *song_editor_pointer, QModelIndex index) -> QWidget *;
void JUSTLY_EXPORT set_editor(const SongEditor *song_editor_pointer,
const QAbstractItemView *table_view_pointer,QModelIndex index) -> QWidget *;
void JUSTLY_EXPORT set_editor(const QAbstractItemView *table_view_pointer,
QWidget *cell_editor_pointer, QModelIndex index,
const QVariant &new_value);

Expand All @@ -59,6 +64,7 @@ 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);
void JUSTLY_EXPORT trigger_delete(const SongEditor *song_editor_pointer);
void JUSTLY_EXPORT trigger_remove_rows(const SongEditor *song_editor_pointer);

void JUSTLY_EXPORT trigger_cut(const SongEditor *song_editor_pointer);
void JUSTLY_EXPORT trigger_copy(const SongEditor *song_editor_pointer);
Expand Down
132 changes: 60 additions & 72 deletions src/chord/ChordsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ static const auto CONCERT_A_MIDI = 69;

static const auto C_0_MIDI = 12;

static const auto C_SCALE = 0;
static const auto C_SHARP_SCALE = 1;
static const auto D_SCALE = 2;
static const auto E_FLAT_SCALE = 3;
static const auto E_SCALE = 4;
static const auto F_SCALE = 5;
static const auto F_SHARP_SCALE = 6;
static const auto G_SCALE = 7;
static const auto A_FLAT_SCALE = 8;
static const auto A_SCALE = 9;
static const auto B_FLAT_SCALE = 10;
static const auto B_SCALE = 11;
enum Degree {
c_degree = 0,
c_sharp_degree = 1,
d_degree = 2,
e_flat_degree = 3,
e_degree = 4,
f_degree = 5,
f_sharp_degree = 6,
g_degree = 7,
a_flat_degree = 8,
a_degree = 9,
b_flat_degree = 10,
b_degree = 11
};

[[nodiscard]] static auto
get_chord_column(const QModelIndex &index) -> ChordColumn {
Expand Down Expand Up @@ -87,11 +89,8 @@ auto ChordsModel::columnCount(const QModelIndex & /*parent_index*/) const
return NUMBER_OF_CHORD_COLUMNS;
}

auto ChordsModel::headerData(int column, Qt::Orientation orientation,
int role) const -> QVariant {
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
switch (to_chord_column(column)) {
auto ChordsModel::get_column_name(int column_number) const -> QString {
switch (to_chord_column(column_number)) {
case chord_interval_column:
return ChordsModel::tr("Interval");
case chord_beats_column:
Expand All @@ -107,23 +106,10 @@ auto ChordsModel::headerData(int column, Qt::Orientation orientation,
case chord_percussions_column:
return ChordsModel::tr("Percussions");
}
}
if (orientation == Qt::Vertical) {
return column + 1;
}
}
// no horizontal headers
// no headers for other roles
return {};
}

Check warning on line 109 in src/chord/ChordsModel.cpp

View workflow job for this annotation

GitHub Actions / main_job (ubuntu-24.04)

control reaches end of non-void function [-Wreturn-type]

Check warning on line 109 in src/chord/ChordsModel.cpp

View workflow job for this annotation

GitHub Actions / main_job (ubuntu-24.04)

control reaches end of non-void function [-Wreturn-type]

auto ChordsModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
auto chord_column = get_chord_column(index);
if (chord_column == chord_notes_column ||
chord_notes_column == chord_percussions_column) {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
auto ChordsModel::is_column_editable(int column_number) const -> bool {
return column_number != chord_notes_column && column_number != chord_percussions_column;
}

auto get_key_text(const ChordsModel &chords_model, qsizetype last_chord_number,
Expand All @@ -140,84 +126,86 @@ auto get_key_text(const ChordsModel &chords_model, qsizetype last_chord_number,
auto difference_from_c = closest_midi - C_0_MIDI;
auto octave =
static_cast<int>(floor(difference_from_c / HALFSTEPS_PER_OCTAVE));
auto scale =
auto degree =
static_cast<int>(difference_from_c - octave * HALFSTEPS_PER_OCTAVE);
auto cents =
static_cast<int>(round((midi_float - closest_midi) * CENTS_PER_HALFSTEP));
QString scale_text;
switch (scale) {
case C_SCALE:
Q_ASSERT(degree >= 0);
Q_ASSERT(degree <= 11);
switch (static_cast<Degree>(degree)) {
case c_degree:
scale_text = "C";
break;
case C_SHARP_SCALE:
case c_sharp_degree:
scale_text = "C♯";
break;
case D_SCALE:
case d_degree:
scale_text = "D";
break;
case E_FLAT_SCALE:
case e_flat_degree:
scale_text = "E♭";
break;
case E_SCALE:
case e_degree:
scale_text = "E";
break;
case F_SCALE:
case f_degree:
scale_text = "F";
break;
case F_SHARP_SCALE:
case f_sharp_degree:
scale_text = "F♯";
break;
case G_SCALE:
case g_degree:
scale_text = "G";
break;
case A_FLAT_SCALE:
case a_flat_degree:
scale_text = "A♭";
break;
case A_SCALE:
case a_degree:
scale_text = "A";
break;
case B_FLAT_SCALE:
case b_flat_degree:
scale_text = "B♭";
break;
case B_SCALE:
case b_degree:
scale_text = "B";
break;
default:
Q_ASSERT(false);
}
QString result;
QTextStream stream(&result);
stream << key << " Hz; " << scale_text << octave << " "
<< (cents >= 0 ? "+" : "") << " " << abs(cents) << " cents";
stream << key << " Hz; " << scale_text << octave;
if (cents != 0) {
stream << " " << (cents >= 0 ? "+" : "") << " " << abs(cents) << " cents";
}
return result;
}

auto ChordsModel::data(const QModelIndex &index, int role) const -> QVariant {
Q_ASSERT(index.isValid());
auto child_number = get_child_number(index);
auto row_number = get_row_number(index);
if (role == Qt::StatusTipRole) {
return get_key_text(*this, child_number);
return get_key_text(*this, row_number);
}
if (role != Qt::DisplayRole && role != Qt::EditRole) {
return {};
}
if (role == Qt::DisplayRole || role == Qt::EditRole) {
const auto &chord = chords.at(child_number);
switch (get_chord_column(index)) {
case chord_interval_column:
return QVariant::fromValue(chord.interval);
case chord_beats_column:
return QVariant::fromValue(chord.beats);
case chord_velocity_ratio_column:
return QVariant::fromValue(chord.velocity_ratio);
case chord_tempo_ratio_column:
return QVariant::fromValue(chord.tempo_ratio);
case chord_words_column:
return chord.words;
case chord_notes_column:
return chord.notes.size();
case chord_percussions_column:
return chord.percussions.size();
}
const auto &chord = chords.at(row_number);
switch (get_chord_column(index)) {
case chord_interval_column:
return QVariant::fromValue(chord.interval);
case chord_beats_column:
return QVariant::fromValue(chord.beats);
case chord_velocity_ratio_column:
return QVariant::fromValue(chord.velocity_ratio);
case chord_tempo_ratio_column:
return QVariant::fromValue(chord.tempo_ratio);
case chord_words_column:
return chord.words;
case chord_notes_column:
return chord.notes.size();
case chord_percussions_column:
return chord.percussions.size();
}
return {};
}

Check warning on line 209 in src/chord/ChordsModel.cpp

View workflow job for this annotation

GitHub Actions / main_job (ubuntu-24.04)

control reaches end of non-void function [-Wreturn-type]

Check warning on line 209 in src/chord/ChordsModel.cpp

View workflow job for this annotation

GitHub Actions / main_job (ubuntu-24.04)

control reaches end of non-void function [-Wreturn-type]

auto ChordsModel::setData(const QModelIndex &index, const QVariant &new_value,
Expand All @@ -226,7 +214,7 @@ auto ChordsModel::setData(const QModelIndex &index, const QVariant &new_value,
if (role != Qt::EditRole) {
return false;
}
auto chord_number = get_child_number(index);
auto chord_number = get_row_number(index);
const auto &chord = chords.at(chord_number);
switch (get_chord_column(index)) {
case chord_interval_column:
Expand Down
7 changes: 2 additions & 5 deletions src/chord/ChordsModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <QList>
#include <QString>
#include <QVariant>
#include <Qt>
#include <QtGlobal>

#include "chord/Chord.hpp"
Expand Down Expand Up @@ -36,10 +35,8 @@ struct ChordsModel : public ItemModel {
[[nodiscard]] auto
columnCount(const QModelIndex & /*parent_index*/) const -> int override;

[[nodiscard]] auto headerData(int column, Qt::Orientation orientation,
int role) const -> QVariant override;
[[nodiscard]] auto
flags(const QModelIndex &index) const -> Qt::ItemFlags override;
[[nodiscard]] auto get_column_name(int column_number) const -> QString override;
[[nodiscard]] auto is_column_editable(int column_number) const -> bool override;
[[nodiscard]] auto data(const QModelIndex &index,
int role) const -> QVariant override;
[[nodiscard]] auto setData(const QModelIndex &index,
Expand Down
2 changes: 1 addition & 1 deletion src/interval/Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ auto Interval::operator==(const Interval &other_interval) const -> bool {

auto interval_is_default(const Interval &interval) -> bool {
return interval.numerator == 1 && interval.denominator == 1 &&
interval.octave != 0;
interval.octave == 0;
}

auto interval_to_double(const Interval &interval) -> double {
Expand Down
Loading

0 comments on commit f99bc38

Please sign in to comment.