コード例 #1
0
ファイル: drumkit.cpp プロジェクト: jask80/hydrogen
bool Drumkit::remove( const QString& dk_name )
{
	QString dk_dir = Filesystem::drumkit_path_search( dk_name );
	if( !Filesystem::drumkit_valid( dk_dir ) ) {
		ERRORLOG( QString( "%1 is not valid drumkit" ).arg( dk_dir ) );
		return false;
	}
	_INFOLOG( QString( "Removing drumkit: %1" ).arg( dk_dir ) );
	if( !Filesystem::rm( dk_dir, true ) ) {
		_ERRORLOG( QString( "Unable to remove drumkit: %1" ).arg( dk_dir ) );
		return false;
	}
	return true;
}
コード例 #2
0
ファイル: PixmapWidget.cpp プロジェクト: AdamFf/hydrogen
void PixmapWidget::setPixmap( QString sPixmapPath, bool expand_horiz )
{
	if ( m_sPixmapPath == sPixmapPath ) {
		return;
	}
	m_sPixmapPath = sPixmapPath;
	__expand_horiz = expand_horiz;

	bool ok = m_pixmap.load( Skin::getImagePath() + sPixmapPath );
	if ( !ok ) {
		_INFOLOG( QString( "Error loading: %1%2").arg( Skin::getImagePath() ).arg( sPixmapPath ) );
	}

	resize( m_pixmap.width(), m_pixmap.height() );
	update();
}
コード例 #3
0
ファイル: drumkit.cpp プロジェクト: jask80/hydrogen
bool Drumkit::install( const QString& path )
{
	_INFOLOG( QString( "Install drumkit %1" ).arg( path ) );
#ifdef H2CORE_HAVE_LIBARCHIVE
	int r;
	struct archive* arch;
	struct archive_entry* entry;

	arch = archive_read_new();

#if ARCHIVE_VERSION_NUMBER < 3000000
	archive_read_support_compression_all( arch );
#else
	archive_read_support_filter_all( arch );
#endif

	archive_read_support_format_all( arch );

#if ARCHIVE_VERSION_NUMBER < 3000000
	if ( ( r = archive_read_open_file( arch, path.toLocal8Bit(), 10240 ) ) ) {
#else
	if ( ( r = archive_read_open_filename( arch, path.toLocal8Bit(), 10240 ) ) ) {
#endif
		_ERRORLOG( QString( "archive_read_open_file() [%1] %2" ).arg( archive_errno( arch ) ).arg( archive_error_string( arch ) ) );
		archive_read_close( arch );

		#if ARCHIVE_VERSION_NUMBER < 3000000
			archive_read_finish( arch );
		#else
			archive_read_free( arch );
		#endif

		return false;
	}
	bool ret = true;
	QString dk_dir = Filesystem::usr_drumkits_dir() + "/";
	while ( ( r = archive_read_next_header( arch, &entry ) ) != ARCHIVE_EOF ) {
		if ( r != ARCHIVE_OK ) {
			_ERRORLOG( QString( "archive_read_next_header() [%1] %2" ).arg( archive_errno( arch ) ).arg( archive_error_string( arch ) ) );
			ret = false;
			break;
		}
		QString np = dk_dir + archive_entry_pathname( entry );

		QByteArray newpath = np.toLocal8Bit();

		archive_entry_set_pathname( entry, newpath.data() );
		r = archive_read_extract( arch, entry, 0 );
		if ( r == ARCHIVE_WARN ) {
			_WARNINGLOG( QString( "archive_read_extract() [%1] %2" ).arg( archive_errno( arch ) ).arg( archive_error_string( arch ) ) );
		} else if ( r != ARCHIVE_OK ) {
			_ERRORLOG( QString( "archive_read_extract() [%1] %2" ).arg( archive_errno( arch ) ).arg( archive_error_string( arch ) ) );
			ret = false;
			break;
		}
	}
	archive_read_close( arch );

	#if ARCHIVE_VERSION_NUMBER < 3000000
		archive_read_finish( arch );
	#else
		archive_read_free( arch );
	#endif

	return ret;
#else // H2CORE_HAVE_LIBARCHIVE
#ifndef WIN32
	// GUNZIP
	QString gzd_name = path.left( path.indexOf( "." ) ) + ".tar";
	FILE* gzd_file = fopen( gzd_name.toLocal8Bit(), "wb" );
	gzFile gzip_file = gzopen( path.toLocal8Bit(), "rb" );
	if ( !gzip_file ) {
		_ERRORLOG( QString( "Error reading drumkit file: %1" ).arg( path ) );
		gzclose( gzip_file );
		fclose( gzd_file );
		return false;
	}
	uchar buf[4096];
	while ( gzread( gzip_file, buf, 4096 ) > 0 ) {
		fwrite( buf, sizeof( uchar ), 4096, gzd_file );
	}
	gzclose( gzip_file );
	fclose( gzd_file );
	// UNTAR
	TAR* tar_file;

	QByteArray tar_path = gzd_name.toLocal8Bit();

	if ( tar_open( &tar_file, tar_path.data(), NULL, O_RDONLY, 0,  TAR_GNU ) == -1 ) {
		_ERRORLOG( QString( "tar_open(): %1" ).arg( QString::fromLocal8Bit( strerror( errno ) ) ) );
		return false;
	}
	bool ret = true;
	char dst_dir[1024];
	QString dk_dir = Filesystem::usr_drumkits_dir() + "/";
	strncpy( dst_dir, dk_dir.toLocal8Bit(), 1024 );
	if ( tar_extract_all( tar_file, dst_dir ) != 0 ) {
		_ERRORLOG( QString( "tar_extract_all(): %1" ).arg( QString::fromLocal8Bit( strerror( errno ) ) ) );
		ret = false;
	}
	if ( tar_close( tar_file ) != 0 ) {
		_ERRORLOG( QString( "tar_close(): %1" ).arg( QString::fromLocal8Bit( strerror( errno ) ) ) );
		ret = false;
	}
	return ret;
#else // WIN32
	_ERRORLOG( "WIN32 NOT IMPLEMENTED" );
	return false;
#endif
#endif
}

};
コード例 #4
0
void* SndioMidiDriver_thread( void* param )
{
	SndioMidiDriver *instance = ( SndioMidiDriver* )param;
	MidiMessage msg;
	struct pollfd pfd;
	nfds_t nfds;
	char buf[1], sysex_data[256], status = 0;
	int i, msglen, count = 0, sysex_len = 0;

	_INFOLOG("SndioMidiDriver_thread starting");

	while (instance->m_bRunning) {
		nfds = mio_pollfd(instance->hdl, &pfd, POLLIN);
		if (poll(&pfd, nfds, 100) < 0) {
			_ERRORLOG("poll error; aborting midi thread");
			break;
		}
		if (!(mio_revents(instance->hdl, &pfd) & POLLIN))
			continue;

		if (!mio_read(instance->hdl, buf, 1)) {
			_ERRORLOG("read error; aborting midi thread");
			break;
		}

		if (buf[0] & 0x80) {
			status = buf[0];
			count = 0;
			msglen = 2;
			msg.m_type = MidiMessage::UNKNOWN;
			msg.m_nData1 = msg.m_nData2 = 0;
			switch (status & 0xf0) {
			case 0x80:
				msg.m_type = MidiMessage::NOTE_OFF;
				break;
			case 0x90:
				msg.m_type = MidiMessage::NOTE_ON;
				break;
			case 0xa0:
				msg.m_type = MidiMessage::POLYPHONIC_KEY_PRESSURE;
				break;
			case 0xb0:
				msg.m_type = MidiMessage::CONTROL_CHANGE;
				break;
			case 0xc0:
				msg.m_type = MidiMessage::PROGRAM_CHANGE;
				break;
			case 0xd0:
				msg.m_type = MidiMessage::CHANNEL_PRESSURE;
				break;
			case 0xe0:
				msg.m_type = MidiMessage::PITCH_WHEEL;
				break;
			case 0xf0:
				switch (status) {
				case 0xf0:
					msg.m_type = MidiMessage::SYSTEM_EXCLUSIVE;
					sysex_len = 0;
					break;
				case 0xf1:
					msg.m_type = MidiMessage::QUARTER_FRAME;
					msglen = 1;
					break;
				case 0xf2:
					msg.m_type = MidiMessage::SONG_POS;
					break;
				case 0xf3:
					/* song select */
					break;
				case 0xf6:
					/* tune */
					break;
				case 0xf7:
					if (!sysex_len)
						continue;
					for (i = 0; i < sysex_len; i++)
						msg.m_sysexData.push_back(sysex_data[i]);
					instance->handleMidiMessage(msg);
					break;
				case 0xf8:
					/* clock */
					break;
				case 0xf9:
					/* tick */
					break;
				case 0xfa:
					msg.m_type = MidiMessage::START;
					msglen = 0;
					break;
				case 0xfb:
					msg.m_type = MidiMessage::CONTINUE;
					msglen = 0;
					break;
				case 0xfc:
					msg.m_type = MidiMessage::STOP;
					msglen = 0;
					break;
				case 0xfe:
					/* active sense */
					break;
				case 0xff:
					/* reset */
					break;
				}
				break;
			}
			if (msg.m_type == MidiMessage::UNKNOWN) {
				/* _INFOLOG("Unhandled midi message type: " + QString::number(status & 0xff)); */
				continue;
			}
			if (msglen > 0)
				continue;
		}

		/* some bytes left in buffer? */
		if (status == 0)
			continue;

		if (status == 0xf0) {
			if (sysex_len > 255) {
				_ERRORLOG("already 256 bytes in midi sysex buffer!");
				continue;
			}
			sysex_data[sysex_len++] = buf[0];
			continue;
		}

		if (msglen > 0) {
			switch (count) {
			case 0:
				msg.m_nData1 = buf[0];
				break;
			case 1:
				msg.m_nData2 = buf[0];
				break;
			default:
				continue;
			}
			if (++count < msglen)
				continue;
		}

		msg.m_nChannel = (status & 0x0f);

		instance->handleMidiMessage(msg);
	}

	_INFOLOG("MIDI Thread DESTROY");
	pthread_exit(NULL);
	return NULL;
}