* cancel rendering if selection changed
* update track slider borders if selection changed * added drag'n drop from ScopeView git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28574 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <MediaRoster.h>
|
||||
#include <TimeSource.h>
|
||||
#include <NodeInfo.h>
|
||||
|
||||
#include "RecorderWindow.h"
|
||||
#include "SoundConsumer.h"
|
||||
@@ -589,6 +590,9 @@ RecorderWindow::MessageReceived(BMessage * message)
|
||||
RefsReceived(message);
|
||||
break;
|
||||
}
|
||||
case B_COPY_TARGET:
|
||||
CopyTarget(message);
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
@@ -681,7 +685,7 @@ RecorderWindow::Play(BMessage * message)
|
||||
return;
|
||||
}
|
||||
|
||||
fPlayLimit = MIN(fPlayFrames, (off_t)(fTrackSlider->RightTime()*fPlayFormat.u.raw_audio.frame_rate/1000000LL));
|
||||
fPlayLimit = MIN(fPlayFrames, (off_t)(fTrackSlider->RightTime() * fPlayFormat.u.raw_audio.frame_rate / 1000000LL));
|
||||
fPlayTrack->SeekToTime(fTrackSlider->MainTime());
|
||||
fPlayFrame = fPlayTrack->CurrentFrame();
|
||||
|
||||
@@ -1002,6 +1006,10 @@ extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *sel
|
||||
void
|
||||
RecorderWindow::UpdatePlayFile()
|
||||
{
|
||||
fScopeView->CancelRendering();
|
||||
StopPlaying();
|
||||
StopRecording();
|
||||
|
||||
// Get selection.
|
||||
int32 selIdx = fSoundList->CurrentSelection();
|
||||
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(selIdx));
|
||||
@@ -1027,6 +1035,7 @@ RecorderWindow::UpdatePlayFile()
|
||||
ErrorAlert("get the file to play", err);
|
||||
delete fPlayFile;
|
||||
fPlayFile = NULL;
|
||||
RemoveCurrentSoundItem();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1049,6 +1058,8 @@ RecorderWindow::UpdatePlayFile()
|
||||
if (!fPlayTrack) {
|
||||
ErrorAlert("get the file to play", err);
|
||||
delete fPlayFile;
|
||||
fPlayFile = NULL;
|
||||
RemoveCurrentSoundItem();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1086,10 +1097,7 @@ RecorderWindow::UpdatePlayFile()
|
||||
fDuration->SetText(durationString.String());
|
||||
|
||||
fTrackSlider->SetTotalTime(duration, true);
|
||||
fScopeView->SetMainTime(fTrackSlider->LeftTime());
|
||||
fScopeView->SetTotalTime(duration);
|
||||
fScopeView->SetRightTime(fTrackSlider->RightTime());
|
||||
fScopeView->SetLeftTime(fTrackSlider->LeftTime());
|
||||
fScopeView->SetTotalTime(duration, true);
|
||||
fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
|
||||
|
||||
fPlayFrames = fPlayTrack->CountFrames();
|
||||
@@ -1150,6 +1158,14 @@ RecorderWindow::AddSoundItem(const BEntry& entry, bool temp)
|
||||
fSoundList->Select(fSoundList->IndexOf(listItem));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecorderWindow::RemoveCurrentSoundItem() {
|
||||
BListItem *item = fSoundList->RemoveItem(fSoundList->CurrentSelection());
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecorderWindow::RecordFile(void * cookie, bigtime_t timestamp,
|
||||
void * data, size_t size, const media_raw_audio_format & format)
|
||||
@@ -1236,3 +1252,69 @@ RecorderWindow::RefsReceived(BMessage *msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecorderWindow::CopyTarget(BMessage *msg)
|
||||
{
|
||||
const char *type = NULL;
|
||||
if (msg->FindString("be:types", &type) == B_OK) {
|
||||
if (!strcasecmp(type, B_FILE_MIME_TYPE)) {
|
||||
const char *name;
|
||||
entry_ref dir;
|
||||
if (msg->FindString("be:filetypes") == B_OK
|
||||
&& msg->FindString("name", &name) == B_OK
|
||||
&& msg->FindRef("directory", &dir) == B_OK) {
|
||||
BDirectory directory(&dir);
|
||||
BFile file(&directory, name, O_RDWR | O_TRUNC);
|
||||
|
||||
// seek time
|
||||
bigtime_t start = fTrackSlider->LeftTime();
|
||||
fPlayTrack->SeekToTime(&start);
|
||||
|
||||
// write data
|
||||
bigtime_t diffTime = fTrackSlider->RightTime() - fTrackSlider->LeftTime();
|
||||
int64 framesToWrite = (int64) (diffTime * fPlayFormat.u.raw_audio.frame_rate / 1000000LL);
|
||||
int32 frameSize = (fPlayFormat.u.raw_audio.format & 0xf)
|
||||
* fPlayFormat.u.raw_audio.channel_count;
|
||||
|
||||
wave_struct header;
|
||||
header.riff.riff_id = FOURCC('R','I','F','F');
|
||||
header.riff.len = (frameSize * framesToWrite) + 36;
|
||||
header.riff.wave_id = FOURCC('W','A','V','E');
|
||||
header.format_chunk.fourcc = FOURCC('f','m','t',' ');
|
||||
header.format_chunk.len = sizeof(header.format);
|
||||
header.format.format_tag = 1;
|
||||
header.format.channels = fPlayFormat.u.raw_audio.channel_count;
|
||||
header.format.samples_per_sec = (uint32)fPlayFormat.u.raw_audio.frame_rate;
|
||||
header.format.avg_bytes_per_sec = (uint32)(fPlayFormat.u.raw_audio.frame_rate
|
||||
* fPlayFormat.u.raw_audio.channel_count
|
||||
* (fPlayFormat.u.raw_audio.format & 0xf));
|
||||
header.format.bits_per_sample = (fPlayFormat.u.raw_audio.format & 0xf) * 8;
|
||||
header.format.block_align = frameSize;
|
||||
header.data_chunk.fourcc = FOURCC('d','a','t','a');
|
||||
header.data_chunk.len = frameSize * framesToWrite;
|
||||
file.Seek(0, SEEK_SET);
|
||||
file.Write(&header, sizeof(header));
|
||||
|
||||
char *data = (char *)malloc(fPlayFormat.u.raw_audio.buffer_size);
|
||||
|
||||
while (framesToWrite > 0) {
|
||||
int64 frames = 0;
|
||||
status_t err = fPlayTrack->ReadFrames(data, &frames);
|
||||
if (frames <= 0 || err != B_OK)
|
||||
break;
|
||||
file.Write(data, frames * frameSize);
|
||||
framesToWrite -= frames;
|
||||
}
|
||||
|
||||
file.Sync();
|
||||
free(data);
|
||||
BNodeInfo nodeInfo(&file);
|
||||
// set type
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
};
|
||||
|
||||
void AddSoundItem(const BEntry& entry, bool temp = false);
|
||||
void RemoveCurrentSoundItem();
|
||||
|
||||
private:
|
||||
BMediaRoster * fRoster;
|
||||
@@ -164,6 +165,7 @@ static void PlayFile(void * cookie, void * data, size_t size, const media_raw_au
|
||||
static void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
|
||||
|
||||
void RefsReceived(BMessage *msg);
|
||||
void CopyTarget(BMessage *msg);
|
||||
};
|
||||
|
||||
#endif /* RECORDERWINDOW_H */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <MimeType.h>
|
||||
#include <Screen.h>
|
||||
#include <Window.h>
|
||||
#include "DrawingTidbits.h"
|
||||
@@ -132,7 +133,7 @@ ScopeView::RenderLoop()
|
||||
|
||||
int32 previewIndex = 0;
|
||||
|
||||
while (fMediaTrack->ReadFrames(samples, &frames) == B_OK) {
|
||||
while (fIsRendering && fMediaTrack->ReadFrames(samples, &frames) == B_OK) {
|
||||
//TRACE("reading block\n");
|
||||
framesIndex = 0;
|
||||
|
||||
@@ -153,8 +154,6 @@ ScopeView::RenderLoop()
|
||||
sum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TRACE("finished computing, rendering\n");
|
||||
@@ -187,9 +186,14 @@ ScopeView::SetMainTime(bigtime_t timestamp)
|
||||
|
||||
|
||||
void
|
||||
ScopeView::SetTotalTime(bigtime_t timestamp)
|
||||
ScopeView::SetTotalTime(bigtime_t timestamp, bool reset)
|
||||
{
|
||||
fTotalTime = timestamp;
|
||||
if (reset) {
|
||||
fMainTime = 0;
|
||||
fLeftTime = 0;
|
||||
fRightTime = fTotalTime;
|
||||
}
|
||||
Invalidate();
|
||||
TRACE("invalidate done\n");
|
||||
}
|
||||
@@ -222,6 +226,13 @@ ScopeView::RenderTrack(BMediaTrack *track, media_format format)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScopeView::CancelRendering()
|
||||
{
|
||||
fIsRendering = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScopeView::FrameResized(float width, float height)
|
||||
{
|
||||
@@ -232,6 +243,28 @@ ScopeView::FrameResized(float width, float height)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScopeView::MouseDown(BPoint position)
|
||||
{
|
||||
if (!fMediaTrack)
|
||||
return;
|
||||
|
||||
uint32 buttons;
|
||||
BPoint point;
|
||||
GetMouse(&point, &buttons);
|
||||
|
||||
if (buttons & B_PRIMARY_MOUSE_BUTTON) {
|
||||
// fill the drag message
|
||||
BMessage drag(B_SIMPLE_DATA);
|
||||
drag.AddInt32("be:actions", B_COPY_TARGET);
|
||||
drag.AddString("be:clip_name", "Audio Clip");
|
||||
drag.AddString("be:types", B_FILE_MIME_TYPE);
|
||||
|
||||
DragMessage(&drag, Bounds());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScopeView::InitBitmap()
|
||||
{
|
||||
|
||||
@@ -24,9 +24,11 @@ public:
|
||||
void SetMainTime(bigtime_t timestamp);
|
||||
void SetLeftTime(bigtime_t timestamp);
|
||||
void SetRightTime(bigtime_t timestamp);
|
||||
void SetTotalTime(bigtime_t timestamp);
|
||||
void SetTotalTime(bigtime_t timestamp, bool reset);
|
||||
void RenderTrack(BMediaTrack *track, media_format format);
|
||||
void CancelRendering();
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MouseDown(BPoint position);
|
||||
private:
|
||||
void Run();
|
||||
void Quit();
|
||||
|
||||
@@ -364,6 +364,7 @@ TrackSlider::SetMainTime(bigtime_t timestamp, bool reset)
|
||||
fLeftTime = 0;
|
||||
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
||||
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
||||
RenderBitmap();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
@@ -380,6 +381,7 @@ TrackSlider::SetTotalTime(bigtime_t timestamp, bool reset)
|
||||
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
|
||||
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
||||
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
||||
RenderBitmap();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user