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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2009 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 * |
141 |
} |
} |
142 |
|
|
143 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
144 |
|
CloseAllConnections(); |
145 |
|
InstrumentManager::StopBackgroundThread(); |
146 |
#if defined(WIN32) |
#if defined(WIN32) |
147 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
148 |
#else |
#else |
555 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
556 |
} |
} |
557 |
#else |
#else |
558 |
|
struct linger linger; |
559 |
|
linger.l_onoff = 1; |
560 |
|
linger.l_linger = 0; |
561 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
562 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
563 |
|
} |
564 |
|
|
565 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
566 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
567 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
633 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
634 |
} |
} |
635 |
|
|
636 |
|
void LSCPServer::CloseAllConnections() { |
637 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
638 |
|
while(iter != Sessions.end()) { |
639 |
|
CloseConnection(iter); |
640 |
|
iter = Sessions.begin(); |
641 |
|
} |
642 |
|
} |
643 |
|
|
644 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
645 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
646 |
} |
} |
1846 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1847 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1848 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1849 |
} |
} |
1850 |
// Must have a device... |
// Must have a device... |
1851 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2497 |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2498 |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2499 |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2500 |
|
} else if (MidiMsg == "CC") { |
2501 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
2502 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
2503 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2504 |
} else { |
} else { |
2505 |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2506 |
} |
} |