Skip to content

Commit

Permalink
sync on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Nov 18, 2024
1 parent 164aade commit ab2e545
Show file tree
Hide file tree
Showing 39 changed files with 56 additions and 20 deletions.
Binary file modified FileWriter.o
Binary file not shown.
Binary file modified LockFreeQueue.o
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ engine.o: engine.cc engine.h snd.cc snd.h
$(CPP) engine.cc -c $(JACK) $(LV2) $(OPTIMIZE) $(SNDFILE) $(GTK)

clean:
rm -v *.o amprack
rm -v *.o

missing: SharedLibrary.o missing.cc
$(CPP) missing.cc SharedLibrary.o log.o -o missing -std=c++17 $(LV2) -I/usr/include/lv2 $(GTK) $(DLFCN)
Expand Down
Binary file modified Plugin.o
Binary file not shown.
Binary file modified PluginControl.o
Binary file not shown.
Binary file modified SharedLibrary.o
Binary file not shown.
Binary file added amprack
Binary file not shown.
Binary file modified amprack.exe
Binary file not shown.
Binary file modified cairo.o
Binary file not shown.
Binary file modified client.o
Binary file not shown.
Binary file modified dictionary.o
Binary file not shown.
Binary file modified engine.o
Binary file not shown.
Binary file modified jack.o
Binary file not shown.
Binary file modified knob.o
Binary file not shown.
Binary file modified log.o
Binary file not shown.
Binary file modified lv2_ext.o
Binary file not shown.
Binary file modified main.o
Binary file not shown.
Binary file modified mem.o
Binary file not shown.
Binary file modified objects.o
Binary file not shown.
Binary file modified pango.o
Binary file not shown.
Binary file modified pluginui.o
Binary file not shown.
5 changes: 5 additions & 0 deletions presets.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "presets.h"

std::string * Presets::presets_dir ;

void
change_value (
GtkSpinButton* self,
Expand Down Expand Up @@ -474,6 +476,7 @@ void Presets::load_user (bool isFav) {

for (const auto & entry : std::filesystem::directory_iterator(where)) {
//~ std::cout << entry.path() << std::endl;
LOGD ("[preset] %s\n", entry.path ().string ().c_str ());

json j = filename_to_json (entry.path ().string ());
if (! isFav)
Expand Down Expand Up @@ -533,6 +536,7 @@ void Presets::save_presets_to_json (std::string filename) {
}

json Presets::get_all_user_presets () {
IN
json ex = json {};
int i = 0 ;
for (const auto & entry : std::filesystem::directory_iterator(*presets_dir)) {
Expand All @@ -541,5 +545,6 @@ json Presets::get_all_user_presets () {
ex [std::to_string (i++)] = j ;
}

OUT
return ex ;
}
8 changes: 6 additions & 2 deletions presets.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Presets {
void add_preset_multi (std::string, int) ;
int import_presets_from_json (json);
void save_presets_to_json (std::string);
std::string dir, * presets_dir, favs_dir ;
std::string dir, favs_dir ;
static std::string * presets_dir ;
std::vector <json> * list_of_presets [4] ;
char * _pdir ;
void library_load () ;
Expand All @@ -65,11 +66,14 @@ class Presets {

# ifdef __linux__
presets_dir = new std::string (getenv ("HOME"));
presets_dir->append ("/amprack/presets/");
# else
presets_dir = new std::string (getenv ("USERPROFILE"));
presets_dir->append ("\\amprack\\presets\\");
# endif

presets_dir->append ("/amprack/presets/");
LOGD ("[presets dir] %s\n", presets_dir->c_str ());

_pdir = strdup (presets_dir->c_str ());

if (! g_file_test (dir.c_str (), G_FILE_TEST_IS_DIR)) {
Expand Down
Binary file modified presets.o
Binary file not shown.
Binary file modified process.o
Binary file not shown.
Binary file modified rack.o
Binary file not shown.
Binary file modified server.o
Binary file not shown.
Binary file modified settings.o
Binary file not shown.
Binary file modified snd.o
Binary file not shown.
15 changes: 10 additions & 5 deletions sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
void sync_send (Sync * sync) {
IN
std::string where = std::string (gtk_entry_buffer_get_text (gtk_entry_get_buffer ((sync -> entry))));
if (where.size () == 0) {
where = std::string ("localhost:6906");
}

int find1 = where.find (":") ;
int find2 = where.find (":", find1 + 1) - find1;

Expand All @@ -23,12 +27,13 @@ void sync_send (Sync * sync) {
LOGD ("[client] response: %s\n", response.c_str ());
LOGD ("ip: %s, port: %s, key: %s\n", ip.c_str(), port.c_str (), key.c_str ());

int how_many = p -> import_presets_from_json (j);
char * ss = g_strdup_printf ("<span foreground=\"green\" weight=\"bold\" size=\"x-large\">Imported %d presets successfully</span>", how_many);
gtk_label_set_markup (sync -> header, ss);
g_free (ss);
/// ayyo, importing what we already have!
//~ int how_many = p -> import_presets_from_json (j);
//~ char * ss = g_strdup_printf ("<span foreground=\"green\" weight=\"bold\" size=\"x-large\">Imported %d presets successfully</span>", how_many);
//~ gtk_label_set_markup (sync -> header, ss);
//~ g_free (ss);

LOGD ("[client] synced %d presets\n", how_many);
//~ LOGD ("[client] synced %d presets\n", how_many);
client -> close_socket ();
OUT
}
Expand Down
Binary file modified sync.o
Binary file not shown.
Binary file modified upwaker.o
Binary file not shown.
3 changes: 2 additions & 1 deletion util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
json filename_to_json (std::string filename) {
//~ IN
if (! std::filesystem::exists (filename)) {
HERE LOGD ("%s does not exist!\n", filename.c_str ());
filename = std::string ("/usr/share/amprack/").append (filename);
if (! std::filesystem::exists (filename)) {
HERE LOGD ("file does not exist! %s\n", filename.c_str ()) ;
// instead of null, empty json is better
return json {} ;
return json::parse ("{}");
}
}

Expand Down
Binary file modified util.o
Binary file not shown.
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define VERSION 157
#define VERSION 158
Binary file modified vringbuffer.o
Binary file not shown.
34 changes: 26 additions & 8 deletions winserver.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
#ifndef __linux__
#include "winserver.h"

asio::thread_pool ioc(1);


void read_session(tcp::socket sock) {
std::cout << "Connection established " << sock.remote_endpoint() << std::endl;
void read_session(Presets * p, tcp::socket sock) {
IN
LOGD ("Connection established");

std::array<char, 1000> buffer;
std::string str ("");

for (boost::system::error_code ec;;) {
size_t n = sock.read_some(asio::buffer(buffer), ec);
std::cout << "Received " << n << " " << quoted(std::string(buffer.data(), n)) << " (" << ec.message() << ")" << std::endl;
LOGD( "Received %d bytes: %s (%s)", n, std::string(buffer.data(), n).c_str (), ec.message().c_str ());

if (ec.failed())
str.append (std::string(buffer.data(), n));
if (ec.failed() || str.find("}}}") != string::npos)
break;
}

std::cout << "Connection closed" << std::endl;
str.pop_back () ;
LOGD ("[server] got request: %s", str.c_str ());
json j = json::parse (str);
int how_many = p -> import_presets_from_json (j);
char * ss = g_strdup_printf ("<span foreground=\"green\" weight=\"bold\" size=\"x-large\">Imported %d presets successfully</span>", how_many);
LOGD("[server] %s\n", ss);
//~ gtk_label_set_markup (sync -> header, ss);
g_free (ss);
LOGD ("Connection closed");
OUT
}

void Client::create () {
Expand All @@ -39,16 +52,20 @@ std::string Client::send_preset (json j) {
try {
tcp::socket m_Socket(ioc);
///| todo enter hostname here
m_Socket.connect({{}, port_});
boost::asio::ip::tcp::endpoint endpoint(
boost::asio::ip::address::from_string(host_), 6906);

m_Socket.connect(endpoint);

std::cout << "Client connected" << std::endl;
LOGD ("Client connected");

///| todo: add extra } here
std::string msg = j.dump ().append (string ("}")) ;
LOGD ("[client] send message: %s", msg.c_str ());
write(m_Socket, asio::buffer(msg));
std::this_thread::sleep_for(100ms);
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
LOGD("Exception: %s",e.what());
}

return string ("{}}");
Expand Down Expand Up @@ -76,3 +93,4 @@ void Server::run () {
OUT
}

#endif
7 changes: 5 additions & 2 deletions winserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ using asio::ip::tcp;
using namespace std::chrono_literals;
using boost::system::error_code;

void read_session(tcp::socket sock) ;
void read_session(Presets * p, tcp::socket sock) ;

class TheServer {
public:
Presets * presets ;
TheServer(asio::any_io_executor ex, uint16_t port) //
: m_Acceptor{ex, tcp::endpoint{tcp::v4(), port}} //
{
IN
m_Acceptor.set_option(tcp::acceptor::reuse_address(true));
do_accept();
OUT
}

private:
Expand All @@ -33,7 +36,7 @@ class TheServer {
IN
m_Acceptor.async_accept([this](boost::system::error_code ec, tcp::socket s) {
if (!ec) {
std::thread(read_session, std::move(s)).detach();
std::thread(read_session, presets, std::move(s)).detach();
do_accept(); // and immediately accept new connection(s)
} else {
//~ std::cout << "Connection error (" << ec.message() << ")" << std::endl;
Expand Down
Binary file modified winserver.o
Binary file not shown.

0 comments on commit ab2e545

Please sign in to comment.