Skip to content

Commit

Permalink
Some tidying up of the calchart sheets. (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpowell77 authored Jan 11, 2025
1 parent 0ec07d1 commit eb4c2f5
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 141 deletions.
4 changes: 2 additions & 2 deletions src/CalChartDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ auto CalChartDoc::GeneratePhatomPointsDrawCommands(
| std::views::transform([this, sheet](auto&& whichPosition) {
auto [which, position] = whichPosition;
// because points draw their position, we remove it then add the new position.
return sheet->GetPoint(which).GetDrawCommands(
return sheet->GetMarcher(which).GetDrawCommands(
GetPointLabel(which),
mConfig)
+ position
- sheet->GetPoint(which).GetPos();
- sheet->GetMarcher(which).GetPos();
})
| std::views::join;
return {
Expand Down
2 changes: 1 addition & 1 deletion src/CalChartDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ namespace {
{
// Print the field:
// create a field for drawing:
const auto pts = sheet.GetPoints();
const auto pts = sheet.GetAllMarchers();
auto boundingBox = GetMarcherBoundingBox(pts);
auto mode = show.GetShowMode().CreateFieldForPrinting(CalChart::CoordUnits2Int(boundingBox.first.x), CalChart::CoordUnits2Int(boundingBox.second.x), landscape);
auto drawCmds = CalChart::CreateModeDrawCommandsWithBorder(config, mode, CalChart::HowToDraw::Printing);
Expand Down
2 changes: 1 addition & 1 deletion src/core/CalChartAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ auto AnimateShow(const Show& show) -> Sheets
return CalChart::Animate::CreateCompileResult(
AnimationData{
static_cast<unsigned>(whichMarcher),
curr_sheet->GetPoint(whichMarcher),
curr_sheet->GetMarcher(whichMarcher),
endPosition,
numBeats,
isLastSheet },
Expand Down
6 changes: 3 additions & 3 deletions src/core/CalChartPrintShowToPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ namespace {
auto fmax = mode.FieldSize().x + fmin;

/* find bounds */
auto allX = sheet.GetAllPoints()
auto allX = sheet.GetAllMarchers()
| std::views::transform([](auto&& point) { return point.GetPos().x; });
auto [max_s, max_n] = std::accumulate(allX.begin(), allX.end(), std::pair<Coord::units, Coord::units>{ fmax, fmin }, [](auto acc, auto x) {
return std::pair<Coord::units, Coord::units>{ std::min(x, std::get<0>(acc)), std::max(x, std::get<1>(acc)) };
Expand Down Expand Up @@ -614,7 +614,7 @@ auto PrintShowToPS::GenerateStandard(Sheet const& sheet, bool split_sheet) const
+ std::format("/slinew {:.4f} def\n", dot_w * mSLineRatio)
+ std::format("/numberfont findfont {:.2f} scalefont setfont\n", dot_w * 2 * mNumRatio);

auto pointsOfInterest = CalChart::Ranges::enumerate_view(sheet.GetAllPoints())
auto pointsOfInterest = CalChart::Ranges::enumerate_view(sheet.GetAllMarchers())
| std::views::filter([clip_s = clip_s, clip_n = clip_n](auto&& enumPoint) {
return std::get<1>(enumPoint).GetPos().x >= clip_s && std::get<1>(enumPoint).GetPos().x <= clip_n;
});
Expand Down Expand Up @@ -651,7 +651,7 @@ auto PrintShowToPS::GenerateOverview(Sheet const& sheet) const -> std::string

auto fieldheight = CoordUnits2Float(fieldsize.y);

auto allBoxes = sheet.GetAllPoints()
auto allBoxes = sheet.GetAllMarchers()
| std::views::transform([](auto&& point) { return point.GetPos(); })
| std::views::transform([this, fieldoff, fieldwidth, fieldheight](auto&& position) {
return std::format("{:.2f} {:.2f} dotbox\n",
Expand Down
141 changes: 66 additions & 75 deletions src/core/CalChartSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

namespace CalChart {

std::string const contnames[MAX_NUM_SYMBOLS] = {
std::array<std::string, MAX_NUM_SYMBOLS> const contnames = {
"Plain", "Sol", "Bksl", "Sl", "X", "Solbksl", "Solsl", "Solx"
};

std::string const long_contnames[MAX_NUM_SYMBOLS] = {
std::array<std::string, MAX_NUM_SYMBOLS> const long_contnames = {
"Plain", "Solid", "Backslash", "Slash", "Crossed", "Solid Backslash", "Solid Slash", "Solid Crossed"
};

Expand All @@ -51,96 +51,99 @@ Sheet::Sheet(size_t numPoints)
{
}

Sheet::Sheet(size_t numPoints, std::string const& newname)
Sheet::Sheet(size_t numPoints, std::string name)
: mAnimationContinuity(MAX_NUM_SYMBOLS)
, mBeats(1)
, mPoints(numPoints)
, mName(newname)
, mName(std::move(name))
{
}

// -=-=-=-=-=- LEGACY CODE -=-=-=-=-=-
// Recommend that you don't touch this unless you know what you are doing.
bool are_equal_helper(std::string const& a, std::string const& b)
{
auto p = std::mismatch(a.begin(), a.end(), b.begin(), [](char c1, char c2) {
return std::tolower(c1) == std::tolower(c2);
});
return (p.first == a.end() && p.second == b.end());
}
namespace {
auto are_equal_helper(std::string const& a, std::string const& b) -> bool
{
auto p = std::mismatch(a.begin(), a.end(), b.begin(), [](char c1, char c2) {
return std::tolower(c1) == std::tolower(c2);
});
return (p.first == a.end() && p.second == b.end());
}

auto are_equal(std::string const& a, std::string const& b) -> bool
{
return a.size() <= b.size() ? are_equal_helper(a, b) : are_equal_helper(b, a);
}

bool are_equal(std::string const& a, std::string const& b)
{
return a.size() <= b.size() ? are_equal_helper(a, b) : are_equal_helper(b, a);
}

SYMBOL_TYPE GetSymbolForName(std::string const& name)
auto GetSymbolForName(std::string const& name) -> SYMBOL_TYPE
{
for (auto i = contnames;
i != (contnames + sizeof(contnames) / sizeof(contnames[0])); ++i) {

if (are_equal(name, *i)) {
return static_cast<SYMBOL_TYPE>(std::distance(contnames, i));
for (auto [index, symbolName] : CalChart::Ranges::enumerate_view(contnames)) {
if (are_equal(name, symbolName)) {
return static_cast<SYMBOL_TYPE>(index);
}
}
// what do we do here? give larger one for now...
// This should probably throw
return MAX_NUM_SYMBOLS;
}

std::string GetNameForSymbol(SYMBOL_TYPE which)
auto GetNameForSymbol(SYMBOL_TYPE which) -> std::string
{
if (which > MAX_NUM_SYMBOLS) {
return "";
}
return contnames[which];
}

std::string GetLongNameForSymbol(SYMBOL_TYPE which)
auto GetLongNameForSymbol(SYMBOL_TYPE which) -> std::string
{
if (which > MAX_NUM_SYMBOLS) {
return "";
}
return long_contnames[which];
}

static void
CheckInconsistancy(SYMBOL_TYPE symbol, uint8_t cont_index,
std::map<SYMBOL_TYPE, uint8_t>& continity_for_symbol,
std::map<uint8_t, SYMBOL_TYPE>& symbol_for_continuity,
std::string const& sheet_name, uint32_t pointNum)
{
// need to check for symbol inconsistency here.
if (continity_for_symbol.count(symbol) == 0) {
// we haven't seen this symbol->cont_index yet
continity_for_symbol[symbol] = cont_index;
} else {
if (continity_for_symbol[symbol] != cont_index) {
std::stringstream buf;
buf << "Error, symbol inconsistency on sheet \"" << sheet_name << "\".\n";
buf << "Symbol " << GetNameForSymbol(symbol)
<< " previously used continuity "
<< (uint32_t)continity_for_symbol[symbol] << " but point " << pointNum
<< " on uses continuity " << (uint32_t)cont_index
<< ", which is used by symbol "
<< GetNameForSymbol(symbol_for_continuity[cont_index]) << ".\n";
buf << "Try opening this file on CalChart v3.3.5 or earlier.\n";
throw CC_FileException(buf.str());
}
}
if (symbol_for_continuity.count(cont_index) == 0) {
symbol_for_continuity[cont_index] = symbol;
} else {
if (symbol_for_continuity[cont_index] != symbol) {
std::stringstream buf;
buf << "Error, symbol inconsistency on sheet \"" << sheet_name << "\".\n";
buf << "Continuity index " << (uint32_t)cont_index
<< " previously used symbol "
<< GetNameForSymbol(symbol_for_continuity[cont_index])
<< " but point " << pointNum << " on uses symbol "
<< GetNameForSymbol(symbol) << ".\n";
buf << "Try opening this file on CalChart v3.3.5 or earlier.\n";
throw CC_FileException(buf.str());
// -=-=-=-=-=- LEGACY CODE -=-=-=-=-=-
// Recommend that you don't touch this unless you know what you are doing.
namespace {
void
CheckInconsistancy(SYMBOL_TYPE symbol, uint8_t cont_index,
std::map<SYMBOL_TYPE, uint8_t>& continity_for_symbol,
std::map<uint8_t, SYMBOL_TYPE>& symbol_for_continuity,
std::string const& sheet_name, uint32_t pointNum)
{
// need to check for symbol inconsistency here.
if (continity_for_symbol.count(symbol) == 0) {
// we haven't seen this symbol->cont_index yet
continity_for_symbol[symbol] = cont_index;
} else {
if (continity_for_symbol[symbol] != cont_index) {
std::stringstream buf;
buf << "Error, symbol inconsistency on sheet \"" << sheet_name << "\".\n";
buf << "Symbol " << GetNameForSymbol(symbol)
<< " previously used continuity "
<< (uint32_t)continity_for_symbol[symbol] << " but point " << pointNum
<< " on uses continuity " << (uint32_t)cont_index
<< ", which is used by symbol "
<< GetNameForSymbol(symbol_for_continuity[cont_index]) << ".\n";
buf << "Try opening this file on CalChart v3.3.5 or earlier.\n";
throw CC_FileException(buf.str());
}
}
if (symbol_for_continuity.count(cont_index) == 0) {
symbol_for_continuity[cont_index] = symbol;
} else {
if (symbol_for_continuity[cont_index] != symbol) {
std::stringstream buf;
buf << "Error, symbol inconsistency on sheet \"" << sheet_name << "\".\n";
buf << "Continuity index " << (uint32_t)cont_index
<< " previously used symbol "
<< GetNameForSymbol(symbol_for_continuity[cont_index])
<< " but point " << pointNum << " on uses symbol "
<< GetNameForSymbol(symbol) << ".\n";
buf << "Try opening this file on CalChart v3.3.5 or earlier.\n";
throw CC_FileException(buf.str());
}
}
}
}
Expand Down Expand Up @@ -507,8 +510,6 @@ auto Sheet::SerializeSheet() const -> std::vector<std::byte>
return result;
}

Sheet::~Sheet() = default;

// Find point at certain coords
auto Sheet::FindMarcher(Coord where, Coord::units searchBound, unsigned ref) const -> std::optional<int>
{
Expand Down Expand Up @@ -602,10 +603,6 @@ std::string Sheet::GetRawPrintContinuity() const
return mPrintableContinuity.GetOriginalLine();
}

unsigned short Sheet::GetBeats() const { return mBeats; }

void Sheet::SetBeats(unsigned short b) { mBeats = b; }

// Get position of point
Coord Sheet::GetPosition(unsigned i, unsigned ref) const
{
Expand Down Expand Up @@ -646,19 +643,13 @@ Textline_list Sheet::GetPrintableContinuity() const
return mPrintableContinuity.GetChunks();
}

Point const& Sheet::GetPoint(unsigned i) const { return mPoints[i]; }

Point& Sheet::GetPoint(unsigned i) { return mPoints[i]; }

SYMBOL_TYPE Sheet::GetSymbol(unsigned i) const { return mPoints[i].GetSymbol(); }
auto Sheet::GetMarcher(unsigned i) const -> Point { return mPoints[i]; }

void Sheet::SetSymbol(unsigned i, SYMBOL_TYPE sym)
{
mPoints[i].SetSymbol(sym);
}

std::vector<Point> Sheet::GetPoints() const { return mPoints; }

std::vector<SYMBOL_TYPE> Sheet::GetSymbols() const
{
std::vector<SYMBOL_TYPE> result;
Expand Down Expand Up @@ -817,7 +808,7 @@ namespace {
// we want sheets to print in landscape when the width exceeds the height
auto Sheet::ShouldPrintLandscape() const -> bool
{
auto boundingBox = GetMarcherBoundingBox(GetPoints());
auto boundingBox = GetMarcherBoundingBox(GetAllMarchers());
return (boundingBox.second.x - boundingBox.first.x) > CalChart::Int2CoordUnits(CalChart::kFieldStepSizeNorthSouth[0]);
}

Expand Down
Loading

0 comments on commit eb4c2f5

Please sign in to comment.