Exemple #1
0
void
MainWin::Play() {
    printf("Playing.\n");

    if (sp && sp->HasData()) {
        sp->Start();
        return;
    }

    printf("Starting at position %d.\n", (int) position);

    status_t err;

    LibraryItem *item = dynamic_cast<LibraryItem *>(be_app->library->list->ItemAt(position));
    printf("Playing track %s.\n", item->entry.name);

    mediaFile = new BMediaFile(&item->entry);
    if ((err = mediaFile->InitCheck()) != B_OK) {
        printf("Play: Initiating media file failed: %s; skipping.\n", strerror(err));
        delete mediaFile;
        Next();
        return;
    }

    playTrack = 0;
    for (int i = 0; i < mediaFile->CountTracks(); i++) {
        playTrack = mediaFile->TrackAt(i);
        playFormat.type = B_MEDIA_RAW_AUDIO;

        if (playTrack->DecodedFormat(&playFormat) == B_OK)
            break;

        if (playTrack)
            mediaFile->ReleaseTrack(playTrack);
    }

    if (playTrack) {
        sp = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", PlayBuffer, Notifier);
        sp->SetCookie(this);
        sp->SetVolume(1.0f);
        sp->SetHasData(true);
        sp->Start();

        char timestamp[100];
        Timestamp(timestamp, playTrack->Duration());

        progress->Reset(NULL, timestamp);
        progress->SetMaxValue(playTrack->Duration());

        BMessage *select = new BMessage(MSG_LIBRARY_HIGHLIGHT);
        select->AddUInt32("position", position);

        be_app->library->PostMessage(select);

        printf("Playback started.\n");
    } else {
        printf("ERROR: No valid track found. Skipping.\n");
        Next();
    }
}
Exemple #2
0
status_t
BKey::Flatten(BMessage& message) const
{
	if (message.MakeEmpty() != B_OK
		|| message.AddUInt32("type", Type()) != B_OK
		|| message.AddUInt32("purpose", fPurpose) != B_OK
		|| message.AddString("identifier", fIdentifier) != B_OK
		|| message.AddString("secondaryIdentifier", fSecondaryIdentifier)
			!= B_OK
		|| message.AddString("owner", fOwner) != B_OK
		|| message.AddInt64("creationTime", fCreationTime) != B_OK
		|| message.AddData("data", B_RAW_TYPE, fData.Buffer(),
			fData.BufferLength()) != B_OK) {
		return B_ERROR;
	}

	return B_OK;
}
void
ToolSelectionWindow::_AddTool(const DrawingTool* tool)
{
    BMessage* message = new BMessage(HS_TOOL_CHANGED);
    message->AddUInt32("buttons", 0);
    message->AddInt32(skTool, tool->Type());

    ToolButton* button = new ToolButton(tool->Name(), message, tool->Icon());
    button->ResizeToPreferred();
    fMatrixView->AddSubView(button);

    gToolMap.insert(std::make_pair(tool->Type(), button));
}
void
ModifierKeysWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kMsgHideShowIcons:
			_HideShowIcons();
			break;

		case kMsgUpdateModifier:
		{
			int32 menuitem = MENU_ITEM_SHIFT;
			int32 key = -1;

			for (; menuitem <= MENU_ITEM_COMMAND; menuitem++) {
				if (message->FindInt32(_KeyToString(menuitem), &key) == B_OK)
					break;
			}

			if (key == -1)
				return;

			// menuitem contains the item we want to set
			// key contains the item we want to set it to.

			switch (menuitem) {
				case MENU_ITEM_SHIFT:
					fCurrentMap->left_shift_key = _KeyToKeyCode(key);
					fCurrentMap->right_shift_key = _KeyToKeyCode(key, true);
					break;

				case MENU_ITEM_CONTROL:
					fCurrentMap->left_control_key = _KeyToKeyCode(key);
					fCurrentMap->right_control_key = _KeyToKeyCode(key, true);
					break;

				case MENU_ITEM_OPTION:
					fCurrentMap->left_option_key = _KeyToKeyCode(key);
					fCurrentMap->right_option_key = _KeyToKeyCode(key, true);
					break;

				case MENU_ITEM_COMMAND:
					fCurrentMap->left_command_key = _KeyToKeyCode(key);
					fCurrentMap->right_command_key = _KeyToKeyCode(key, true);
					break;
			}

			_MarkMenuItems();
			_ValidateDuplicateKeys();
			_HideShowIcons();

			// enable/disable revert button
			fRevertButton->SetEnabled(
				memcmp(fCurrentMap, fSavedMap, sizeof(key_map)));
			break;
		}

		// OK button
		case kMsgApplyModifiers:
		{
			// if duplicate modifiers are found, don't update
			if (_DuplicateKeys() != 0)
				break;

			BMessage* updateModifiers = new BMessage(kMsgUpdateModifierKeys);

			if (fCurrentMap->left_shift_key != fSavedMap->left_shift_key) {
				updateModifiers->AddUInt32("left_shift_key",
					fCurrentMap->left_shift_key);
			}

			if (fCurrentMap->right_shift_key != fSavedMap->right_shift_key) {
				updateModifiers->AddUInt32("right_shift_key",
					fCurrentMap->right_shift_key);
			}

			if (fCurrentMap->left_control_key != fSavedMap->left_control_key) {
				updateModifiers->AddUInt32("left_control_key",
					fCurrentMap->left_control_key);
			}

			if (fCurrentMap->right_control_key
				!= fSavedMap->right_control_key) {
				updateModifiers->AddUInt32("right_control_key",
					fCurrentMap->right_control_key);
			}

			if (fCurrentMap->left_option_key != fSavedMap->left_option_key) {
				updateModifiers->AddUInt32("left_option_key",
					fCurrentMap->left_option_key);
			}

			if (fCurrentMap->right_option_key != fSavedMap->right_option_key) {
				updateModifiers->AddUInt32("right_option_key",
					fCurrentMap->right_option_key);
			}

			if (fCurrentMap->left_command_key != fSavedMap->left_command_key) {
				updateModifiers->AddUInt32("left_command_key",
					fCurrentMap->left_command_key);
			}

			if (fCurrentMap->right_command_key
				!= fSavedMap->right_command_key) {
				updateModifiers->AddUInt32("right_command_key",
					fCurrentMap->right_command_key);
			}

			// KeymapWindow updates the modifiers
			be_app->PostMessage(updateModifiers);

			// we are done here, close the window
			this->PostMessage(B_QUIT_REQUESTED);
			break;
		}

		// Revert button
		case kMsgRevertModifiers:
			memcpy(fCurrentMap, fSavedMap, sizeof(key_map));

			_MarkMenuItems();
			_ValidateDuplicateKeys();
			_HideShowIcons();

			fRevertButton->SetEnabled(false);
			break;

		default:
			BWindow::MessageReceived(message);
	}
}