OSC Liblo Window10配置

OpenSoundControl一种网络通讯协议,想了解详情的自行打开网站。
liblo 是最知名的OSC库, 功能完整,用 C 和 LGPL 许可编写。
下载请前往GitHub库
解压后安装过程如下,需要用到CMake:
1.选择源代码文件和构建工程的文件。
图1
2.点击Configure,选择自己的编译器:
图2
3.等待Configure结束:
图3
4.再次点击Cnfigure:
图4
5.点击Generate,生成项目工程:
图5
6.用刚才选择的编译器打开工程:
图6
7.生成->批生成->勾选ALLBUILD和INSTALL:
图7
图8
图9
8.添加环境变量:
图10
9.建立一个C++工程,修改属性表(Debug和Release用一样的属性表):
分别添加:
VC++目录->包含目录:C:\Program Files (x86)\liblo\include;C:\Program Files (x86)\liblo\include\lo
VC++目录->引用目录:C:\Program Files (x86)\liblo\lib
链接器->输入->附加依赖项:liblo.lib
图11
图12
图13
最终属性表使用记事本打开后如下:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>C:\Program Files %28x86%29\liblo\include;C:\Program Files %28x86%29\liblo\include\lo;$(IncludePath)</IncludePath>
    <LibraryPath>C:\Program Files %28x86%29\liblo\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>liblo.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

10.使用如下代码测试:


#include <iostream>
#include <atomic>

#include <lo/lo.h>
#include <lo/lo_cpp.h>

int main()
{
    /*
     * Create a server on a background thread.  Note, all message
     * handlers will run on the background thread!
     */
    lo::ServerThread st(9000);
    if (!st.is_valid()) {
        std::cout << "Nope." << std::endl;
        return 1;
    }

    /* Set some lambdas to be called when the thread starts and
     * ends. Here we demonstrate capturing a reference to the server
     * thread. */
    st.set_callbacks([&st](){printf("Thread init: %p.\n",&st);},
                     [](){printf("Thread cleanup.\n");});

    std::cout << "URL: " << st.url() << std::endl;

    /*
     * Counter for number of messages received -- we use an atomic
     * because it will be updated in a background thread.
     */
    std::atomic<int> received(0);

    /*
     * Add a method handler for "/example,i" using a C++11 lambda to
     * keep it succinct.  We capture a reference to the `received'
     * count and modify it atomatically.
     *
     * You can also pass in a normal function, or a callable function
     * object.
     *
     * Note: If the lambda doesn't specify a return value, the default
     *       is `return 0', meaning "this message has been handled,
     *       don't continue calling the method chain."  If this is not
     *       the desired behaviour, add `return 1' to your method
     *       handlers.
     */
    st.add_method("example", "i",
                  [&received](lo_arg **argv, int)
                  {std::cout << "example (" << (++received) << "): "
                             << argv[0]->i << std::endl;});

    /*
     * Start the server.
     */
    st.start();

    /*
     * Send some messages to the server we just created on localhost.
     */
    lo::Address a("localhost", "9000");

    /*
     * An individual message
     */
    a.send("example", "i", 7890987);

    /*
     * Initalizer lists and message constructors are supported, so
     * that bundles can be created easily:
     */
    a.send(lo::Bundle({{"example", lo::Message("i", 1234321)},
                       {"example", lo::Message("i", 4321234)}}));

    /*
     * Polymorphic overloads on lo::Message::add() mean you don't need
     * to specify the type explicitly.  This is intended to be useful
     * for templates.
     */
    lo::Message m;
    m.add(7654321);
    a.send("example", m);

    /*
     * Wait for messages to be received and processed.
     */
    int tries = 200;
    while (received < 4 && --tries > 0) {
#ifdef WIN32
        Sleep(10);
#else
        usleep(10*1000);
#endif
    }

    if (tries <= 0) {
        std::cout << "Error, waited too long for messages." << std::endl;
        return 1;
    }

    /*
     * Resources are freed automatically, RAII-style, including
     * closing the background server.
     */
    std::cout << "Success!" << std::endl;
}

运行结果如下:
图12
注:
Release模式下,下面这行代码会报错,原因未知,注释掉即可:

std::cout << "URL: " << st.url() << std::endl;
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值