Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,18 @@ struct EditorImpl : public Editor, public InputHandler {
// If the path is empty, ask a path from the user.
if (save_path.empty() || showSaveAsDialog) {
// Set the default filter index based on the save format.
// SDL doesn't support this currently.
int filterIndex;
switch (saveFmt) {
default:
case SIM_SM:
filterIndex = 1;
filterIndex = 0;
break;
case SIM_SSC:
filterIndex = 2;
filterIndex = 1;
break;
case SIM_OSU:
filterIndex = 3;
filterIndex = 2;
break;
};

Expand All @@ -608,13 +609,13 @@ struct EditorImpl : public Editor, public InputHandler {

// Update the save format based on the selected filter index.
switch (filterIndex) {
case 1:
case 0:
saveFmt = SIM_SM;
break;
case 2:
case 1:
saveFmt = SIM_SSC;
break;
case 3:
case 2:
saveFmt = SIM_OSU;
break;
default:
Expand Down
42 changes: 28 additions & 14 deletions src/Editor/LoadWav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace {
struct WaveHeader {
uint8_t chunkId[4]; // "RIFF"
uint32_t chunkSize;
uint8_t format[4]; // "WAVE"
uint8_t subchunk1Id[4]; // "fmt "
uint32_t subchunk1Size;
uint8_t format[4]; // "WAVE"
};
struct WaveFormat {
uint16_t audioFormat;
uint16_t numChannels;
uint32_t sampleRate;
Expand Down Expand Up @@ -65,22 +65,36 @@ SoundSource* LoadWav(std::ifstream&& file, std::string& title,
WaveHeader header;
file.read(reinterpret_cast<char*>(&header), sizeof(header));
if (file.fail() || memcmp(header.chunkId, "RIFF", 4) != 0 ||
memcmp(header.format, "WAVE", 4) != 0 ||
memcmp(header.subchunk1Id, "fmt ", 4) != 0 || header.audioFormat != 1 ||
header.sampleRate == 0 || header.numChannels == 0 ||
(header.bitsPerSample != 8 && header.bitsPerSample != 16 &&
header.bitsPerSample != 24)) {
memcmp(header.format, "WAVE", 4) != 0) {
return nullptr;
}

// Find format tag.
WaveData data;
while (true) {
file.read(reinterpret_cast<char*>(&data), sizeof(WaveData));
if (file.fail()) return nullptr;
if (memcmp(data.chunkId, "fmt ", 4) == 0) break;
file.ignore(data.chunkSize);
}

// Read format.
WaveFormat format;
file.read(reinterpret_cast<char*>(&format), sizeof(format));
if (file.fail() || format.audioFormat != 1 || format.sampleRate == 0 ||
format.numChannels == 0 ||
(format.bitsPerSample != 8 && format.bitsPerSample != 16 &&
format.bitsPerSample != 24)) {
return nullptr;
}

// Skip over additional parameters at the end of the format chunk.
if (header.subchunk1Size > 16) {
size_t extraBytes = static_cast<size_t>(header.subchunk1Size) - 16;
if (data.chunkSize > 16) {
size_t extraBytes = static_cast<size_t>(data.chunkSize) - 16;
file.ignore(extraBytes);
}

// Read the start of the data chunk.
WaveData data;
while (true) {
file.read(reinterpret_cast<char*>(&data), sizeof(WaveData));
if (file.fail()) return nullptr;
Expand All @@ -91,9 +105,9 @@ SoundSource* LoadWav(std::ifstream&& file, std::string& title,
// Create a wav loader that will read the contents of the data chunk.
WavLoader* loader = new WavLoader;

loader->frequency = header.sampleRate;
loader->numChannels = header.numChannels;
loader->bytesPerSample = header.bitsPerSample / 8;
loader->frequency = format.sampleRate;
loader->numChannels = format.numChannels;
loader->bytesPerSample = format.bitsPerSample / 8;
loader->numFrames =
data.chunkSize / (loader->bytesPerSample * loader->numChannels);
loader->numFramesLeft = loader->numFrames;
Expand Down
2 changes: 1 addition & 1 deletion src/Editor/Notefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ struct NotefieldImpl : public Notefield {
Renderer::resetColor();
Renderer::bindShader(Renderer::SH_COLOR);

bool zoomedIn = (gView->getScaleLevel() >= 2);
bool zoomedIn = (gView->getZoomLevel() >= 4);
int viewH = gView->getHeight();

// We keep track of the measure labels to render them afterwards.
Expand Down
4 changes: 3 additions & 1 deletion src/Editor/NotefieldPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ struct NotefieldPreviewImpl : public NotefieldPreview {
++measure;
row += it->rowsPerMeasure;
}
it = next, ++next;
it = next;
if (next == end) break;
++next;
}
batch.flush();
}
Expand Down
8 changes: 6 additions & 2 deletions src/Editor/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ struct SelectionImpl : public Selection {
if (keyFlags & (Keyflag::SHIFT | Keyflag::ALT)) {
Texture& tex =
(keyFlags & Keyflag::SHIFT) ? myAddIcon : mySubIcon;
Draw::sprite(tex, {start.x, start.y, mpos.x - start.x,
mpos.y - start.y});
Draw::sprite(
tex,
{start.x - static_cast<int>(8 * gSystem->getScaleFactor()),
start.y - static_cast<int>(8 * gSystem->getScaleFactor()),
static_cast<int>(16 * gSystem->getScaleFactor()),
static_cast<int>(16 * gSystem->getScaleFactor())});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Editor/TempoBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ struct TempoBoxesImpl : public TempoBoxes {
}

// Display detailed info of the mouse over box.
if (myMouseOverBox >= 0 && myShowHelp &&
!gSystem->isMouseDown(Mouse::LMB)) {
if (myMouseOverBox >= 0 && myMouseOverBox < myBoxes.size() &&
myShowHelp && !gSystem->isMouseDown(Mouse::LMB)) {
drawBoxHelp(myBoxes[myMouseOverBox]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Simfile/TimingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ static void Merge(std::vector<MergedTS>& out, const SegmentList& in) {
continue;
}

while (ins != insEnd && ins->row > read->seg->row) {
while (ins != insEnd && ins->row >= read->seg->row) {
write->type = in.type();
write->seg = ins.ptr;
--ins, --write;
}
if (ins == insEnd) break;

// Move existing segments.
while (read != readEnd && read->seg->row >= ins->row) {
while (read != readEnd && read->seg->row > ins->row) {
*write = *read;
--read;
if (read == readEnd) goto exit_loop;
--write;
if (read == readEnd) goto exit_loop;
}
}

Expand Down