Home Forums BreakawayOne HTTP move a BA1 slider

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #16618
    locod
    Participant

    Hi there, I’m a little out of my depth so please bear with me.
    I’ve been asked by a BA1 user to send midi from within a dj software into BreakawayOne via http localhost.
    I’ve started a plugin for the dj SW and it appears to connect, and am trying further small steps, [if (connected) move a BA1 slider ]

    I’m just a little lost how move the sliders, it may be obvious, it maybe just string formatting. but I’m a little out of my depth.
    here’s a snippet of what I have, thanks in advance for any replies.

    	WSAData wsaData;
    	WORD DllVersion = MAKEWORD(2, 1);
    	if (WSAStartup(DllVersion, &wsaData) != 0) {
    		return S_OK;  // Dj software 
    	}
    
    	string getInput = "";
    	SOCKADDR_IN addr;
    	int addrLen = sizeof(addr);
    	IN_ADDR ipvalue;
    	addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    	addr.sin_port = htons(8200);
    	addr.sin_family = AF_INET;
    
    	SOCKET connection = socket(AF_INET, SOCK_STREAM, NULL);
    	if (connect(connection, (SOCKADDR*)&addr, addrLen) == 0) {
    
    		SendCommand("deck 1 play");  // Dj software connection confirmation
    
    // HERE IS WHERE I'M STUCK
    		getInput = "http://127.0.0.1:8282/parameter/hd1/spk/volume?set=0";
    		send(connection, getInput.c_str(), strlen(getInput.c_str()), 0);
    
    	}
    	else {
    		return S_OK; // Dj software 
    	}
    	return S_OK;
    #16619
    locod
    Participant

    small typo in my code snippet

    addr.sin_port = htons(8200);

    should be 8282
    still lost

    #16620
    locod
    Participant

    As best as I can figure this is the GET request I should send(),
    but I don’t know, maybe there’s something here I fundamentally don’t understand.
    I can’t even figure if I should be using BARemote or not, slightly frustrated now, but that’s par for the course with c++ [at least for me]

    		string getInput = "GET /parameter/hd1/spk/volume?=0 HTTP/1.1\r\nHOST: http://127.0.0.1:8282\r\n\r\n";
    		send(connection, getInput.c_str(), strlen(getInput.c_str()), 0);
    • This reply was modified 2 years, 6 months ago by locod.
    #16621
    Milky
    Keymaster

    Have you researched the use of “cURL”. There are a couple of examples Here

    #16623
    locod
    Participant

    @Milky I haven’t, I thought it could be done without 3rd party libs.
    embarrassingly I had to look up how to even install a lib, I suppose the day hasn’t been a total waste then.

    Thanks, I might be back.

    #16624
    locod
    Participant

    Wait is cURL command line? is that going to work with a midi slider?

    #16625
    locod
    Participant

    I’m even further lost, your examples are command line, I can’t find any simple examples using libcurl, [anywhere]
    Seemed too easy getting a client connection in the first 20 minutes, and now I’ve been 20 tabs deep for 8 hours, and I’m still no wiser.
    Can’t winsock do it? Or could I get a short libcurl example please. [connect & request]

    #16627
    Milky
    Keymaster

    Yes, it is a command line. cURL.exe is bundled with Win10, and downloadable for earlier OSs.
    Is there any way that you can shell out to DOS?

    You could send it to a browser, or possibly directly to the inbuilt web server.

    • This reply was modified 2 years, 6 months ago by Milky.
    #16629
    locod
    Participant

    Isn’t cmd or a browser going to make a window appear every time I touch the slider? to drop the slider to zero is a incremental step, the goal is control from a midi device slider.

    #16630
    locod
    Participant

    finally found a distro for libcurl that avoids all the config,
    I have this simple console app, it connects, it returns OK, it doesn’t move the vol slider though

    #include <stdio.h>
    #include <curl/curl.h>
    
    int main(void)
    {
        CURL* curl;
        CURLcode res;
    
        /* In windows, this will init the winsock stuff */
        curl_global_init(CURL_GLOBAL_ALL);
    
        /* get a curl handle */
        curl = curl_easy_init();
        if (curl) {
    
            curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:8282");
    
            curl_easy_setopt(curl, CURLOPT_HTTPGET, "/parameter/hd1/spk/volume?=0");
    
            /* Perform the request, res will get the return code */
            res = curl_easy_perform(curl);
            /* Check for errors */
            if (res != CURLE_OK)
                fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));
    
            /* always cleanup */
            curl_easy_cleanup(curl);
        }
        curl_global_cleanup();
        return 0;
    }
    #16631
    Milky
    Keymaster

    As I read that code, you are GETTING the current value of the volume, but you are not PUTTING a new value to change it.

    #16632
    locod
    Participant

    I tried that also, my original intel was a AHK script and that used GET

    However, I found the solution […a solution] I started trying things that shouldn’t work, and then it worked, no tailoring, real formatting, GET or PUT, just send it all, full path

            curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:8282/parameter/hd1/spk/volume=0");
        // NOT NEEDED APPARENTLY  curl_easy_setopt(curl, CURLOPT_HTTPGET, "/parameter/hd1/spk/volume?=0");
            /* Perform the request, res will get the return code */
            res = curl_easy_perform(curl);

    After discovering that, 20 minutes later I’ve have a device talking to a virtualdj plugin, the plugin talks to BA1

    #16633
    Milky
    Keymaster

    Excellent! I use AHK quite a bit, including to set/unset various things in BA1, but actually Run or RunWait to the curl line similar to the previous examples. That gives me a return code, plus I can specify “Hide” in the options, so you don’t see a box flash up at all. The response isn’t instantaneous, but pretty close to it.

    For instance, this line will send a toggle command to turn bypass processing on or off
    RunWait, curl --silent --output nul http://otsbox:8282/parameter/hd1/proc/bypass_proxy+=1,,hide

    #16638
    locod
    Participant

    Small update, not that anybody cares.
    I got it working with winsock, I was sending the wrong way, wrong format

    int intSlider2 = slider2 * 100;
    std::stringstream cmd1;
    cmd1 << "PUT /parameter/hd1/spk/volume=" << intSlider2 << " HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";
    std::string getInput = cmd1.str().c_str();
    connection = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (connect(connection, (SOCKADDR*)&addr, addrLen) == 0) {
    	send(connection, getInput.c_str(), strlen(getInput.c_str()), 0);
    	closesocket(connection);
    	}

    midi device talks to virtualdj, vdj talks to plugin, plugin talks to BA1, added bonus I have real time metadata update, I notice a few streams the meta is updated too early or late. If anybody is a vdj && BA1 user you can contact me here.

    • This reply was modified 2 years, 5 months ago by locod.
    #16640
    MrKlorox
    Participant

    Thank you for documenting your research and experimentation! I’m certain this will come in handy for somebody.

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.