| 1 |
/* |
| 2 |
This file is part of IanniX, a graphical real-time open-source sequencer for digital art |
| 3 |
Copyright (C) 2010-2015 — IanniX Association |
| 4 |
|
| 5 |
Project Manager: Thierry Coduys (http://www.le-hub.org) |
| 6 |
Development: Guillaume Jacquemin (https://www.buzzinglight.com) |
| 7 |
|
| 8 |
This file was written by Guillaume Jacquemin. |
| 9 |
|
| 10 |
IanniX is a free software: you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation, either version 3 of the License, or |
| 13 |
any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "interfacesyphon.h" |
| 25 |
#include "ui_interfacesyphon.h" |
| 26 |
#import "/Library/Frameworks/Syphon.framework/Versions/A/Headers/Syphon.h" |
| 27 |
|
| 28 |
InterfaceSyphon::InterfaceSyphon(QWidget *parent) : |
| 29 |
NetworkInterface(parent), |
| 30 |
ui(new Ui::InterfaceSyphon) { |
| 31 |
ui->setupUi(this); |
| 32 |
|
| 33 |
serverEnable.setAction(ui->serverEnable, "interfaceSyphonServerEnable"); |
| 34 |
clientEnable.setAction(ui->clientEnable, "interfaceSyphonClientEnable"); |
| 35 |
|
| 36 |
//Init code |
| 37 |
serverInit = false; |
| 38 |
serverTexture = 0; |
| 39 |
serverSyphon = nil; |
| 40 |
clientInit = false; |
| 41 |
clientTexture = 0; |
| 42 |
clientSyphon = nil; |
| 43 |
initSyphonServer(); |
| 44 |
} |
| 45 |
|
| 46 |
InterfaceSyphon::~InterfaceSyphon() { |
| 47 |
releaseSyphonServer(); |
| 48 |
delete ui; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
void InterfaceSyphon::initSyphonServer() { |
| 53 |
serverSyphon = nil; |
| 54 |
} |
| 55 |
|
| 56 |
void InterfaceSyphon::releaseSyphonServer() { |
| 57 |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 58 |
|
| 59 |
[(SyphonServer *)serverSyphon stop]; |
| 60 |
[(SyphonServer *)serverSyphon release]; |
| 61 |
|
| 62 |
[pool drain]; |
| 63 |
} |
| 64 |
|
| 65 |
void InterfaceSyphon::createSyphonServer() { |
| 66 |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 67 |
|
| 68 |
serverSyphon = [[SyphonServer alloc] initWithName:nil context:CGLGetCurrentContext() options:nil]; |
| 69 |
serverInit = true; |
| 70 |
|
| 71 |
[pool drain]; |
| 72 |
} |
| 73 |
void InterfaceSyphon::createSyphonClient() { |
| 74 |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 75 |
|
| 76 |
SyphonServerDirectory *servers = [SyphonServerDirectory sharedDirectory]; |
| 77 |
if(servers) { |
| 78 |
if([servers.servers count] > 0) { |
| 79 |
clientSyphon = [[SyphonClient alloc] initWithServerDescription:[servers.servers objectAtIndex:0] options:nil newFrameHandler:^(SyphonClient *clientSyphon) { |
| 80 |
clientInit = true; |
| 81 |
clientTextureOk = true; |
| 82 |
}]; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
[pool drain]; |
| 87 |
} |
| 88 |
|
| 89 |
void InterfaceSyphon::publishTexture(int textureTarget, int width, int height) { |
| 90 |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 91 |
[(SyphonServer *)serverSyphon publishFrameTexture:serverTexture textureTarget:textureTarget imageRegion:NSMakeRect(0, 0, width, height) textureDimensions:NSMakeSize(width, height) flipped:false]; |
| 92 |
[pool drain]; |
| 93 |
} |
| 94 |
|
| 95 |
GLuint InterfaceSyphon::getTexture(QSizeF *size) { |
| 96 |
clientTextureOk = false; |
| 97 |
SyphonImage *frame = [(SyphonClient*)clientSyphon newFrameImageForContext:CGLGetCurrentContext()]; |
| 98 |
if(frame) { |
| 99 |
clientTexture = frame.textureName; |
| 100 |
if(size) { |
| 101 |
size->setWidth(frame.textureSize.width); |
| 102 |
size->setHeight(frame.textureSize.height); |
| 103 |
} |
| 104 |
[frame release]; |
| 105 |
return clientTexture; |
| 106 |
} |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
|