* better handling of dropped files
* dragging now uses the mime type icon git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src apps soundrecorder ;
|
|||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared ;
|
||||||
|
UseLibraryHeaders icon ;
|
||||||
|
|
||||||
Application SoundRecorder :
|
Application SoundRecorder :
|
||||||
DrawButton.cpp
|
DrawButton.cpp
|
||||||
|
|||||||
@@ -43,7 +43,6 @@
|
|||||||
|
|
||||||
#include "RecorderWindow.h"
|
#include "RecorderWindow.h"
|
||||||
#include "SoundConsumer.h"
|
#include "SoundConsumer.h"
|
||||||
#include "SoundListView.h"
|
|
||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
|
|
||||||
#if ! NDEBUG
|
#if ! NDEBUG
|
||||||
@@ -807,7 +806,15 @@ void
|
|||||||
RecorderWindow::Selected(BMessage * message)
|
RecorderWindow::Selected(BMessage * message)
|
||||||
{
|
{
|
||||||
// User selected a sound in list view
|
// User selected a sound in list view
|
||||||
UpdatePlayFile();
|
int32 selIdx = fSoundList->CurrentSelection();
|
||||||
|
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(selIdx));
|
||||||
|
if (!pItem)
|
||||||
|
return;
|
||||||
|
status_t err = UpdatePlayFile(pItem, true);
|
||||||
|
if (err != B_OK) {
|
||||||
|
ErrorAlert("recognize this file as a media file", err == B_MEDIA_NO_HANDLER ? B_OK : err);
|
||||||
|
RemoveCurrentSoundItem();
|
||||||
|
}
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,20 +1010,13 @@ RecorderWindow::UpdateButtons()
|
|||||||
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, media_format *inout_format);
|
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, media_format *inout_format);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
status_t
|
||||||
RecorderWindow::UpdatePlayFile()
|
RecorderWindow::UpdatePlayFile(SoundListItem* item, bool updateDisplay)
|
||||||
{
|
{
|
||||||
fScopeView->CancelRendering();
|
fScopeView->CancelRendering();
|
||||||
StopPlaying();
|
StopPlaying();
|
||||||
StopRecording();
|
StopRecording();
|
||||||
|
|
||||||
// Get selection.
|
|
||||||
int32 selIdx = fSoundList->CurrentSelection();
|
|
||||||
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(selIdx));
|
|
||||||
if (! pItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fPlayTrack && fPlayFile) {
|
if (fPlayTrack && fPlayFile) {
|
||||||
fPlayFile->ReleaseTrack(fPlayTrack);
|
fPlayFile->ReleaseTrack(fPlayTrack);
|
||||||
fPlayTrack = NULL;
|
fPlayTrack = NULL;
|
||||||
@@ -1027,16 +1027,14 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t err;
|
status_t err;
|
||||||
BEntry& entry = pItem->Entry();
|
BEntry& entry = item->Entry();
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
entry.GetRef(&ref);
|
entry.GetRef(&ref);
|
||||||
fPlayFile = new BMediaFile(&ref); //, B_MEDIA_FILE_UNBUFFERED);
|
fPlayFile = new BMediaFile(&ref); //, B_MEDIA_FILE_UNBUFFERED);
|
||||||
if ((err = fPlayFile->InitCheck()) < B_OK) {
|
if ((err = fPlayFile->InitCheck()) < B_OK) {
|
||||||
ErrorAlert("recognize this file as a media file", err);
|
|
||||||
delete fPlayFile;
|
delete fPlayFile;
|
||||||
fPlayFile = NULL;
|
fPlayFile = NULL;
|
||||||
RemoveCurrentSoundItem();
|
return err;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ix=0; ix<fPlayFile->CountTracks(); ix++) {
|
for (int ix=0; ix<fPlayFile->CountTracks(); ix++) {
|
||||||
@@ -1056,13 +1054,14 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!fPlayTrack) {
|
if (!fPlayTrack) {
|
||||||
ErrorAlert("find an audio track", err);
|
|
||||||
delete fPlayFile;
|
delete fPlayFile;
|
||||||
fPlayFile = NULL;
|
fPlayFile = NULL;
|
||||||
RemoveCurrentSoundItem();
|
return B_STREAM_NOT_FOUND;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!updateDisplay)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
BString filename = "File Name: ";
|
BString filename = "File Name: ";
|
||||||
filename << ref.name;
|
filename << ref.name;
|
||||||
fFilename->SetText(filename.String());
|
fFilename->SetText(filename.String());
|
||||||
@@ -1101,6 +1100,7 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
|
fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
|
||||||
|
|
||||||
fPlayFrames = fPlayTrack->CountFrames();
|
fPlayFrames = fPlayTrack->CountFrames();
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1108,7 +1108,10 @@ void
|
|||||||
RecorderWindow::ErrorAlert(const char * action, status_t err)
|
RecorderWindow::ErrorAlert(const char * action, status_t err)
|
||||||
{
|
{
|
||||||
char msg[300];
|
char msg[300];
|
||||||
sprintf(msg, "Cannot %s: %s. [%lx]", action, strerror(err), (int32) err);
|
if (err != B_OK)
|
||||||
|
sprintf(msg, "Cannot %s: %s. [%lx]", action, strerror(err), (int32) err);
|
||||||
|
else
|
||||||
|
sprintf(msg, "Cannot %s.", action);
|
||||||
(new BAlert("", msg, "Stop"))->Go();
|
(new BAlert("", msg, "Stop"))->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1161,8 +1164,12 @@ RecorderWindow::AddSoundItem(const BEntry& entry, bool temp)
|
|||||||
|
|
||||||
void
|
void
|
||||||
RecorderWindow::RemoveCurrentSoundItem() {
|
RecorderWindow::RemoveCurrentSoundItem() {
|
||||||
BListItem *item = fSoundList->RemoveItem(fSoundList->CurrentSelection());
|
int32 index = fSoundList->CurrentSelection();
|
||||||
|
BListItem *item = fSoundList->RemoveItem(index);
|
||||||
delete item;
|
delete item;
|
||||||
|
if (index >= fSoundList->CountItems())
|
||||||
|
index = fSoundList->CountItems() - 1;
|
||||||
|
fSoundList->Select(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1171,7 +1178,6 @@ RecorderWindow::RecordFile(void * cookie, bigtime_t timestamp,
|
|||||||
void * data, size_t size, const media_raw_audio_format & format)
|
void * data, size_t size, const media_raw_audio_format & format)
|
||||||
{
|
{
|
||||||
// Callback called from the SoundConsumer when receiving buffers.
|
// Callback called from the SoundConsumer when receiving buffers.
|
||||||
assert((format.format & 0x02) && format.channel_count);
|
|
||||||
RecorderWindow * window = (RecorderWindow *)cookie;
|
RecorderWindow * window = (RecorderWindow *)cookie;
|
||||||
|
|
||||||
if (window->fRecording) {
|
if (window->fRecording) {
|
||||||
@@ -1238,6 +1244,8 @@ RecorderWindow::RefsReceived(BMessage *msg)
|
|||||||
{
|
{
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
|
int32 countGood = 0;
|
||||||
|
int32 countBad = 0;
|
||||||
|
|
||||||
while (msg->FindRef("refs", i++, &ref) == B_OK) {
|
while (msg->FindRef("refs", i++, &ref) == B_OK) {
|
||||||
|
|
||||||
@@ -1246,10 +1254,28 @@ RecorderWindow::RefsReceived(BMessage *msg)
|
|||||||
BNode node(&entry);
|
BNode node(&entry);
|
||||||
|
|
||||||
if (node.IsFile()) {
|
if (node.IsFile()) {
|
||||||
AddSoundItem(entry, false);
|
SoundListItem * listItem = new SoundListItem(entry, false);
|
||||||
|
if (UpdatePlayFile(listItem) == B_OK) {
|
||||||
|
fSoundList->AddItem(listItem);
|
||||||
|
countGood++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
delete listItem;
|
||||||
} else if(node.IsDirectory()) {
|
} else if(node.IsDirectory()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
countBad++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (countBad > 0 && countGood == 0)
|
||||||
|
(new BAlert("Nothing to Play", "None of the files appear to be "
|
||||||
|
"audio files", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
|
||||||
|
else if (countGood > 0) {
|
||||||
|
if (countBad > 0)
|
||||||
|
(new BAlert("Invalid audio files", "Some of the files "
|
||||||
|
"don't appear to be audio files", "OK", NULL, NULL,
|
||||||
|
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
|
||||||
|
fSoundList->Select(fSoundList->CountItems() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,7 +1296,6 @@ RecorderWindow::CopyTarget(BMessage *msg)
|
|||||||
|
|
||||||
// seek time
|
// seek time
|
||||||
bigtime_t start = fTrackSlider->LeftTime();
|
bigtime_t start = fTrackSlider->LeftTime();
|
||||||
fPlayTrack->SeekToTime(&start);
|
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
bigtime_t diffTime = fTrackSlider->RightTime() - fTrackSlider->LeftTime();
|
bigtime_t diffTime = fTrackSlider->RightTime() - fTrackSlider->LeftTime();
|
||||||
@@ -1299,11 +1324,16 @@ RecorderWindow::CopyTarget(BMessage *msg)
|
|||||||
|
|
||||||
char *data = (char *)malloc(fPlayFormat.u.raw_audio.buffer_size);
|
char *data = (char *)malloc(fPlayFormat.u.raw_audio.buffer_size);
|
||||||
|
|
||||||
|
fPlayTrack->SeekToTime(&start);
|
||||||
|
fPlayFrame = fPlayTrack->CurrentFrame();
|
||||||
while (framesToWrite > 0) {
|
while (framesToWrite > 0) {
|
||||||
int64 frames = 0;
|
int64 frames = 0;
|
||||||
status_t err = fPlayTrack->ReadFrames(data, &frames);
|
status_t err = fPlayTrack->ReadFrames(data, &frames);
|
||||||
if (frames <= 0 || err != B_OK)
|
if (frames <= 0 || err != B_OK) {
|
||||||
|
if (err != B_OK)
|
||||||
|
fprintf(stderr, "CopyTarget: ReadFrames failed\n");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
file.Write(data, frames * frameSize);
|
file.Write(data, frames * frameSize);
|
||||||
framesToWrite -= frames;
|
framesToWrite -= frames;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "DrawButton.h"
|
#include "DrawButton.h"
|
||||||
#include "ScopeView.h"
|
#include "ScopeView.h"
|
||||||
|
#include "SoundListView.h"
|
||||||
#include "TransportButton.h"
|
#include "TransportButton.h"
|
||||||
#include "TrackSlider.h"
|
#include "TrackSlider.h"
|
||||||
#include "UpDownButton.h"
|
#include "UpDownButton.h"
|
||||||
@@ -155,7 +156,7 @@ private:
|
|||||||
void CalcSizes(float min_width, float min_height);
|
void CalcSizes(float min_width, float min_height);
|
||||||
void SetButtonState(BtnState state);
|
void SetButtonState(BtnState state);
|
||||||
void UpdateButtons();
|
void UpdateButtons();
|
||||||
void UpdatePlayFile();
|
status_t UpdatePlayFile(SoundListItem *item, bool updateDisplay = false);
|
||||||
void ErrorAlert(const char * action, status_t err);
|
void ErrorAlert(const char * action, status_t err);
|
||||||
|
|
||||||
static void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_raw_audio_format & format);
|
static void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_raw_audio_format & format);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <IconUtils.h>
|
||||||
#include <MimeType.h>
|
#include <MimeType.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
@@ -260,7 +261,28 @@ ScopeView::MouseDown(BPoint position)
|
|||||||
drag.AddString("be:clip_name", "Audio Clip");
|
drag.AddString("be:clip_name", "Audio Clip");
|
||||||
drag.AddString("be:types", B_FILE_MIME_TYPE);
|
drag.AddString("be:types", B_FILE_MIME_TYPE);
|
||||||
|
|
||||||
DragMessage(&drag, Bounds());
|
uint8* data;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
BMimeType wavType("audio/x-wav");
|
||||||
|
if (wavType.InitCheck() < B_OK
|
||||||
|
|| wavType.GetIcon(&data, &size) < B_OK) {
|
||||||
|
wavType.SetTo("audio");
|
||||||
|
if (wavType.InitCheck() < B_OK
|
||||||
|
|| wavType.GetIcon(&data, &size) < B_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BBitmap* bitmap = new BBitmap(
|
||||||
|
BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||||
|
if (BIconUtils::GetVectorIcon(data, size, bitmap) < B_OK) {
|
||||||
|
delete[] data;
|
||||||
|
delete bitmap;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete[] data;
|
||||||
|
DragMessage(&drag, bitmap, B_OP_ALPHA, BPoint(0,0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user