Small cleaning.

This commit is contained in:
James Grogan 2022-12-04 18:13:32 +00:00
parent 70220fc6e9
commit d7fe11913f
26 changed files with 613 additions and 548 deletions

View file

@ -18,9 +18,6 @@ public:
void openDevice(AudioDevice* device) override; void openDevice(AudioDevice* device) override;
void play(AudioDevice* device, AudioSample* sample, unsigned duration) override; void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;
private:
void openDevice(const AudioDevicePtr& device) override;
}; };
using NullAudioInterfacePtr = std::shared_ptr<NullAudioInterface>; using NullAudioInterfacePtr = std::shared_ptr<NullAudioInterface>;

View file

@ -2,6 +2,7 @@
#include "FileLogger.h" #include "FileLogger.h"
#include "AudioSynth.h" #include "AudioSynth.h"
#include "AudioDevice.h"
#include <vector> #include <vector>
#include <iostream> #include <iostream>
@ -26,37 +27,37 @@ std::unique_ptr<WasapiInterface> WasapiInterface::Create()
return std::make_unique<WasapiInterface>(); return std::make_unique<WasapiInterface>();
} }
void WasapiInterface::OpenDevice(const AudioDevicePtr& device) void WasapiInterface::openDevice(AudioDevice* device)
{ {
} }
void WasapiInterface::SetAccessType(const AudioDevicePtr& device) void WasapiInterface::setAccessType(AudioDevice* device)
{ {
} }
void WasapiInterface::SetSampleFormat(const AudioDevicePtr& device) void WasapiInterface::setSampleFormat(AudioDevice* device)
{ {
} }
void WasapiInterface::SetSampleRate(const AudioDevicePtr& device) void WasapiInterface::setSampleRate(AudioDevice* device)
{ {
} }
void WasapiInterface::SetPeriod(const AudioDevicePtr& device) void WasapiInterface::setPeriod(AudioDevice* device)
{ {
} }
void WasapiInterface::SetBufferSize(const AudioDevicePtr& device) void WasapiInterface::setBufferSize(AudioDevice* device)
{ {
} }
void WasapiInterface::SetChannelNumber(const AudioDevicePtr& device) void WasapiInterface::setChannelNumber(AudioDevice* device)
{ {
} }
@ -76,7 +77,7 @@ const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient); const IID IID_IAudioClient = __uuidof(IAudioClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient); const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
void WasapiInterface::Play(const AudioDevicePtr& device) void WasapiInterface::play(AudioDevice* device, AudioSample* sample, unsigned duration)
{ {
std::cout << "Into wasapi play" << std::endl; std::cout << "Into wasapi play" << std::endl;
IMMDeviceEnumerator* pEnumerator = nullptr; IMMDeviceEnumerator* pEnumerator = nullptr;

View file

@ -1,36 +1,35 @@
#pragma once #pragma once
#include "IAudioInterface.h" #include "IAudioInterface.h"
#include "AudioDevice.h"
#include <memory> #include <memory>
class AudioDevice;
class WasapiInterface : public IAudioInterface class WasapiInterface : public IAudioInterface
{ {
public: public:
WasapiInterface(); WasapiInterface();
~WasapiInterface(); ~WasapiInterface();
static std::unique_ptr<WasapiInterface> Create(); static std::unique_ptr<WasapiInterface> Create();
void OpenDevice(const AudioDevicePtr& device) override; void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;
private:
void openDevice(AudioDevice* device) override;
void SetAccessType(const AudioDevicePtr& device); void setAccessType(AudioDevice* device);
void SetSampleFormat(const AudioDevicePtr& device); void setSampleFormat(AudioDevice* device);
void SetSampleRate(const AudioDevicePtr& device); void setSampleRate(AudioDevice* device);
void SetPeriod(const AudioDevicePtr& device); void setPeriod(AudioDevice* device);
void SetBufferSize(const AudioDevicePtr& device); void setBufferSize(AudioDevice* device);
void SetChannelNumber(const AudioDevicePtr& device); void setChannelNumber(AudioDevice* device);
void Play(const AudioDevicePtr& device) override;
}; };
using AlsaInterfacePtr = std::shared_ptr<WasapiInterface>; using WasapiInterfacePtr = std::unique_ptr<WasapiInterface>;

View file

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
#include <bitset> #include <bitset>
int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType) int MidiChannelEventAdapter::readEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType)
{ {
int first_four_bits = 0xF0; int first_four_bits = 0xF0;
int second_four_bits = 0xF; int second_four_bits = 0xF;
@ -34,11 +34,11 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
{ {
if (isStatusByte) if (isStatusByte)
{ {
byteCount += ReadEventData(file, event); byteCount += readEventData(file, event);
} }
else else
{ {
byteCount += ReadEventData(file, event, firstByte); byteCount += readEventData(file, event, firstByte);
} }
break; break;
} }
@ -55,7 +55,7 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
return byteCount; return byteCount;
} }
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event, char c) int MidiChannelEventAdapter::readEventData(std::ifstream* file, MidiChannelEvent* event, char c)
{ {
int value0 = int(c); int value0 = int(c);
int value1 = *BinaryStream::getNextByteAsInt(file); int value1 = *BinaryStream::getNextByteAsInt(file);
@ -63,7 +63,7 @@ int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent
return 1; return 1;
} }
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event) int MidiChannelEventAdapter::readEventData(std::ifstream* file, MidiChannelEvent* event)
{ {
int value0 = *BinaryStream::getNextByteAsInt(file); int value0 = *BinaryStream::getNextByteAsInt(file);
int value1 = *BinaryStream::getNextByteAsInt(file); int value1 = *BinaryStream::getNextByteAsInt(file);

View file

@ -7,8 +7,8 @@
class MidiChannelEventAdapter class MidiChannelEventAdapter
{ {
public: public:
static int ReadEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType); static int readEvent(std::ifstream* file, char firstByte, MidiChannelEvent* event, MidiChannelEvent::Type& lastEventType);
static int ReadEventData(std::ifstream* file, MidiChannelEvent* event, char c); static int readEventData(std::ifstream* file, MidiChannelEvent* event, char c);
static int ReadEventData(std::ifstream* file, MidiChannelEvent* event); static int readEventData(std::ifstream* file, MidiChannelEvent* event);
}; };

View file

@ -3,11 +3,9 @@
#include "MetaMidiEvent.h" #include "MetaMidiEvent.h"
#include <fstream> #include <fstream>
class MidiMetaEventAdapter class MidiMetaEventAdapter
{ {
public: public:
static int ReadEvent(std::ifstream* file, MetaMidiEvent* event, int& lastMidiChannel); static int ReadEvent(std::ifstream* file, MetaMidiEvent* event, int& lastMidiChannel);
static int ReadIntEvent(std::ifstream* file, MetaMidiEvent* event, int length=-1); static int ReadIntEvent(std::ifstream* file, MetaMidiEvent* event, int length=-1);

View file

@ -87,7 +87,7 @@ int MidiReader::processEvent(MidiTrack* track)
auto event = std::make_unique<MidiChannelEvent>(); auto event = std::make_unique<MidiChannelEvent>();
event->SetTimeDelta(timeDelta); event->SetTimeDelta(timeDelta);
//std::cout << "Midi event" << std::endl; //std::cout << "Midi event" << std::endl;
byteCount += MidiChannelEventAdapter::ReadEvent(mFile->getInHandle(), c, event.get(), mLastChannelEventType); byteCount += MidiChannelEventAdapter::readEvent(mFile->getInHandle(), c, event.get(), mLastChannelEventType);
track->AddEvent(std::move(event)); track->AddEvent(std::move(event));
} }
return byteCount; return byteCount;

View file

@ -29,6 +29,11 @@ AbstractApp* GuiApplication::getMainApplication() const
return mMainApplication.get(); return mMainApplication.get();
} }
AbstractUIInterface* GuiApplication::getUiInterface() const
{
return mUiInterface.get();
}
void GuiApplication::initializeViews() void GuiApplication::initializeViews()
{ {
mDesktopManager->getWindowManager()->getMainWindow()->setSize(800, 600); mDesktopManager->getWindowManager()->getMainWindow()->setSize(800, 600);

View file

@ -21,10 +21,7 @@ public:
void run(); void run();
AbstractUIInterface* getUiInterface() const override AbstractUIInterface* getUiInterface() const override;
{
return mUiInterface.get();
}
void setUiInterfaceBackend(UiInterfaceFactory::Backend backend); void setUiInterfaceBackend(UiInterfaceFactory::Backend backend);

View file

@ -5,7 +5,6 @@
class StatusBar : public Widget class StatusBar : public Widget
{ {
public: public:
StatusBar(); StatusBar();
static std::unique_ptr<StatusBar> Create(); static std::unique_ptr<StatusBar> Create();

View file

@ -6,7 +6,6 @@
class TabbedPanelWidget : public Widget class TabbedPanelWidget : public Widget
{ {
public: public:
TabbedPanelWidget(); TabbedPanelWidget();

View file

@ -1,5 +1,7 @@
#include "TemplateFile.h" #include "TemplateFile.h"
#include "StringUtils.h"
#include <iostream> #include <iostream>
TemplateFile::TemplateFile(const Path& path) TemplateFile::TemplateFile(const Path& path)

View file

@ -0,0 +1,169 @@
#include "TemplateNodes.h"
#include "StringUtils.h"
TemplateNode::TemplateNode(TemplateNode* parent)
: mParent(parent)
{
}
TemplateNode* TemplateNode::getParent() const
{
return mParent;
}
void TemplateNode::addChild(std::unique_ptr<TemplateNode> child)
{
mChildren.push_back(std::move(child));
}
std::size_t TemplateNode::getNumChildren() const
{
return mChildren.size();
}
std::string TemplateNode::getIdentifier() const
{
return {};
}
TemplateNode* TemplateNode::getChild(std::size_t index) const
{
return mChildren[index].get();
}
std::string TemplateNode::getRawContent() const
{
std::string content;
for (const auto& child : mChildren)
{
content += child->getRawContent() + "\n";
}
return content;
}
void TemplateNode::setExtensionParent(TemplateNode* parent)
{
mExtensionParent = parent;
}
std::string TemplateNode::render(TemplateNode* parentContext)
{
if (!parentContext && mExtensionParent)
{
parentContext = mExtensionParent;
}
std::string content;
for (size_t idx = 0; idx < mChildren.size(); idx++)
{
content += mChildren[idx]->render(parentContext);
}
return content;
}
TemplateExtends::TemplateExtends(TemplateNode* parent, const std::string& path)
: TemplateNode(parent)
{
mPath = StringUtils::stripQuotes(path);
};
std::string TemplateExtends::getRawContent() const
{
return "TemplateExtends: " + mPath;
}
std::string TemplateExtends::getPath() const
{
return mPath;
}
TemplateBlock::TemplateBlock(TemplateNode* parent, const std::string& name)
: TemplateNode(parent),
mName(name)
{
}
void TemplateBlock::addLine(const std::string& line)
{
mBody.push_back(line);
}
std::string TemplateBlock::getRawContent() const
{
std::string content = "TemplateBlock: " + mName + "\n";
content += TemplateNode::getRawContent();
return content;
}
std::string TemplateBlock::renderAsParent(TemplateNode* base)
{
return {};
}
std::string TemplateBlock::render(TemplateNode* parentContext)
{
std::string content;
if (parentContext)
{
if (auto parent_node = parentContext->getFirstChildShallow<TemplateBlock>(getIdentifier()))
{
content = dynamic_cast<TemplateBlock*>(parent_node)->renderAsParent(this);
}
}
else
{
}
return content;
}
TemplateExpression::TemplateExpression(TemplateNode* parent, const std::string& content)
: TemplateNode(parent),
mContent(content)
{
}
std::string TemplateExpression::getRawContent() const
{
return "TemplateExpression: " + mContent;
}
TemplateTextBody::TemplateTextBody(TemplateNode* parent)
: TemplateNode(parent)
{
}
void TemplateTextBody::addLine(const std::string& content)
{
mContent.push_back(content);
}
bool TemplateTextBody::hasContent() const
{
return !mContent.empty();
}
std::string TemplateTextBody::render(TemplateNode* parentContext)
{
std::string content;
for (const auto& line : mContent)
{
content += line + '\n';
}
return content;
}
std::string TemplateTextBody::getRawContent() const
{
std::string content;
for (const auto& line : mContent)
{
content += "TemplateBody: " + line + "\n";
}
return content;
}

View file

@ -1,49 +1,27 @@
#pragma once #pragma once
#include <memory>
#include <string>
#include <vector>
class TemplateNode class TemplateNode
{ {
public: public:
TemplateNode(TemplateNode* parent);
TemplateNode(TemplateNode* parent) virtual ~TemplateNode() = default;
: mParent(parent)
{
} TemplateNode* getParent() const;
TemplateNode* getParent() const virtual void addChild(std::unique_ptr<TemplateNode> child);
{
return mParent;
}
virtual void addChild(std::unique_ptr<TemplateNode> child) std::size_t getNumChildren() const;
{
mChildren.push_back(std::move(child));
}
std::size_t getNumChildren() const virtual std::string getIdentifier() const;
{
return mChildren.size();
}
virtual std::string getIdentifier() const TemplateNode* getChild(std::size_t index) const;
{
return {};
}
TemplateNode* getChild(std::size_t index) const virtual std::string getRawContent() const;
{
return mChildren[index].get();
}
virtual std::string getRawContent() const
{
std::string content;
for (const auto& child : mChildren)
{
content += child->getRawContent() + "\n";
}
return content;
}
template<typename T> template<typename T>
T* getFirstChildShallow(const std::string& identifier = {}) const T* getFirstChildShallow(const std::string& identifier = {}) const
@ -68,25 +46,9 @@ public:
return nullptr; return nullptr;
} }
void setExtensionParent(TemplateNode* parent) void setExtensionParent(TemplateNode* parent);
{
mExtensionParent = parent;
}
virtual std::string render(TemplateNode* parentContext = nullptr) virtual std::string render(TemplateNode* parentContext = nullptr);
{
if (!parentContext && mExtensionParent)
{
parentContext = mExtensionParent;
}
std::string content;
for (size_t idx = 0; idx < mChildren.size(); idx++)
{
content += mChildren[idx]->render(parentContext);
}
return content;
}
protected: protected:
std::vector<std::unique_ptr<TemplateNode> > mChildren; std::vector<std::unique_ptr<TemplateNode> > mChildren;
@ -99,21 +61,12 @@ using TemplateNodePtr = std::unique_ptr<TemplateNode>;
class TemplateExtends : public TemplateNode class TemplateExtends : public TemplateNode
{ {
public: public:
TemplateExtends(TemplateNode* parent, const std::string& path) TemplateExtends(TemplateNode* parent, const std::string& path);
: TemplateNode(parent)
{
mPath = StringUtils::stripQuotes(path);
};
std::string getRawContent() const override virtual ~TemplateExtends() = default;
{
return "TemplateExtends: " + mPath;
}
std::string getPath() const std::string getRawContent() const override;
{ std::string getPath() const;
return mPath;
}
private: private:
std::string mPath; std::string mPath;
@ -122,46 +75,17 @@ private:
class TemplateBlock : public TemplateNode class TemplateBlock : public TemplateNode
{ {
public: public:
TemplateBlock(TemplateNode* parent, const std::string& name) TemplateBlock(TemplateNode* parent, const std::string& name);
: TemplateNode(parent),
mName(name)
{
} virtual ~TemplateBlock() = default;
void addLine(const std::string& line) void addLine(const std::string& line);
{
mBody.push_back(line);
}
std::string getRawContent() const override std::string getRawContent() const override;
{
std::string content = "TemplateBlock: " + mName + "\n";
content += TemplateNode::getRawContent();
return content;
}
std::string renderAsParent(TemplateNode* base) std::string renderAsParent(TemplateNode* base);
{
return {};
}
std::string render(TemplateNode* parentContext) override std::string render(TemplateNode* parentContext) override;
{
std::string content;
if (parentContext)
{
if (auto parent_node = parentContext->getFirstChildShallow<TemplateBlock>(getIdentifier()))
{
content = dynamic_cast<TemplateBlock*>(parent_node)->renderAsParent(this);
}
}
else
{
}
return content;
}
private: private:
std::string mName; std::string mName;
@ -171,17 +95,11 @@ private:
class TemplateExpression : public TemplateNode class TemplateExpression : public TemplateNode
{ {
public: public:
TemplateExpression(TemplateNode* parent, const std::string& content) TemplateExpression(TemplateNode* parent, const std::string& content);
: TemplateNode(parent),
mContent(content)
{
} virtual ~TemplateExpression() = default;
std::string getRawContent() const override std::string getRawContent() const override;
{
return "TemplateExpression: " + mContent;
}
private: private:
std::string mContent; std::string mContent;
@ -190,42 +108,17 @@ private:
class TemplateTextBody : public TemplateNode class TemplateTextBody : public TemplateNode
{ {
public: public:
TemplateTextBody(TemplateNode* parent) TemplateTextBody(TemplateNode* parent);
: TemplateNode(parent)
{
} virtual ~TemplateTextBody() = default;
void addLine(const std::string& content) void addLine(const std::string& content);
{
mContent.push_back(content);
}
bool hasContent() const std::string getRawContent() const override;
{
return !mContent.empty();
}
std::string render(TemplateNode* parentContext) override bool hasContent() const;
{
std::string content;
for (const auto& line : mContent)
{
content += line + '\n';
}
return content;
}
std::string getRawContent() const override
{
std::string content;
for (const auto& line : mContent)
{
content += "TemplateBody: " + line + "\n";
}
return content;
}
std::string render(TemplateNode* parentContext) override;
private: private:
std::vector<std::string> mContent; std::vector<std::string> mContent;
}; };

View file

@ -131,7 +131,7 @@ void File::close()
FileFormat::Format File::inferFormat() const FileFormat::Format File::inferFormat() const
{ {
const auto extension = getExtension(); const auto extension = getExtension();
return FileFormat::InferFormat(extension); return FileFormat::inferFormat(extension);
} }
void File::writeText(const std::string& text) void File::writeText(const std::string& text)

View file

@ -1,5 +1,7 @@
#include "FileFormats.h" #include "FileFormats.h"
#include "StringUtils.h"
FileFormat::ExtensionMap FileFormat::mExtensions = [] FileFormat::ExtensionMap FileFormat::mExtensions = []
{ {
ExtensionMap ret; ExtensionMap ret;
@ -8,3 +10,25 @@ FileFormat::ExtensionMap FileFormat::mExtensions = []
ret[Format::Wav] = ".wav"; ret[Format::Wav] = ".wav";
return ret; return ret;
}(); }();
bool FileFormat::isFormat(const std::string& extension, Format format)
{
return StringUtils::ToLower(extension) == mExtensions[format];
}
FileFormat::Format FileFormat::inferFormat(const std::string& query)
{
for(const auto& extension : mExtensions)
{
if(extension.second == query)
{
return extension.first;
}
}
return Format::Unknown;
}
std::string FileFormat::getExtension(Format format)
{
return mExtensions[format];
}

View file

@ -2,7 +2,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "StringUtils.h"
class FileFormat{ class FileFormat{
@ -27,31 +26,14 @@ public:
using ExtensionMap = std::map<Format, std::string>; using ExtensionMap = std::map<Format, std::string>;
public:
static bool isFormat(const std::string& extension, Format format);
static Format inferFormat(const std::string& query);
static std::string getExtension(Format format);
private: private:
static ExtensionMap mExtensions; static ExtensionMap mExtensions;
public:
bool IsFormat(const std::string& extension, Format format)
{
return StringUtils::ToLower(extension) == mExtensions[format];
}
static Format InferFormat(const std::string& query)
{
for(const auto& extension : mExtensions)
{
if(extension.second == query)
{
return extension.first;
}
}
return Format::Unknown;
}
std::string GetExtension(Format format)
{
return mExtensions[format];
}
}; };

View file

@ -4,9 +4,7 @@
class HttpResponse class HttpResponse
{ {
public: public:
HttpResponse(); HttpResponse();
~HttpResponse(); ~HttpResponse();

View file

@ -8,6 +8,7 @@
#include "ZlibEncoder.h" #include "ZlibEncoder.h"
#include "CyclicRedundancyChecker.h" #include "CyclicRedundancyChecker.h"
#include "StringUtils.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>

View file

@ -5,6 +5,7 @@
#include "BufferBitStream.h" #include "BufferBitStream.h"
#include "OutputBitStream.h" #include "OutputBitStream.h"
#include "ImageBitStream.h" #include "ImageBitStream.h"
#include "StringUtils.h"
#include "PngFilter.h" #include "PngFilter.h"
#include "Lz77Encoder.h" #include "Lz77Encoder.h"