Skip to content

Commit

Permalink
Merge dev41
Browse files Browse the repository at this point in the history
  • Loading branch information
starg2 committed Sep 5, 2020
2 parents 9060045 + 1a8bd5f commit 21285da
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 37 deletions.
45 changes: 42 additions & 3 deletions interface/w32g_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -5601,19 +5601,33 @@ static struct
} rc_queue[RC_QUEUE_SIZE];
static volatile int rc_queue_len, rc_queue_beg, rc_queue_end;

#define TIMW32G_USE_USERMODE_LOCKS
#ifdef TIMW32G_USE_USERMODE_LOCKS
static SRWLOCK w32g_lock_srwlock = SRWLOCK_INIT;
static CONDITION_VARIABLE w32g_lock_cv = CONDITION_VARIABLE_INIT;
#else
static HANDLE w32g_lock_sem = NULL;
static HANDLE w32g_empty_sem = NULL;
#endif

void w32g_lock(void)
{
#ifdef TIMW32G_USE_USERMODE_LOCKS
AcquireSRWLockExclusive(&w32g_lock_srwlock);
#else
if(w32g_lock_sem)
WaitForSingleObject(w32g_lock_sem, INFINITE);
#endif
}

void w32g_unlock(void)
{
#ifdef TIMW32G_USE_USERMODE_LOCKS
ReleaseSRWLockExclusive(&w32g_lock_srwlock);
#else
if(w32g_lock_sem)
ReleaseSemaphore(w32g_lock_sem, 1, NULL);
#endif
}

void w32g_send_rc(int rc, ptr_size_t value)
Expand All @@ -5631,26 +5645,45 @@ void w32g_send_rc(int rc, ptr_size_t value)
rc_queue[rc_queue_end].rc = rc;
rc_queue[rc_queue_end].value = value;
rc_queue_end = (rc_queue_end + 1) % RC_QUEUE_SIZE;
#ifdef TIMW32G_USE_USERMODE_LOCKS
w32g_unlock();
WakeConditionVariable(&w32g_lock_cv);
#else
if(w32g_empty_sem)
ReleaseSemaphore(w32g_empty_sem, 1, NULL);
w32g_unlock();
#endif
}

int w32g_get_rc(ptr_size_t *value, int wait_if_empty)
{
int rc;
#ifdef TIMW32G_USE_USERMODE_LOCKS
w32g_lock();
#endif

while(rc_queue_len == 0)
{
if(!wait_if_empty)
return RC_NONE;
{
#ifdef TIMW32G_USE_USERMODE_LOCKS
w32g_unlock();
#endif
return RC_NONE;
}
#ifdef TIMW32G_USE_USERMODE_LOCKS
SleepConditionVariableSRW(&w32g_lock_cv, &w32g_lock_srwlock, INFINITE, 0);
#else
if(w32g_empty_sem)
WaitForSingleObject(w32g_empty_sem, INFINITE);
#endif
VOLATILE_TOUCH(rc_queue_len);
}

w32g_lock();
rc = rc_queue[rc_queue_beg].rc;
#ifndef TIMW32G_USE_USERMODE_LOCKS
w32g_lock();
#endif
rc = rc_queue[rc_queue_beg].rc;
*value = rc_queue[rc_queue_beg].value;
rc_queue_len--;
rc_queue_beg = (rc_queue_beg + 1) % RC_QUEUE_SIZE;
Expand All @@ -5664,8 +5697,10 @@ int w32g_open(void)
SaveSettingTiMidity(st_current);
memcpy(st_temp, st_current, sizeof(SETTING_TIMIDITY));

#ifndef TIMW32G_USE_USERMODE_LOCKS
w32g_lock_sem = CreateSemaphore(NULL, 1, 1, _T("TiMidity Mutex Lock"));
w32g_empty_sem = CreateSemaphore(NULL, 0, 8, _T("TiMidity Empty Lock"));
#endif

hPlayerThread = GetCurrentThread();
w32g_wait_for_init = 1;
Expand Down Expand Up @@ -5703,6 +5738,7 @@ static void terminate_main_thread(void)
void w32g_close(void)
{
terminate_main_thread();
#ifndef TIMW32G_USE_USERMODE_LOCKS
if(w32g_lock_sem){
CloseHandle(w32g_lock_sem);
w32g_lock_sem = NULL;
Expand All @@ -5711,13 +5747,15 @@ void w32g_close(void)
CloseHandle(w32g_empty_sem);
w32g_empty_sem = NULL;
}
#endif
}

void w32g_restart(void)
{
w32g_restart_gui_flag = 1;

terminate_main_thread();
#ifndef TIMW32G_USE_USERMODE_LOCKS
if(w32g_lock_sem){
CloseHandle(w32g_lock_sem);
w32g_lock_sem = NULL;
Expand All @@ -5726,6 +5764,7 @@ void w32g_restart(void)
CloseHandle(w32g_empty_sem);
w32g_empty_sem = NULL;
}
#endif

/* Reset variable */
hDebugEditWnd = 0;
Expand Down
85 changes: 51 additions & 34 deletions timidity/sfz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,7 @@ class InstrumentBuilder

// TODO: support trigger=release
case TriggerKind::Release:
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::Trigger);
ctl->cmsg(
Expand All @@ -1668,6 +1669,7 @@ class InstrumentBuilder
case TriggerKind::First:
case TriggerKind::Legato:
default:
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::Trigger);
ctl->cmsg(
Expand Down Expand Up @@ -1729,39 +1731,48 @@ class InstrumentBuilder

if (s.seq_length < s.seq_position)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'seq_position' is larger than 'seq_length'; this region will never be played",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}
}
}
else
{
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequenceLength);
ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'seq_position' is larger than 'seq_length'; this region will never be played",
"%s(%u): 'seq_length' was specified but 'seq_position' was not; this region will never be played",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}
}
else
}
else if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition))
{
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequenceLength);
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'seq_length' was specified but 'seq_position' was not; this region will never be played",
"%s(%u): 'seq_position' was specified but 'seq_length' was not",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}
}
else if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition))
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'seq_position' was specified but 'seq_length' was not",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}

if (auto loRand = flatSection.GetAs<double>(OpCodeKind::LoRand))
{
Expand Down Expand Up @@ -1859,15 +1870,18 @@ class InstrumentBuilder
// sw_down is invalid; disable it
s.sw_down = -1;

auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwDown);

ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'sw_down' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwDown);

ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'sw_down' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}
}
}
else
Expand All @@ -1884,15 +1898,18 @@ class InstrumentBuilder
// sw_up is invalid; disable it
s.sw_up = -1;

auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwUp);

ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'sw_up' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
if (i == 0)
{
auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SwUp);

ctl->cmsg(
CMSG_WARNING,
VERB_VERBOSE,
"%s(%u): 'sw_up' was specified but it is outside the range specified by 'sw_lokey' and 'sw_hikey'",
std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
static_cast<std::uint32_t>(loc.Line)
);
}
}
}
else
Expand Down

0 comments on commit 21285da

Please sign in to comment.