示例#1
0
double BeatGrid::getBpm() const {
    QMutexLocker locker(&m_mutex);
    if (!isValid()) {
        return 0;
    }
    return bpm();
}
示例#2
0
double BeatGrid::getBpmRange(double startSample, double stopSample) const {
    QMutexLocker locker(&m_mutex);
    if (!isValid() || startSample > stopSample) {
        return -1;
    }
    return bpm();
}
示例#3
0
/// Note: Since txTick() takes a significant amount of time, the
/// fastest the metronome will currently go is 240 bpm.
void txMetronome(MorseToken) {
  uint8_t bpm(60);
  switch (symbolStackSize()) {
  case 3: 
    bpm = 100 * s(2).m2i() + 10 * s(1).m2i() + s(0).m2i();
    popN(3);
    break;
  case 2: 
    bpm = 10 * s(1).m2i() + s(0).m2i();
    popN(2);
    break;
  case 1:
    bpm = s(0).m2i();
    popN(1);
    break;
  default: txError();
  }
  uint32_t timeout(60 * 1000000 / bpm);
  elapsedMicros sinceTick(0);
  while (!touchPoll(dahPin)) {
    if (timeout < sinceTick) {
      sinceTick = 0;
      txTick(MorseToken());
    }
  }
}
int main()
{
    // Read input and populate graph[][]
    // Set m, n
	long cnt,i;

	while(scanf("%ld",&n)==1)
	{
		m=n;
		memset( matchL, -1, sizeof( matchL ) );
		memset( matchR, -1, sizeof( matchR ) );
		memset(graph,0,sizeof(graph));

		Inp();

		cnt = 0;
		for(i = 0; i < m; i++ )
		{
			memset( seen, 0, sizeof( seen ) );
			if( bpm( i ) ) cnt++;
		}
		
		printf("%ld\n",n-cnt/2);

		// cnt contains the number of happy pigeons
		// matchL[i] contains the hole of pigeon i or -1 if pigeon i is unhappy
		// matchR[j] contains the pigeon in hole j or -1 if hole j is empty
	}
    return 0;
}
示例#5
0
double BeatGrid::getBpmAroundPosition(double curSample, int n) const {
    Q_UNUSED(curSample);
    Q_UNUSED(n);

    QMutexLocker locker(&m_mutex);
    if (!isValid()) {
        return -1;
    }
    return bpm();
}
示例#6
0
void BeatGrid::scale(double dScalePercentage) {
    QMutexLocker locker(&m_mutex);
    if (!isValid()) {
        return;
    }
    double newBpm = bpm() * dScalePercentage;
    m_grid.mutable_bpm()->set_bpm(newBpm);
    m_dBeatLength = (60.0 * m_iSampleRate / newBpm) * kFrameSize;
    locker.unlock();
    emit(updated());
}
示例#7
0
int main()
{
	int i, j, tc, cnt;
	char s1[10], s2[10];

//	freopen( "a.in", "r", stdin );

	scanf( "%d", &tc );

	while ( tc-- )
	{
		scanf( "%d %d", &n, &m );

		memset( graph, 0, sizeof( graph ) );

		for ( i = 0; i < m; ++i )
		{
			scanf( "%s %s", s1, s2 );
			populate( i, s1, s2 );
		}

		memset( matchL, -1, sizeof( matchL ) );
		memset( matchR, -1, sizeof( matchR ) );

		cnt = 0;

		for ( i = 0; i < m; i++ )
		{
			memset( seen, 0, sizeof( seen ) );

			if ( bpm( i ) )
			{
				++cnt;
			}
		}

		// cnt contains the number of happy pigeons

		if ( cnt == m )
		{
			printf( "YES\n" );
		}
		else
		{
			printf( "NO\n" );
		}
	}

	return 0;
}
示例#8
0
void BeatGrid::readByteArray(const QByteArray* pByteArray) {
    mixxx::track::io::BeatGrid grid;
    if (grid.ParseFromArray(pByteArray->constData(), pByteArray->length())) {
        m_grid = grid;
        m_dBeatLength = (60.0 * m_iSampleRate / bpm()) * kFrameSize;
        return;
    }

    // Legacy fallback for BeatGrid-1.0
    if (pByteArray->size() != sizeof(BeatGridData))
        return;
    const BeatGridData* blob = (const BeatGridData*)pByteArray->constData();

    // We serialize into frame offsets but use sample offsets at runtime
    setGrid(blob->bpm, blob->firstBeat * kFrameSize);
}
bool bpm( int u )
{
    for( int v = 0; v < n; v++ ) if( graph[u][v] )
    {
        if( seen[v] ) continue;
        seen[v] = true;

        if( matchR[v] < 0 || bpm( matchR[v] ) )
        {
            matchL[u] = v;
            matchR[v] = u;
            return true;
        }
    }
    return false;
}
示例#10
0
char bpm( int u )
{
    for ( int v = 0; v < n; v++ )
	{
		if ( graph[u][v] == 1 )
		{
			if ( seen[v] )
			{
				continue;
			}

			seen[v] = 1;

			if ( matchR[v] < 0 || bpm( matchR[v] ) )
			{
				matchL[u] = v;
				matchR[v] = u;
				return 1;
			}
		}
	}

    return 0;
}
示例#11
0
// internal use only
bool BeatGrid::isValid() const {
    return m_iSampleRate > 0 && bpm() > 0;
}
 std::chrono::microseconds microsPerBeat() const
 {
   return std::chrono::microseconds{std::llround(60. * 1e6 / bpm())};
 }
示例#13
0
int
PlaylistItem::compare( QListViewItem *i, int col, bool ascending ) const
{
    #define i static_cast<PlaylistItem*>(i)
    if( Playlist::instance()->dynamicMode() && (isEnabled() != i->isEnabled()) )
        return isEnabled() ? 1 : -1;

    //damn C++ and its lack of operator<=>
    #define cmp(a,b) ( (a < b ) ? -1 : ( a > b ) ? 1 : 0 )
    switch( col )
    {
        case Track:      return cmp( track(),     i->track() );
        case Score:      return cmp( score(),     i->score() );
        case Rating:     return cmp( rating(),    i->rating() );
        case Length:     return cmp( length(),    i->length() );
        case PlayCount:  return cmp( playCount(), i->playCount() );
        case LastPlayed: return cmp( lastPlay(),  i->lastPlay() );
        case Bitrate:    return cmp( bitrate(),   i->bitrate() );
        case Bpm:        return cmp( bpm(),       i->bpm() );
        case Filesize:   return cmp( filesize(),  i->filesize() );
        case Mood:
            return cmp( moodbar_const().hueSort(), i->moodbar_const().hueSort() );
        case Year:
            if( year() == i->year() )
                return compare( i, Artist, ascending );
            return cmp( year(), i->year() );
        case DiscNumber:
            if( discNumber() == i->discNumber() )
                return compare( i, Track, true ) * (ascending ? 1 : -1);
            return cmp( discNumber(), i->discNumber() );
    }
    #undef cmp
    #undef i

    QString a =    text( col ).lower();
    QString b = i->text( col ).lower();

    switch( col )
    {
        case Type:
            a = a.rightJustify( b.length(), '0' );
            b = b.rightJustify( a.length(), '0' );
            break;

        case Artist:
            if( a == b ) //if same artist, try to sort by album
                return compare( i, Album, ascending );
            else
            {
                if( a.startsWith( "the ", false ) )
                    a = a.mid( 4 );
                if( b.startsWith( "the ", false ) )
                    b = b.mid( 4 );
            }
            break;

        case Album:
            if( a == b ) //if same album, try to sort by track
                //TODO only sort in ascending order?
                return compare( i, DiscNumber, true ) * (ascending ? 1 : -1);
            break;
    }

    return QString::localeAwareCompare( a, b );
}