From b56ed4c20106b8475813b9f02cbfcb3fb51f1714 Mon Sep 17 00:00:00 2001 From: starg Date: Wed, 24 Aug 2016 00:38:05 +0900 Subject: [PATCH] =?utf8?q?=E3=82=AA=E3=82=AF=E3=82=BF=E3=83=BC=E3=83=96?= =?utf8?q?=E6=8C=87=E5=AE=9A=E3=81=AE=E3=81=AA=E3=81=84=E9=9F=B3=E7=AC=A6?= =?utf8?q?=E3=81=AF=E5=90=8C=E3=81=98=E3=82=B9=E3=83=86=E3=83=BC=E3=83=88?= =?utf8?q?=E3=83=A1=E3=83=B3=E3=83=88=E5=86=85=E3=81=AE=E4=BB=A5=E5=89=8D?= =?utf8?q?=E3=81=AE=E6=8C=87=E5=AE=9A=E3=82=92=E5=BC=95=E3=81=8D=E7=B6=99?= =?utf8?q?=E3=81=90=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/message/id.hpp | 1 + src/ast2ir/phrase2ir.cpp | 28 +++++++++++++++++++++++++--- src/ast2ir/phrase2ir.hpp | 1 + src/driver/msgcallback.cpp | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/message/id.hpp b/include/message/id.hpp index e3f9b01..e8f02a9 100644 --- a/include/message/id.hpp +++ b/include/message/id.hpp @@ -21,6 +21,7 @@ enum class MessageID : int TrackNumberIsOutOfSafeRange, TrackNumberIsOutOfPreferredRange, TooLargeRepeatCount, + OctaveOutOfRange, // error_attribute.hpp GrammarAttributeArgument, diff --git a/src/ast2ir/phrase2ir.cpp b/src/ast2ir/phrase2ir.cpp index 312e598..cbed111 100644 --- a/src/ast2ir/phrase2ir.cpp +++ b/src/ast2ir/phrase2ir.cpp @@ -70,7 +70,7 @@ bool Phrase2IRCompiler::Compile(const AST::Phrase& ast, IR::BlockReference index AutoPop autoPop(m_AttributeStack); Compile(ast.Block, index); - return true; + return !HasErrors(); } catch (const Exceptions::MessageException& e) { @@ -96,6 +96,7 @@ bool Phrase2IRCompiler::Compile(const AST::Phrase& ast, IR::BlockReference index std::vector Phrase2IRCompiler::operator()(const AST::NoteSequenceStatement& ast) { m_DefaultDuration = TickPerQuarter; + m_DefaultOctave = 5; if (ast.Attributes.empty()) { @@ -108,7 +109,6 @@ std::vector Phrase2IRCompiler::operator()(const AST::NoteS m_AttributeStack.push_back(ast.Attributes); AutoPop autoPop(m_AttributeStack); - // with bounds checking m_IR.Blocks[newIndex.ID].Attributes = m_AttributeStack.back(); if (ast.NoteSeq.is_initialized()) @@ -227,11 +227,33 @@ std::vector Phrase2IRCompiler::operator()(const AST::Rest& std::vector Phrase2IRCompiler::operator()(const AST::NoteNumber& ast, int duration) { + if (ast.Octave.is_initialized()) + { + auto octave = ast.Octave.value(); + + if (0 <= octave.Value && octave.Value <= 10) + { + m_DefaultOctave = octave.Value; + } + else + { + AddMessage( + Message::MessageItem{ + Message::MessageKind::Error, + Message::MessageID::OctaveOutOfRange, + m_IR.Name, + octave.Location, + {std::to_string(octave.Value)} + } + ); + } + } + return { IR::Event{ m_RelativeTime, IR::Note{ - MIDI::NoteNumber(ast.Name.Name, ast.Name.Minor, ast.Octave.get_value_or(AST::NoteOctave{4, ast.Location}).Value), + MIDI::NoteNumber(ast.Name.Name, ast.Name.Minor, m_DefaultOctave), 100, duration, 100 diff --git a/src/ast2ir/phrase2ir.hpp b/src/ast2ir/phrase2ir.hpp index 06c44a8..c04b180 100644 --- a/src/ast2ir/phrase2ir.hpp +++ b/src/ast2ir/phrase2ir.hpp @@ -54,6 +54,7 @@ private: int m_RelativeTime = 0; int m_DefaultDuration; + int m_DefaultOctave; }; } // namespace AST2IR diff --git a/src/driver/msgcallback.cpp b/src/driver/msgcallback.cpp index bb996d5..4e48e30 100644 --- a/src/driver/msgcallback.cpp +++ b/src/driver/msgcallback.cpp @@ -42,6 +42,7 @@ MessagePrinter::MessagePrinter(IStdErrWriter* pStdErrWriter) {Message::MessageID::TrackNumberIsOutOfSafeRange, "track number '{0}' is out of range (must be 0 <= # < {1})"}, {Message::MessageID::TrackNumberIsOutOfPreferredRange, "track number '{0}' is out of range (must be 0 <= # < {1})"}, {Message::MessageID::TooLargeRepeatCount, "repeat count '{0}' is too large (must be <= {1})"}, + {Message::MessageID::OctaveOutOfRange, "octave value '{0}' is out of range (must be between 0 and 10)"}, // error_attribute.hpp {Message::MessageID::GrammarAttributeArgument, "parse error: GrammarAttributeArgument"}, -- 2.11.0