* 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 <MediaRoster.h>
|
||||||
#include <TimeSource.h>
|
#include <TimeSource.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
|
||||||
#include "RecorderWindow.h"
|
#include "RecorderWindow.h"
|
||||||
#include "SoundConsumer.h"
|
#include "SoundConsumer.h"
|
||||||
@@ -589,6 +590,9 @@ RecorderWindow::MessageReceived(BMessage * message)
|
|||||||
RefsReceived(message);
|
RefsReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case B_COPY_TARGET:
|
||||||
|
CopyTarget(message);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -681,7 +685,7 @@ RecorderWindow::Play(BMessage * message)
|
|||||||
return;
|
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());
|
fPlayTrack->SeekToTime(fTrackSlider->MainTime());
|
||||||
fPlayFrame = fPlayTrack->CurrentFrame();
|
fPlayFrame = fPlayTrack->CurrentFrame();
|
||||||
|
|
||||||
@@ -1002,6 +1006,10 @@ extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *sel
|
|||||||
void
|
void
|
||||||
RecorderWindow::UpdatePlayFile()
|
RecorderWindow::UpdatePlayFile()
|
||||||
{
|
{
|
||||||
|
fScopeView->CancelRendering();
|
||||||
|
StopPlaying();
|
||||||
|
StopRecording();
|
||||||
|
|
||||||
// Get selection.
|
// Get selection.
|
||||||
int32 selIdx = fSoundList->CurrentSelection();
|
int32 selIdx = fSoundList->CurrentSelection();
|
||||||
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(selIdx));
|
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(selIdx));
|
||||||
@@ -1027,6 +1035,7 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
ErrorAlert("get the file to play", err);
|
ErrorAlert("get the file to play", err);
|
||||||
delete fPlayFile;
|
delete fPlayFile;
|
||||||
fPlayFile = NULL;
|
fPlayFile = NULL;
|
||||||
|
RemoveCurrentSoundItem();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1049,6 +1058,8 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
if (!fPlayTrack) {
|
if (!fPlayTrack) {
|
||||||
ErrorAlert("get the file to play", err);
|
ErrorAlert("get the file to play", err);
|
||||||
delete fPlayFile;
|
delete fPlayFile;
|
||||||
|
fPlayFile = NULL;
|
||||||
|
RemoveCurrentSoundItem();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1086,10 +1097,7 @@ RecorderWindow::UpdatePlayFile()
|
|||||||
fDuration->SetText(durationString.String());
|
fDuration->SetText(durationString.String());
|
||||||
|
|
||||||
fTrackSlider->SetTotalTime(duration, true);
|
fTrackSlider->SetTotalTime(duration, true);
|
||||||
fScopeView->SetMainTime(fTrackSlider->LeftTime());
|
fScopeView->SetTotalTime(duration, true);
|
||||||
fScopeView->SetTotalTime(duration);
|
|
||||||
fScopeView->SetRightTime(fTrackSlider->RightTime());
|
|
||||||
fScopeView->SetLeftTime(fTrackSlider->LeftTime());
|
|
||||||
fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
|
fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
|
||||||
|
|
||||||
fPlayFrames = fPlayTrack->CountFrames();
|
fPlayFrames = fPlayTrack->CountFrames();
|
||||||
@@ -1150,6 +1158,14 @@ RecorderWindow::AddSoundItem(const BEntry& entry, bool temp)
|
|||||||
fSoundList->Select(fSoundList->IndexOf(listItem));
|
fSoundList->Select(fSoundList->IndexOf(listItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RecorderWindow::RemoveCurrentSoundItem() {
|
||||||
|
BListItem *item = fSoundList->RemoveItem(fSoundList->CurrentSelection());
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecorderWindow::RecordFile(void * cookie, bigtime_t timestamp,
|
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)
|
||||||
@@ -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 AddSoundItem(const BEntry& entry, bool temp = false);
|
||||||
|
void RemoveCurrentSoundItem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMediaRoster * fRoster;
|
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, ...);
|
static void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
|
||||||
|
|
||||||
void RefsReceived(BMessage *msg);
|
void RefsReceived(BMessage *msg);
|
||||||
|
void CopyTarget(BMessage *msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RECORDERWINDOW_H */
|
#endif /* RECORDERWINDOW_H */
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <MimeType.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include "DrawingTidbits.h"
|
#include "DrawingTidbits.h"
|
||||||
@@ -132,7 +133,7 @@ ScopeView::RenderLoop()
|
|||||||
|
|
||||||
int32 previewIndex = 0;
|
int32 previewIndex = 0;
|
||||||
|
|
||||||
while (fMediaTrack->ReadFrames(samples, &frames) == B_OK) {
|
while (fIsRendering && fMediaTrack->ReadFrames(samples, &frames) == B_OK) {
|
||||||
//TRACE("reading block\n");
|
//TRACE("reading block\n");
|
||||||
framesIndex = 0;
|
framesIndex = 0;
|
||||||
|
|
||||||
@@ -153,8 +154,6 @@ ScopeView::RenderLoop()
|
|||||||
sum = 0;
|
sum = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("finished computing, rendering\n");
|
TRACE("finished computing, rendering\n");
|
||||||
@@ -187,9 +186,14 @@ ScopeView::SetMainTime(bigtime_t timestamp)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScopeView::SetTotalTime(bigtime_t timestamp)
|
ScopeView::SetTotalTime(bigtime_t timestamp, bool reset)
|
||||||
{
|
{
|
||||||
fTotalTime = timestamp;
|
fTotalTime = timestamp;
|
||||||
|
if (reset) {
|
||||||
|
fMainTime = 0;
|
||||||
|
fLeftTime = 0;
|
||||||
|
fRightTime = fTotalTime;
|
||||||
|
}
|
||||||
Invalidate();
|
Invalidate();
|
||||||
TRACE("invalidate done\n");
|
TRACE("invalidate done\n");
|
||||||
}
|
}
|
||||||
@@ -222,6 +226,13 @@ ScopeView::RenderTrack(BMediaTrack *track, media_format format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScopeView::CancelRendering()
|
||||||
|
{
|
||||||
|
fIsRendering = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScopeView::FrameResized(float width, float height)
|
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
|
void
|
||||||
ScopeView::InitBitmap()
|
ScopeView::InitBitmap()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,9 +24,11 @@ public:
|
|||||||
void SetMainTime(bigtime_t timestamp);
|
void SetMainTime(bigtime_t timestamp);
|
||||||
void SetLeftTime(bigtime_t timestamp);
|
void SetLeftTime(bigtime_t timestamp);
|
||||||
void SetRightTime(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 RenderTrack(BMediaTrack *track, media_format format);
|
||||||
|
void CancelRendering();
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
|
virtual void MouseDown(BPoint position);
|
||||||
private:
|
private:
|
||||||
void Run();
|
void Run();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|||||||
@@ -364,6 +364,7 @@ TrackSlider::SetMainTime(bigtime_t timestamp, bool reset)
|
|||||||
fLeftTime = 0;
|
fLeftTime = 0;
|
||||||
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
||||||
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
||||||
|
RenderBitmap();
|
||||||
}
|
}
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -380,6 +381,7 @@ TrackSlider::SetTotalTime(bigtime_t timestamp, bool reset)
|
|||||||
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
|
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
|
||||||
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
|
||||||
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
|
||||||
|
RenderBitmap();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user