rename ggwave-gui -> waver

This commit is contained in:
Georgi Gerganov
2021-01-05 18:56:29 +02:00
parent ecf4fd02ad
commit d29bf6d0e8
12 changed files with 25 additions and 25 deletions

View File

@@ -0,0 +1,15 @@
add_executable(waver main.cpp common.cpp interface.cpp interface-unix.cpp)
target_include_directories(waver PRIVATE
..
${SDL2_INCLUDE_DIRS}
)
target_link_libraries(waver PRIVATE
ggwave
ggwave-common
ggwave-common-sdl2
ggsock
imgui-sdl2
${CMAKE_THREAD_LIBS_INIT}
)

8
examples/waver/README.md Normal file
View File

@@ -0,0 +1,8 @@
# waver
Simple GUI program using `ggwave`. The UI is the same as in the `Waver: Data Over Sound` mobile applications.
<a href="https://youtu.be/KWlcgZHJhGQ"><img src="../../media/waver-0-fast.gif"></a>
<a href="https://apps.apple.com/us/app/waver-data-over-sound/id1543607865?itsct=apps_box&amp;itscg=30200&ign-itsct=apps_box#?platform=iphone" style="display: inline-block; overflow: hidden; border-radius: 13px; width: 250px; height: 83px;"><img height="60px" src="https://tools.applemediaservices.com/api/badges/download-on-the-app-store/white/en-US?size=250x83&amp;releaseDate=1607558400&h=8e5fafc57929918f684abc83ff8311ef" alt="Download on the App Store"></a>
<a href='https://play.google.com/store/apps/details?id=com.ggerganov.Waver&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'><img alt='Get it on Google Play' src='https://i.imgur.com/BKDCbKv.png' height="60px"/></a>

1487
examples/waver/common.cpp Normal file

File diff suppressed because it is too large Load Diff

75
examples/waver/common.h Normal file
View File

@@ -0,0 +1,75 @@
#pragma once
#include "ggwave-common-sdl2.h"
#include <thread>
#include <vector>
std::thread initMain();
void renderMain();
void deinitMain(std::thread & worker);
// share info
struct ShareInfo {
std::string uri;
std::string filename;
const char * dataBuffer;
size_t dataSize;
};
int getShareId();
ShareInfo getShareInfo();
// open info
struct OpenInfo {
std::string uri;
std::string filename;
const char * dataBuffer;
size_t dataSize;
};
int getOpenId();
OpenInfo getOpenInfo();
// delete file
struct DeleteInfo {
std::string uri;
std::string filename;
};
int getDeleteId();
DeleteInfo getDeleteInfo();
// receive
struct ReceiveInfo {
const char * uri;
const char * filename;
const char * dataBuffer;
size_t dataSize;
};
int getReceivedId();
std::vector<ReceiveInfo> getReceiveInfos();
bool confirmReceive(const char * uri);
// input
void clearAllFiles();
void clearFile(const char * uri);
void addFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize,
bool focus);
void addFile(
const char * uri,
const char * filename,
std::vector<char> && data,
bool focus);

View File

@@ -0,0 +1,56 @@
#include "interface.h"
#include "pfd/pfd.h"
#include <fstream>
void interface_addFile(
const char * ,
const char * ,
const char * ,
size_t ) {
}
void interface_loadAllFiles() {
}
void interface_shareFile(
const char * ,
const char * filename,
const char * dataBuffer,
size_t dataSize) {
auto f = pfd::save_file("Save file", filename, { "All Files", "*" }, pfd::opt::none);
if (f.result().empty() == false) {
printf("Saving to: %s\n", f.result().c_str());
std::ofstream fout(f.result(), std::ios::binary);
if (fout.is_open() && fout.good()) {
fout.write(dataBuffer, dataSize);
fout.close();
}
}
}
void interface_openFile(
const char * ,
const char * ,
const char * ,
size_t ) {
}
void interface_deleteFile(
const char * ,
const char * ) {
}
void interface_receiveFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize) {
addFile(uri, filename, dataBuffer, dataSize, false);
}
bool interface_needReloadFiles() {
return false;
}

View File

@@ -0,0 +1,73 @@
#include "interface.h"
int g_lastShareId = 0;
int g_lastOpenId = 0;
int g_lastDeleteId = 0;
int g_lastReceivedId = 0;
int g_frameCount = 0;
void updateMain() {
auto curShareId = getShareId();
if (curShareId != g_lastShareId) {
auto shareInfo = getShareInfo();
interface_shareFile(
shareInfo.uri.data(),
shareInfo.filename.data(),
shareInfo.dataBuffer,
shareInfo.dataSize);
g_lastShareId = curShareId;
}
auto curOpenId = getOpenId();
if (curOpenId != g_lastOpenId) {
auto openInfo = getOpenInfo();
interface_openFile(
openInfo.uri.data(),
openInfo.filename.data(),
openInfo.dataBuffer,
openInfo.dataSize);
g_lastOpenId = curOpenId;
}
auto curDeleteId = getDeleteId();
if (curDeleteId != g_lastDeleteId) {
auto deleteInfo = getDeleteInfo();
interface_deleteFile(deleteInfo.uri.c_str(), deleteInfo.filename.c_str());
bool isRemoveAll = std::string(deleteInfo.uri) == "###ALL-FILES###";
if (interface_needReloadFiles() || isRemoveAll) {
clearAllFiles();
interface_loadAllFiles();
} else {
clearFile(deleteInfo.uri.c_str());
}
g_lastDeleteId = curDeleteId;
}
auto curReceivedId = getReceivedId();
if (curReceivedId != g_lastReceivedId) {
auto receiveInfos = getReceiveInfos();
int n = (int) receiveInfos.size();
for (int i = 0; i < n; ++i) {
interface_receiveFile(
receiveInfos[i].uri,
receiveInfos[i].filename,
receiveInfos[i].dataBuffer,
receiveInfos[i].dataSize);
confirmReceive(receiveInfos[i].uri);
}
if (interface_needReloadFiles()) {
clearAllFiles();
interface_loadAllFiles();
}
g_lastReceivedId = curReceivedId;
}
}

View File

@@ -0,0 +1,48 @@
#ifndef interface_h
#define interface_h
#ifdef __cplusplus
#include "common.h"
extern "C" {
#endif
void interface_addFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize);
void interface_loadAllFiles();
void interface_shareFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize);
void interface_openFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize);
void interface_deleteFile(
const char * uri,
const char * filename);
void interface_receiveFile(
const char * uri,
const char * filename,
const char * dataBuffer,
size_t dataSize);
bool interface_needReloadFiles();
void updateMain();
#ifdef __cplusplus
}
#endif
#endif /* interface_h */

225
examples/waver/main.cpp Normal file
View File

@@ -0,0 +1,225 @@
#include "interface.h"
#include "ggwave-common.h"
#include <imgui-extra/imgui_impl.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <fstream>
#include <vector>
#include <iterator>
std::vector<char> readFile(const char* filename) {
std::ifstream file(filename, std::ios::binary);
file.unsetf(std::ios::skipws);
std::streampos fileSize;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<char> vec;
vec.reserve(fileSize);
vec.insert(vec.begin(),
std::istream_iterator<char>(file),
std::istream_iterator<char>());
return vec;
}
// ImGui helpers
bool ImGui_BeginFrame(SDL_Window * window) {
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ProcessEvent(&event);
if (event.type == SDL_QUIT) return false;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) return false;
if (event.type == SDL_DROPFILE) {
printf("Dropped file: '%s'\n", event.drop.file);
auto data = readFile(event.drop.file);
std::string uri = event.drop.file;
std::string filename = event.drop.file;
if (uri.find("/") || uri.find("\\")) {
filename = uri.substr(uri.find_last_of("/\\") + 1);
}
addFile(uri.c_str(), filename.c_str(), std::move(data), true);
break;
}
}
ImGui_NewFrame(window);
return true;
}
bool ImGui_EndFrame(SDL_Window * window) {
// Rendering
int display_w, display_h;
SDL_GetWindowSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.0f, 0.0f, 0.0f, 0.4f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
ImGui_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
return true;
}
bool ImGui_SetStyle() {
ImGuiStyle & style = ImGui::GetStyle();
style.AntiAliasedFill = false;
style.AntiAliasedLines = false;
style.WindowRounding = 0.0f;
style.WindowPadding = ImVec2(8, 8);
style.WindowRounding = 0.0f;
style.FramePadding = ImVec2(4, 3);
style.FrameRounding = 0.0f;
style.ItemSpacing = ImVec2(8, 4);
style.ItemInnerSpacing = ImVec2(4, 4);
style.IndentSpacing = 21.0f;
style.ScrollbarSize = 16.0f;
style.ScrollbarRounding = 9.0f;
style.GrabMinSize = 10.0f;
style.GrabRounding = 3.0f;
style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.41f, 0.41f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
//style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
style.Colors[ImGuiCol_Border] = ImVec4(0.31f, 0.31f, 0.31f, 0.71f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.39f, 0.39f, 0.39f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.50f, 0.50f, 0.70f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.27f, 0.27f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f);
//style.Colors[ImGuiCol_ComboBg] = ImVec4(0.00f, 0.39f, 0.39f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(0.13f, 0.55f, 0.55f, 1.00f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.61f, 1.00f, 0.00f, 0.51f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(0.79f, 0.51f, 0.00f, 0.51f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f);
//style.Colors[ImGuiCol_Column] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f);
//style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
//style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f);
//style.Colors[ImGuiCol_CloseButton] = ImVec4(0.40f, 0.39f, 0.38f, 0.16f);
//style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f);
//style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f);
style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.78f);
return true;
}
int main(int argc, char** argv) {
auto argm = parseCmdArguments(argc, argv);
int captureId = argm["c"].empty() ? 0 : std::stoi(argm["c"]);
int playbackId = argm["p"].empty() ? 0 : std::stoi(argm["p"]);
if (GGWave_init(playbackId, captureId) == false) {
fprintf(stderr, "Failed to initialize GGWave\n");
return -1;
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
fprintf(stderr, "Error: %s\n", SDL_GetError());
return -1;
}
ImGui_PreInit();
int windowX = 400;
int windowY = 600;
// Waver video settings
//float scale = 0.65;
//int windowX = scale*570;
//int windowY = scale*917;
const char * windowTitle = "Waver";
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window * window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowX, windowY, window_flags);
void * gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
ImGui_Init(window, gl_context);
ImGui_SetStyle();
ImGui::GetIO().Fonts->AddFontFromFileTTF("../examples/assets/fonts/DroidSans.ttf", 14.0f);
static ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
ImFontConfig config;
config.MergeMode = true;
config.GlyphOffset = { 0.0f, 0.0f };
ImGui::GetIO().Fonts->AddFontFromFileTTF("../examples/assets/fonts/fontawesome-webfont.ttf", 14.0f, &config, ranges);
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
ImGui_NewFrame(window);
ImGui::Render();
auto worker = initMain();
// tmp
//addFile("test0.raw", "test0.raw", std::vector<char>(1024));
//addFile("test1.jpg", "test0.jpg", std::vector<char>(1024*1024 + 624));
//addFile("test2.mpv", "test0.mov", std::vector<char>(1024*1024*234 + 53827));
while (true) {
if (ImGui_BeginFrame(window) == false) {
break;
}
renderMain();
updateMain();
ImGui_EndFrame(window);
}
deinitMain(worker);
GGWave_deinit();
// Cleanup
ImGui_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}