Skip to content

Commit

Permalink
pre break
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Oct 30, 2024
1 parent 3bff44c commit 1db2091
Show file tree
Hide file tree
Showing 41 changed files with 242 additions and 45 deletions.
Binary file modified FileWriter.o
Binary file not shown.
Binary file modified LockFreeQueue.o
Binary file not shown.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TARGET=linux
VERSION=`git rev-list --count HEAD`

ifeq ($(TARGET),linux)
GTK=`pkg-config --cflags --libs gtk4`
GTK=`pkg-config --cflags --libs gtk4`
LV2=`pkg-config --cflags lilv-0 --libs`
JACK=`pkg-config jack --libs --cflags portaudio-2.0`
SNDFILE=`pkg-config --libs sndfile --cflags`
Expand All @@ -16,8 +16,8 @@ LAME=`pkg-config lame --libs --cflags` -l:libmp3lame.a
GLIB=`pkg-config glib-2.0 --libs --cflags`
X11=`pkg-config x11 --libs --cflags`
OPTIMIZE=#-Ofast -mtune=cortex-a72 -mcpu=cortex-a72
CC=cc
CPP=c++
CC=cc -g -ggdb
CPP=c++ -g -ggdb
else ifeq ($(TARGET),win32)
GTK=`x86_64-w64-mingw32-pkg-config --cflags --libs gtk4 gtk4-win32` -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/gtk-4.0/
LV2=
Expand All @@ -27,7 +27,7 @@ OPUS=`x86_64-w64-mingw32-pkg-config --cflags --libs opus opusfile`
LAME=-llibmp3lame
X11=
GLIB=`mingw64-pkg-config glib-2.0 --libs --cflags`
OPTIMIZE=
OPTIMIZE=-fast
CC=x86_64-w64-mingw32-gcc -g -mwindows -mconsole
CPP=x86_64-w64-mingw32-g++ -std=c++17 -g -mwindows -mconsole
DLFCN=-llibdl
Expand Down Expand Up @@ -104,5 +104,8 @@ vringbuffer.o: upwaker.c vringbuffer.cc
win32-release:
export VER=$(VERSION) ; cd .. ; zip -r releases/amprack-$$VER.zip win/

sync.o: sync.cc sync.h
sync.o: sync.cc sync.h server.o
$(CPP) -c sync.cc $(GTK)

server.o: server.cc server.h client.cc client.h
$(CPP) -c server.cc client.cc $(GTK) -Wall
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 modified amprack
Binary file not shown.
Binary file modified cairo.o
Binary file not shown.
90 changes: 72 additions & 18 deletions client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ void Client::run() {

void
Client::create() {
IN
struct sockaddr_in server_addr;

// use DNS to get IP address
struct hostent *hostEntry;
hostEntry = gethostbyname(host_.c_str());
if (!hostEntry) {
cout << "No such host name: " << host_ << endl;
exit(-1);
LOGD ("No such host name: %s" , host_.c_str ());
return ;
}

LOGD ("[client] connect to %s:%d\n", host_.c_str (), port_);
// setup socket address structure
memset(&server_addr,0,sizeof(server_addr));
server_addr.sin_family = AF_INET;
Expand All @@ -38,20 +40,24 @@ Client::create() {
// create socket
server_ = socket(PF_INET,SOCK_STREAM,0);
if (!server_) {
HERE LOGD ("cannot create socket\n");
perror("socket");
exit(-1);
}

// connect to server
if (connect(server_,(const struct sockaddr *)&server_addr,sizeof(server_addr)) < 0) {
HERE LOGD ("cannot connect to server\n");
perror("connect");
exit(-1);
}
}

void
Client::close_socket() {
IN
close(server_);
OUT
}

void
Expand All @@ -64,37 +70,81 @@ Client::echo() {
line += "\n";
// send request
bool success = send_request(line);
// break if an error occurred
if (not success)
if (not success) {
printf ("[68] break if an error occurred\n");
break;
}
// get a response
success = get_response();
// break if an error occurred
if (not success)
break;
if (not success) {
printf ("[73] break if an error occurred\n");
break;
}
}
close_socket();
}

std::string
Client::send_preset(json j) {
IN
// loop to handle user interface
bool success = send_request(j.dump ());
if (not success) {
printf ("[86] break if an error occurred\n");
}
// get a response
string response = "";
// read until we get a newline
while (response.find("}}") == string::npos) {
int nread = recv(server_,buf_,1024,0);
if (nread < 0) {
if (errno == EINTR) {
printf ("the socket call was interrupted -- try again\n");
continue;
}
else {
HERE LOGD ("an error occurred: %s\n", strerror (errno));
return "";
}
} else if (nread == 0) {
printf ("the socket is closed\n");
return "";
}
// be sure to use append in case we have binary data
response.append(buf_,nread);
}

// a better client would cut off anything after the newline and
// save it in a cache
if (not success) {
HERE LOGD ("[92] break if an error occurred\n");
}

close_socket();
OUT
return response ;
}

bool
Client::send_request(string request) {
// prepare to send request
//~ printf ("----------------------- -|prepare to send request: %s |- ---------------------------\n",
//~ request.c_str ());
const char* ptr = request.c_str();
int nleft = request.length();
int nwritten;
// loop to be sure it is all sent
while (nleft) {
if ((nwritten = send(server_, ptr, nleft, 0)) < 0) {
if (errno == EINTR) {
// the socket call was interrupted -- try again
LOGD ("the socket call was interrupted -- try again\n");
continue;
} else {
// an error occurred, so break out
HERE LOGD ("an error occurred: %s\n", strerror (errno));
perror("write");
return false;
}
} else if (nwritten == 0) {
// the socket is closed
LOGD ("the socket is closed\n");
return false;
}
nleft -= nwritten;
Expand All @@ -105,26 +155,30 @@ Client::send_request(string request) {

bool
Client::get_response() {
IN
string response = "";
// read until we get a newline
while (response.find("\n") == string::npos) {
while (response.find("}}") == string::npos) {
int nread = recv(server_,buf_,1024,0);
if (nread < 0) {
if (errno == EINTR)
// the socket call was interrupted -- try again
if (errno == EINTR) {
printf ("the socket call was interrupted -- try again\n");
continue;
else
// an error occurred, so break out
}
else {
HERE LOGD ("an error occurred, so break out\n");
return "";
}
} else if (nread == 0) {
// the socket is closed
printf ("the socket is closed\n");
return "";
}
// be sure to use append in case we have binary data
response.append(buf_,nread);
}
// a better client would cut off anything after the newline and
// save it in a cache
cout << response;
HERE LOGD ("[client] response: %s\n", response.c_str ());
OUT
return true;
}
12 changes: 9 additions & 3 deletions client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@
#include <iostream>
#include <string>


#include "presets.h"
#include "json.hpp"

using namespace std;
using json = nlohmann::json;

class Client {
public:
Client(string host, int port);
~Client();

void run();

private:
std::string send_preset(json j) ;
virtual void create();
virtual void close_socket();

private:
void echo();
bool send_request(string);
bool get_response();

string host_;
int port_;
int server_;
Expand Down
Binary file added 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.
12 changes: 12 additions & 0 deletions presets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,15 @@ void Presets::save_presets_to_json (std::string filename) {
else
msg ("Error exporting presets");
}

json Presets::get_all_user_presets () {
json ex = json {};
int i = 0 ;
for (const auto & entry : std::filesystem::directory_iterator(*presets_dir)) {
//~ std::cout << entry.path() << std::endl;
json j = filename_to_json (entry.path ().string ());
ex [std::to_string (i++)] = j ;
}

return ex ;
}
2 changes: 2 additions & 0 deletions presets.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Presets {
GtkWidget * page_no ;
GtkAdjustment * adj ;

json get_all_user_presets ();

Presets () {
# ifdef __linux__
dir = std::string (getenv ("HOME")).append ("/.config/amprack") ;
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.
Loading

0 comments on commit 1db2091

Please sign in to comment.