3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2015 Christian Schoenebeck * |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
31 |
|
|
32 |
#if defined(WIN32) |
#if defined(WIN32) |
33 |
#include <windows.h> |
#include <windows.h> |
34 |
|
typedef unsigned short in_port_t; |
35 |
|
typedef unsigned long in_addr_t; |
36 |
#else |
#else |
37 |
#include <fcntl.h> |
#include <fcntl.h> |
38 |
#endif |
#endif |
113 |
|
|
114 |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
115 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
116 |
SocketAddress.sin_addr.s_addr = addr; |
SocketAddress.sin_addr.s_addr = (in_addr_t)addr; |
117 |
SocketAddress.sin_port = port; |
SocketAddress.sin_port = (in_port_t)port; |
118 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
119 |
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT"); |
120 |
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO"); |
710 |
|
|
711 |
strcpy((char*) buf, command.c_str()); |
strcpy((char*) buf, command.c_str()); |
712 |
LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket); |
LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket); |
713 |
return command.size(); |
return (int) command.size(); |
714 |
} |
} |
715 |
|
|
716 |
extern yyparse_param_t* GetCurrentYaccSession() { |
extern yyparse_param_t* GetCurrentYaccSession() { |
764 |
// first get as many character as possible and add it to the 'input' buffer |
// first get as many character as possible and add it to the 'input' buffer |
765 |
while (true) { |
while (true) { |
766 |
#if defined(WIN32) |
#if defined(WIN32) |
767 |
result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
result = (int)recv(socket, (char*)&c, 1, 0); //Read one character at a time for now |
768 |
#else |
#else |
769 |
result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
result = (int)recv(socket, (void*)&c, 1, 0); //Read one character at a time for now |
770 |
#endif |
#endif |
771 |
if (result == 1) input.push_back(c); |
if (result == 1) input.push_back(c); |
772 |
else break; // end of input or some error |
else break; // end of input or some error |
800 |
} else if (c == 3) { // custom ASCII code usage for moving cursor right (LSCP shell) |
} else if (c == 3) { // custom ASCII code usage for moving cursor right (LSCP shell) |
801 |
if (iter->iCursorOffset < 0) iter->iCursorOffset++; |
if (iter->iCursorOffset < 0) iter->iCursorOffset++; |
802 |
} else { |
} else { |
803 |
size_t cursorPos = bufferedCommands[socket].size() + iter->iCursorOffset; |
ssize_t cursorPos = bufferedCommands[socket].size() + iter->iCursorOffset; |
804 |
// backspace character - should only happen with shell |
// backspace character - should only happen with shell |
805 |
if (c == '\b') { |
if (c == '\b') { |
806 |
if (!bufferedCommands[socket].empty() && cursorPos > 0) |
if (!bufferedCommands[socket].empty() && cursorPos > 0) |
851 |
} |
} |
852 |
#else |
#else |
853 |
if (result == -1) { |
if (result == -1) { |
|
if (errno == EAGAIN) //Would block, try again later. |
|
|
return false; |
|
854 |
switch(errno) { |
switch(errno) { |
855 |
case EBADF: |
case EBADF: |
856 |
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
857 |
return false; |
break; // close connection |
858 |
case ECONNREFUSED: |
case ECONNREFUSED: |
859 |
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
860 |
return false; |
break; // close connection |
861 |
case ENOTCONN: |
case ENOTCONN: |
862 |
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
863 |
return false; |
break; // close connection |
864 |
case ENOTSOCK: |
case ENOTSOCK: |
865 |
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
866 |
return false; |
break; // close connection |
867 |
case EAGAIN: |
case EAGAIN: |
868 |
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
869 |
return false; |
return false; // don't close connection, try again later |
870 |
case EINTR: |
case EINTR: |
871 |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
872 |
return false; |
break; // close connection |
873 |
case EFAULT: |
case EFAULT: |
874 |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
875 |
return false; |
break; // close connection |
876 |
case EINVAL: |
case EINVAL: |
877 |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
878 |
return false; |
break; // close connection |
879 |
case ENOMEM: |
case ENOMEM: |
880 |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
881 |
return false; |
break; // close connection |
882 |
default: |
default: |
883 |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
884 |
return false; |
break; // close connection |
885 |
} |
} |
886 |
CloseConnection(iter); |
CloseConnection(iter); |
887 |
return false; |
return false; |
1146 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
1147 |
LSCPResultSet result; |
LSCPResultSet result; |
1148 |
try { |
try { |
1149 |
int n = EngineFactory::AvailableEngineTypes().size(); |
int n = (int)EngineFactory::AvailableEngineTypes().size(); |
1150 |
result.Add(n); |
result.Add(n); |
1151 |
} |
} |
1152 |
catch (Exception e) { |
catch (Exception e) { |
1350 |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
1351 |
LSCPResultSet result; |
LSCPResultSet result; |
1352 |
try { |
try { |
1353 |
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
int n = (int) AudioOutputDeviceFactory::AvailableDrivers().size(); |
1354 |
result.Add(n); |
result.Add(n); |
1355 |
} |
} |
1356 |
catch (Exception e) { |
catch (Exception e) { |
1376 |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
1377 |
LSCPResultSet result; |
LSCPResultSet result; |
1378 |
try { |
try { |
1379 |
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
int n = (int)MidiInputDeviceFactory::AvailableDrivers().size(); |
1380 |
result.Add(n); |
result.Add(n); |
1381 |
} |
} |
1382 |
catch (Exception e) { |
catch (Exception e) { |
2434 |
dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); |
2435 |
LSCPResultSet result; |
LSCPResultSet result; |
2436 |
try { |
try { |
2437 |
result.Add(MidiInstrumentMapper::Maps().size()); |
result.Add(int(MidiInstrumentMapper::Maps().size())); |
2438 |
} catch (Exception e) { |
} catch (Exception e) { |
2439 |
result.Error(e); |
result.Error(e); |
2440 |
} |
} |
3275 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3276 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3277 |
LSCPResultSet result; |
LSCPResultSet result; |
3278 |
result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices()); |
result.Add(int(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices())); |
3279 |
return result.Produce(); |
return result.Produce(); |
3280 |
} |
} |
3281 |
|
|
3377 |
std::vector<InstrumentManager::instrument_id_t> IDs = |
std::vector<InstrumentManager::instrument_id_t> IDs = |
3378 |
pManager->GetInstrumentFileContent(Filename); |
pManager->GetInstrumentFileContent(Filename); |
3379 |
// return the amount of instruments in the file |
// return the amount of instruments in the file |
3380 |
result.Add(IDs.size()); |
result.Add((int)IDs.size()); |
3381 |
// no more need to ask other engine types |
// no more need to ask other engine types |
3382 |
bFound = true; |
bFound = true; |
3383 |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |