It was already after dark when he finally closed the lid of his

laptop. The source code was written, compiled, and checked in. The bugs
fixed, trampled, squashed. And the MidiPlayer had working Live Input.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8222 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
mahlzeit
2004-06-28 16:35:11 +00:00
parent 8a2005e28a
commit c75d8265c9
3 changed files with 79 additions and 55 deletions
+25 -30
View File
@@ -150,13 +150,10 @@ void MidiPlayerWindow::MenusBeginning()
delete inputPopUp->RemoveItem(t); delete inputPopUp->RemoveItem(t);
} }
bool seenInput = false; // Note: if the selected endpoint no longer exists, then no endpoint is
// marked. However, we won't disconnect it until you choose another one.
if (inputId == -1) inputOff->SetMarked(inputId == -1);
{
inputOff->SetMarked(true);
seenInput = true;
}
int32 id = 0; int32 id = 0;
BMidiEndpoint* endp; BMidiEndpoint* endp;
@@ -170,21 +167,11 @@ void MidiPlayerWindow::MenusBeginning()
BMenuItem* item = new BMenuItem(endp->Name(), msg); BMenuItem* item = new BMenuItem(endp->Name(), msg);
inputPopUp->AddItem(item); inputPopUp->AddItem(item);
item->SetMarked(inputId == id);
if (inputId == id)
{
item->SetMarked(true);
seenInput = true;
}
} }
endp->Release(); endp->Release();
} }
if (!seenInput) // endpoint no longer exists
{
inputOff->SetMarked(true);
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -556,19 +543,6 @@ void MidiPlayerWindow::OnInputChanged(BMessage* msg)
int32 newId; int32 newId;
if (msg->FindInt32("id", &newId) == B_OK) if (msg->FindInt32("id", &newId) == B_OK)
{ {
if (!instrLoaded)
{
scopeView->SetLoading(true);
scopeView->Invalidate();
UpdateIfNeeded();
bridge->Init(B_BIG_SYNTH);
instrLoaded = true;
scopeView->SetLoading(false);
scopeView->Invalidate();
}
BMidiProducer* endp; BMidiProducer* endp;
endp = BMidiRoster::FindProducer(inputId); endp = BMidiRoster::FindProducer(inputId);
@@ -583,8 +557,29 @@ void MidiPlayerWindow::OnInputChanged(BMessage* msg)
endp = BMidiRoster::FindProducer(inputId); endp = BMidiRoster::FindProducer(inputId);
if (endp != NULL) if (endp != NULL)
{ {
if (!instrLoaded)
{
scopeView->SetLoading(true);
scopeView->Invalidate();
UpdateIfNeeded();
bridge->Init(B_BIG_SYNTH);
instrLoaded = true;
scopeView->SetLoading(false);
scopeView->Invalidate();
}
endp->Connect(bridge); endp->Connect(bridge);
endp->Release(); endp->Release();
scopeView->SetLiveInput(true);
scopeView->Invalidate();
}
else
{
scopeView->SetLiveInput(false);
scopeView->Invalidate();
} }
} }
} }
+48 -24
View File
@@ -37,7 +37,8 @@ ScopeView::ScopeView()
enabled = true; enabled = true;
haveFile = false; haveFile = false;
loading = false; loading = false;
liveInput = false;
sampleCount = (int32) Bounds().Width(); sampleCount = (int32) Bounds().Width();
leftSamples = new int16[sampleCount]; leftSamples = new int16[sampleCount];
rightSamples = new int16[sampleCount]; rightSamples = new int16[sampleCount];
@@ -81,7 +82,11 @@ void ScopeView::Draw(BRect updateRect)
{ {
super::Draw(updateRect); super::Draw(updateRect);
if (!haveFile) if (loading)
{
DrawLoading();
}
else if (!haveFile && !liveInput)
{ {
DrawNoFile(); DrawNoFile();
} }
@@ -89,14 +94,14 @@ void ScopeView::Draw(BRect updateRect)
{ {
DrawDisabled(); DrawDisabled();
} }
else if (!playing) else if (playing || liveInput)
{
DrawStopped();
}
else
{ {
DrawPlaying(); DrawPlaying();
} }
else
{
DrawStopped();
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -129,6 +134,13 @@ void ScopeView::SetLoading(bool flag)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ScopeView::SetLiveInput(bool flag)
{
liveInput = flag;
}
//------------------------------------------------------------------------------
int32 ScopeView::_Thread(void* data) int32 ScopeView::_Thread(void* data)
{ {
return ((ScopeView*) data)->Thread(); return ((ScopeView*) data)->Thread();
@@ -144,7 +156,7 @@ int32 ScopeView::Thread()
while (!finished) while (!finished)
{ {
if (enabled && playing && haveFile) if (enabled && (playing || liveInput))
{ {
if (LockLooperWithTimeout(50000) == B_OK) if (LockLooperWithTimeout(50000) == B_OK)
{ {
@@ -159,24 +171,16 @@ int32 ScopeView::Thread()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ScopeView::DrawLoading()
{
DrawText("Loading instruments...");
}
//------------------------------------------------------------------------------
void ScopeView::DrawNoFile() void ScopeView::DrawNoFile()
{ {
const char* string = "Drop MIDI file here"; DrawText("Drop MIDI file here");
font_height height;
GetFontHeight(&height);
float strWidth = StringWidth(string);
float strHeight = height.ascent + height.descent;
float x = (Bounds().Width() - strWidth)/2;
float y = height.ascent + (Bounds().Height() - strHeight)/2;
SetHighColor(255, 255, 255);
SetLowColor(ViewColor());
SetDrawingMode(B_OP_OVER);
DrawString(string, BPoint(x, y));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -230,3 +234,23 @@ void ScopeView::DrawPlaying()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ScopeView::DrawText(const char* text)
{
font_height height;
GetFontHeight(&height);
float strWidth = StringWidth(text);
float strHeight = height.ascent + height.descent;
float x = (Bounds().Width() - strWidth)/2;
float y = height.ascent + (Bounds().Height() - strHeight)/2;
SetHighColor(255, 255, 255);
SetLowColor(ViewColor());
SetDrawingMode(B_OP_OVER);
DrawString(text, BPoint(x, y));
}
//------------------------------------------------------------------------------
+6 -1
View File
@@ -40,6 +40,7 @@ public:
void SetEnabled(bool flag); void SetEnabled(bool flag);
void SetHaveFile(bool flag); void SetHaveFile(bool flag);
void SetLoading(bool flag); void SetLoading(bool flag);
void SetLiveInput(bool flag);
private: private:
@@ -47,17 +48,21 @@ private:
static int32 _Thread(void* data); static int32 _Thread(void* data);
int32 Thread(); int32 Thread();
void DrawLoading();
void DrawNoFile(); void DrawNoFile();
void DrawDisabled(); void DrawDisabled();
void DrawStopped(); void DrawStopped();
void DrawPlaying(); void DrawPlaying();
void DrawText(const char* text);
bool finished; bool finished;
bool playing; bool playing;
bool enabled; bool enabled;
bool haveFile; bool haveFile;
bool loading; bool loading;
bool liveInput;
int32 sampleCount; int32 sampleCount;
int16* leftSamples; int16* leftSamples;
int16* rightSamples; int16* rightSamples;