Initial version of the MidiPlayer app. Not complete yet.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8056 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c7ad7fe18e
commit
0fe1abb5aa
@ -7,6 +7,7 @@ SubInclude OBOS_TOP src apps diskprobe ;
|
||||
SubInclude OBOS_TOP src apps expander ;
|
||||
SubInclude OBOS_TOP src apps magnify ;
|
||||
SubInclude OBOS_TOP src apps mediaplayer ;
|
||||
SubInclude OBOS_TOP src apps midiplayer ;
|
||||
SubInclude OBOS_TOP src apps people ;
|
||||
SubInclude OBOS_TOP src apps pulse ;
|
||||
SubInclude OBOS_TOP src apps showimage ;
|
||||
|
16
src/apps/midiplayer/Jamfile
Normal file
16
src/apps/midiplayer/Jamfile
Normal file
@ -0,0 +1,16 @@
|
||||
SubDir OBOS_TOP src apps midiplayer ;
|
||||
|
||||
AddResources MidiPlayer :
|
||||
MidiPlayer.rdef
|
||||
;
|
||||
|
||||
App MidiPlayer :
|
||||
MidiPlayerApp.cpp
|
||||
MidiPlayerWindow.cpp
|
||||
ScopeView.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs MidiPlayer :
|
||||
be
|
||||
midi
|
||||
;
|
76
src/apps/midiplayer/MidiPlayer.rdef
Normal file
76
src/apps/midiplayer/MidiPlayer.rdef
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
resource app_signature "application/x-vnd.OpenBeOS.MidiPlayer";
|
||||
|
||||
resource app_flags B_SINGLE_LAUNCH;
|
||||
|
||||
resource app_version
|
||||
{
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
variety = B_APPV_ALPHA,
|
||||
internal = 0,
|
||||
short_info = "MidiPlayer",
|
||||
long_info = "OpenBeOS - MidiPlayer"
|
||||
};
|
||||
|
||||
resource file_types message
|
||||
{
|
||||
"types" = "audio/x-midi"
|
||||
};
|
||||
|
||||
resource large_icon array
|
||||
{
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFF003F0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFF003F1818180000FFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFF003F1818181818180000FFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFF003F1818181818181818170000FFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFF003F1818181818181818181818180000FFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFF003F1718181818181818181818181818180000FFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFF003F1717181818181818181818181818181818180000FFFFFFFF"
|
||||
$"FFFFFFFFFF003F183C361818181818171818181818181818181818180000FFFF"
|
||||
$"FFFFFFFF003F18181818312B18183F16181718181818181818181818180A00FF"
|
||||
$"FFFFFF003F181818181818181800003F0A0B171818181818181818170B0B00FF"
|
||||
$"FFFF003F17181818181818181816110B3F110017171818181818180A0B0A00FF"
|
||||
$"FF003F18181818181818181818180B3F1100003F3F17181818170B0B0A0000FF"
|
||||
$"003F181818181818181818181818180000111100003F1718180A0B0B000A00FF"
|
||||
$"003F3F1818181818181818181818181817171811110017170B0B0A000B0B000E"
|
||||
$"0011113F3F1718181818181818181818181818181818180A0B0A000B0B0A000F"
|
||||
$"00111111113F3F1718181818181818181818181818180B0B0A000B0B0A000F0F"
|
||||
$"001111111111113F3F1818181818181818181818180A0B0B000A0B0A000F0F0F"
|
||||
$"0000001111111111113F3F1818181818181818180A0B0B000A0B0B000E0F0FFF"
|
||||
$"00111100001111111111113F3F1818181818180A0B0B000A0B0B000E0F0FFFFF"
|
||||
$"001111111100001111111111113F3F1818180A0B0B000A0B0A000F0F0FFFFFFF"
|
||||
$"0011111111111100001111111111113F170B0A0B000A0B0B000F0E0FFFFFFFFF"
|
||||
$"FF0000111111111111000011111111110A0B0A000B0B0A000F0F0FFFFFFFFFFF"
|
||||
$"FFFFFF000011111111111100001111110A0B000A0B0B000F0E0FFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFF00001111111111110000110A000B0A0B000F0F0FFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFF000011111111111100000A0B0A000F0F0FFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFF000011111111110A0B0A000F0F0FFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFF00001111110A0B000F0F0EFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFF0000110A000F0F0FFFFFFFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000E0F0FFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
};
|
||||
|
||||
resource mini_icon array
|
||||
{
|
||||
$"FFFFFFFFFFFF00FFFFFFFFFFFFFFFFFF"
|
||||
$"FFFFFFFFFF00170000FFFFFFFFFFFFFF"
|
||||
$"FFFFFFFF00171718180000FFFFFFFFFF"
|
||||
$"FFFFFF00171718181818180000FFFFFF"
|
||||
$"FFFF0017362B3F1717181818180000FF"
|
||||
$"FF0017171800003F0017171818181700"
|
||||
$"0017181818181700003F3F1717180A00"
|
||||
$"003F3F171818180017000018170B0400"
|
||||
$"0017183F3F181818181717180A050A00"
|
||||
$"00111118173F3F181817170B040B000F"
|
||||
$"000404111118173F3F170B040A000FFF"
|
||||
$"0011110404111117180A050A000FFFFF"
|
||||
$"FF000011110404110B040B000EFFFFFF"
|
||||
$"FFFFFF0000111104040B000FFFFFFFFF"
|
||||
$"FFFFFFFFFF0000110A000FFFFFFFFFFF"
|
||||
$"FFFFFFFFFFFFFF00000EFFFFFFFFFFFF"
|
||||
};
|
92
src/apps/midiplayer/MidiPlayerApp.cpp
Normal file
92
src/apps/midiplayer/MidiPlayerApp.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <Alert.h>
|
||||
#include <StorageKit.h>
|
||||
|
||||
#include "MidiPlayerApp.h"
|
||||
#include "MidiPlayerWindow.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
MidiPlayerApp::MidiPlayerApp()
|
||||
: BApplication(MIDI_PLAYER_SIGNATURE)
|
||||
{
|
||||
window = new MidiPlayerWindow;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerApp::ReadyToRun()
|
||||
{
|
||||
window->Show();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerApp::AboutRequested()
|
||||
{
|
||||
(new BAlert(
|
||||
NULL, "OpenBeOS MidiPlayer\n\n", "Okay", NULL, NULL,
|
||||
B_WIDTH_AS_USUAL, B_INFO_ALERT))->Go();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerApp::RefsReceived(BMessage* msg)
|
||||
{
|
||||
msg->what = B_SIMPLE_DATA;
|
||||
window->PostMessage(msg);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerApp::ArgvReceived(int32 argc, char** argv)
|
||||
{
|
||||
// Note: we only load the first file, even if more than one is specified.
|
||||
// For some reason, BeOS R5 MidiPlayer loads them all but will only play
|
||||
// the last one. That's not very useful.
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
BMessage msg;
|
||||
msg.what = B_SIMPLE_DATA;
|
||||
|
||||
BEntry entry(argv[1]);
|
||||
entry_ref ref;
|
||||
entry.GetRef(&ref);
|
||||
msg.AddRef("refs", &ref);
|
||||
|
||||
window->PostMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
MidiPlayerApp app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
50
src/apps/midiplayer/MidiPlayerApp.h
Normal file
50
src/apps/midiplayer/MidiPlayerApp.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MIDI_PLAYER_APP_H
|
||||
#define MIDI_PLAYER_APP_H
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#define MIDI_PLAYER_SIGNATURE "application/x-vnd.OpenBeOS.MidiPlayer"
|
||||
|
||||
class MidiPlayerWindow;
|
||||
|
||||
class MidiPlayerApp : public BApplication
|
||||
{
|
||||
public:
|
||||
|
||||
MidiPlayerApp();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
virtual void AboutRequested();
|
||||
virtual void RefsReceived(BMessage* msg);
|
||||
virtual void ArgvReceived(int32 argc, char** argv);
|
||||
|
||||
private:
|
||||
|
||||
typedef BApplication super;
|
||||
|
||||
MidiPlayerWindow* window;
|
||||
};
|
||||
|
||||
#endif // MIDI_PLAYER_APP_H
|
454
src/apps/midiplayer/MidiPlayerWindow.cpp
Normal file
454
src/apps/midiplayer/MidiPlayerWindow.cpp
Normal file
@ -0,0 +1,454 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <StorageKit.h>
|
||||
|
||||
#include "MidiPlayerApp.h"
|
||||
#include "MidiPlayerWindow.h"
|
||||
#include "ScopeView.h"
|
||||
|
||||
#define _W(a) (a->Frame().Width())
|
||||
#define _H(a) (a->Frame().Height())
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
MidiPlayerWindow::MidiPlayerWindow()
|
||||
: BWindow(BRect(0, 0, 1, 1), "MIDI Player", B_TITLED_WINDOW,
|
||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE)
|
||||
{
|
||||
playing = false;
|
||||
scopeEnabled = true;
|
||||
reverb = B_REVERB_BALLROOM;
|
||||
volume = 75;
|
||||
windowX = -1;
|
||||
windowY = -1;
|
||||
|
||||
CreateViews();
|
||||
LoadSettings();
|
||||
InitControls();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
MidiPlayerWindow::~MidiPlayerWindow()
|
||||
{
|
||||
Stop(false);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool MidiPlayerWindow::QuitRequested()
|
||||
{
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch (msg->what)
|
||||
{
|
||||
case MSG_PLAY_STOP:
|
||||
OnPlayStop();
|
||||
break;
|
||||
|
||||
case MSG_SHOW_SCOPE:
|
||||
OnShowScope();
|
||||
break;
|
||||
|
||||
case MSG_REVERB_NONE:
|
||||
OnReverb(B_REVERB_NONE);
|
||||
break;
|
||||
|
||||
case MSG_REVERB_CLOSET:
|
||||
OnReverb(B_REVERB_CLOSET);
|
||||
break;
|
||||
|
||||
case MSG_REVERB_GARAGE:
|
||||
OnReverb(B_REVERB_GARAGE);
|
||||
break;
|
||||
|
||||
case MSG_REVERB_IGOR:
|
||||
OnReverb(B_REVERB_BALLROOM);
|
||||
break;
|
||||
|
||||
case MSG_REVERB_CAVERN:
|
||||
OnReverb(B_REVERB_CAVERN);
|
||||
break;
|
||||
|
||||
case MSG_REVERB_DUNGEON:
|
||||
OnReverb(B_REVERB_DUNGEON);
|
||||
break;
|
||||
|
||||
case MSG_VOLUME:
|
||||
OnVolume();
|
||||
break;
|
||||
|
||||
case B_SIMPLE_DATA:
|
||||
OnDrop(msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
super::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::FrameMoved(BPoint origin)
|
||||
{
|
||||
super::FrameMoved(origin);
|
||||
windowX = Frame().left;
|
||||
windowY = Frame().top;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::CreateReverbMenu()
|
||||
{
|
||||
BPopUpMenu* menu = new BPopUpMenu("reverbPopUp");
|
||||
|
||||
reverbNone = new BMenuItem(
|
||||
"None", new BMessage(MSG_REVERB_NONE));
|
||||
|
||||
reverbCloset = new BMenuItem(
|
||||
"Closet", new BMessage(MSG_REVERB_CLOSET));
|
||||
|
||||
reverbGarage = new BMenuItem(
|
||||
"Garage", new BMessage(MSG_REVERB_GARAGE));
|
||||
|
||||
reverbIgor = new BMenuItem(
|
||||
"Igor's Lab", new BMessage(MSG_REVERB_IGOR));
|
||||
|
||||
reverbCavern = new BMenuItem(
|
||||
"Cavern", new BMessage(MSG_REVERB_CAVERN));
|
||||
|
||||
reverbDungeon = new BMenuItem(
|
||||
"Dungeon", new BMessage(MSG_REVERB_DUNGEON));
|
||||
|
||||
menu->AddItem(reverbNone);
|
||||
menu->AddItem(reverbCloset);
|
||||
menu->AddItem(reverbGarage);
|
||||
menu->AddItem(reverbIgor);
|
||||
menu->AddItem(reverbCavern);
|
||||
menu->AddItem(reverbDungeon);
|
||||
|
||||
reverbMenu = new BMenuField(
|
||||
BRect(0, 0, 128, 17), "reverbMenu", "Reverb:", menu,
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||
|
||||
reverbMenu->SetDivider(50);
|
||||
reverbMenu->ResizeToPreferred();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::CreateViews()
|
||||
{
|
||||
scopeView = new ScopeView;
|
||||
|
||||
showScope = new BCheckBox(
|
||||
BRect(0, 0, 1, 1), "showScope", "Scope",
|
||||
new BMessage(MSG_SHOW_SCOPE), B_FOLLOW_LEFT);
|
||||
|
||||
showScope->SetValue(B_CONTROL_ON);
|
||||
showScope->ResizeToPreferred();
|
||||
|
||||
CreateReverbMenu();
|
||||
|
||||
volumeSlider = new BSlider(
|
||||
BRect(0, 0, 1, 1), "volumeSlider", NULL, NULL,
|
||||
0, 100, B_TRIANGLE_THUMB);
|
||||
|
||||
rgb_color col = { 152, 152, 255 };
|
||||
volumeSlider->UseFillColor(true, &col);
|
||||
volumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME));
|
||||
volumeSlider->ResizeToPreferred();
|
||||
volumeSlider->ResizeTo(_W(scopeView) - 37, _H(volumeSlider));
|
||||
|
||||
playButton = new BButton(
|
||||
BRect(0, 1, 80, 1), "playButton", "Play", new BMessage(MSG_PLAY_STOP),
|
||||
B_FOLLOW_RIGHT);
|
||||
|
||||
//playButton->MakeDefault(true);
|
||||
playButton->ResizeToPreferred();
|
||||
playButton->SetEnabled(false);
|
||||
|
||||
BBox* background = new BBox(
|
||||
BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||
B_PLAIN_BORDER);
|
||||
|
||||
BBox* divider = new BBox(
|
||||
BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
|
||||
|
||||
divider->ResizeTo(_W(scopeView), 1);
|
||||
|
||||
BStringView* volumeLabel = new BStringView(
|
||||
BRect(0, 0, 1, 1), NULL, "Volume:");
|
||||
|
||||
volumeLabel->ResizeToPreferred();
|
||||
|
||||
float width = 8 + _W(scopeView) + 8;
|
||||
|
||||
float height =
|
||||
+ 8 + _H(scopeView)
|
||||
+ 8 + _H(showScope)
|
||||
+ 4 + _H(reverbMenu)
|
||||
+ 2 + _H(volumeSlider)
|
||||
+ 10 + _H(divider)
|
||||
+ 6 + _H(playButton)
|
||||
+ 10;
|
||||
|
||||
ResizeTo(width, height);
|
||||
|
||||
AddChild(background);
|
||||
background->ResizeTo(width, height);
|
||||
background->AddChild(scopeView);
|
||||
background->AddChild(showScope);
|
||||
background->AddChild(reverbMenu);
|
||||
background->AddChild(volumeLabel);
|
||||
background->AddChild(volumeSlider);
|
||||
background->AddChild(divider);
|
||||
background->AddChild(playButton);
|
||||
|
||||
float y = 8;
|
||||
scopeView->MoveTo(8, y);
|
||||
|
||||
y += _H(scopeView) + 8;
|
||||
showScope->MoveTo(8 + 50, y);
|
||||
|
||||
y += _H(showScope) + 4;
|
||||
reverbMenu->MoveTo(8, y);
|
||||
|
||||
y += _H(reverbMenu) + 2;
|
||||
volumeLabel->MoveTo(8, y);
|
||||
volumeSlider->MoveTo(8 + 44, y);
|
||||
|
||||
y += _H(volumeSlider) + 10;
|
||||
divider->MoveTo(8, y);
|
||||
|
||||
y += _H(divider) + 6;
|
||||
playButton->MoveTo((width - _W(playButton)) / 2, y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::CenterOnScreen()
|
||||
{
|
||||
BRect screenRect = BScreen(this).Frame();
|
||||
BRect windowRect = Frame();
|
||||
|
||||
MoveTo(
|
||||
(screenRect.Width() - windowRect.Width()) / 2,
|
||||
(screenRect.Height() - windowRect.Height()) / 2);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::InitControls()
|
||||
{
|
||||
Lock();
|
||||
|
||||
showScope->SetValue(scopeEnabled ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||
scopeView->SetEnabled(scopeEnabled);
|
||||
|
||||
reverbNone->SetMarked(reverb == B_REVERB_NONE);
|
||||
reverbCloset->SetMarked(reverb == B_REVERB_CLOSET);
|
||||
reverbGarage->SetMarked(reverb == B_REVERB_GARAGE);
|
||||
reverbIgor->SetMarked(reverb == B_REVERB_BALLROOM);
|
||||
reverbCavern->SetMarked(reverb == B_REVERB_CAVERN);
|
||||
reverbDungeon->SetMarked(reverb == B_REVERB_DUNGEON);
|
||||
be_synth->SetReverb(reverb);
|
||||
|
||||
volumeSlider->SetValue(volume);
|
||||
|
||||
if (windowX != -1 && windowY != -1)
|
||||
{
|
||||
MoveTo(windowX, windowY);
|
||||
}
|
||||
else
|
||||
{
|
||||
CenterOnScreen();
|
||||
}
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::LoadSettings()
|
||||
{
|
||||
BFile file(SETTINGS_FILE, B_READ_ONLY);
|
||||
|
||||
if (file.InitCheck() != B_OK) { return; }
|
||||
if (file.Lock() != B_OK) { return; }
|
||||
|
||||
file.ReadAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool));
|
||||
file.ReadAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32));
|
||||
file.ReadAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32));
|
||||
file.ReadAttr("WindowX", B_FLOAT_TYPE, 0, &windowX, sizeof(float));
|
||||
file.ReadAttr("WindowY", B_FLOAT_TYPE, 0, &windowY, sizeof(float));
|
||||
|
||||
file.Unlock();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::SaveSettings()
|
||||
{
|
||||
BFile file(SETTINGS_FILE, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
|
||||
|
||||
if (file.InitCheck() != B_OK) { return; }
|
||||
if (file.Lock() != B_OK) { return; }
|
||||
|
||||
file.WriteAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool));
|
||||
file.WriteAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32));
|
||||
file.WriteAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32));
|
||||
file.WriteAttr("WindowX", B_FLOAT_TYPE, 0, &windowX, sizeof(float));
|
||||
file.WriteAttr("WindowY", B_FLOAT_TYPE, 0, &windowY, sizeof(float));
|
||||
|
||||
file.Sync();
|
||||
file.Unlock();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::LoadFile(entry_ref* ref)
|
||||
{
|
||||
if (playing)
|
||||
{
|
||||
Stop(false);
|
||||
}
|
||||
|
||||
synth.UnloadFile();
|
||||
|
||||
if (synth.LoadFile(ref) == B_OK)
|
||||
{
|
||||
// Ideally, we would call SetVolume() in InitControls(),
|
||||
// but for some reason that doesn't work; BMidiSynthFile
|
||||
// will use the default volume instead. So we do it here.
|
||||
synth.SetVolume(volume / 100.0f);
|
||||
|
||||
playButton->SetEnabled(true);
|
||||
scopeView->SetHaveFile(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
(new BAlert(
|
||||
NULL, "Could not load song", "Okay", NULL, NULL,
|
||||
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
|
||||
|
||||
playButton->SetEnabled(false);
|
||||
scopeView->SetHaveFile(false);
|
||||
}
|
||||
|
||||
Play();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::Play()
|
||||
{
|
||||
synth.Start();
|
||||
playButton->SetLabel("Stop");
|
||||
playing = true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::Stop(bool changeButton)
|
||||
{
|
||||
if (changeButton)
|
||||
{
|
||||
playButton->SetEnabled(false);
|
||||
}
|
||||
|
||||
synth.Fade();
|
||||
|
||||
if (changeButton)
|
||||
{
|
||||
playButton->SetEnabled(true);
|
||||
playButton->SetLabel("Play");
|
||||
}
|
||||
|
||||
playing = false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::OnPlayStop()
|
||||
{
|
||||
if (playing)
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Play();
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::OnShowScope()
|
||||
{
|
||||
scopeEnabled = !scopeEnabled;
|
||||
scopeView->SetEnabled(scopeEnabled);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::OnReverb(reverb_mode mode)
|
||||
{
|
||||
reverb = mode;
|
||||
be_synth->SetReverb(reverb);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::OnVolume()
|
||||
{
|
||||
volume = volumeSlider->Value();
|
||||
synth.SetVolume(volume / 100.0f);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MidiPlayerWindow::OnDrop(BMessage* msg)
|
||||
{
|
||||
entry_ref ref;
|
||||
if (msg->FindRef("refs", &ref) == B_OK)
|
||||
{
|
||||
LoadFile(&ref);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
99
src/apps/midiplayer/MidiPlayerWindow.h
Normal file
99
src/apps/midiplayer/MidiPlayerWindow.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MIDI_PLAYER_WINDOW_H
|
||||
#define MIDI_PLAYER_WINDOW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <MidiSynthFile.h>
|
||||
|
||||
#define SETTINGS_FILE "/boot/home/config/settings/MidiPlayerSettings"
|
||||
|
||||
enum
|
||||
{
|
||||
MSG_PLAY_STOP = 1000,
|
||||
MSG_SHOW_SCOPE,
|
||||
MSG_REVERB_NONE,
|
||||
MSG_REVERB_CLOSET,
|
||||
MSG_REVERB_GARAGE,
|
||||
MSG_REVERB_IGOR,
|
||||
MSG_REVERB_CAVERN,
|
||||
MSG_REVERB_DUNGEON,
|
||||
MSG_VOLUME,
|
||||
};
|
||||
|
||||
class ScopeView;
|
||||
|
||||
class MidiPlayerWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
|
||||
MidiPlayerWindow();
|
||||
virtual ~MidiPlayerWindow();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage* msg);
|
||||
virtual void FrameMoved(BPoint origin);
|
||||
|
||||
private:
|
||||
|
||||
typedef BWindow super;
|
||||
|
||||
void CreateReverbMenu();
|
||||
void CreateViews();
|
||||
void CenterOnScreen();
|
||||
void InitControls();
|
||||
void LoadSettings();
|
||||
void SaveSettings();
|
||||
|
||||
void LoadFile(entry_ref* ref);
|
||||
void Play();
|
||||
void Stop(bool changeButton);
|
||||
|
||||
void OnPlayStop();
|
||||
void OnShowScope();
|
||||
void OnReverb(reverb_mode mode);
|
||||
void OnVolume();
|
||||
void OnDrop(BMessage* msg);
|
||||
|
||||
ScopeView* scopeView;
|
||||
BCheckBox* showScope;
|
||||
BMenuField* reverbMenu;
|
||||
BMenuItem* reverbNone;
|
||||
BMenuItem* reverbCloset;
|
||||
BMenuItem* reverbGarage;
|
||||
BMenuItem* reverbIgor;
|
||||
BMenuItem* reverbCavern;
|
||||
BMenuItem* reverbDungeon;
|
||||
BSlider* volumeSlider;
|
||||
BButton* playButton;
|
||||
|
||||
bool playing;
|
||||
bool scopeEnabled;
|
||||
reverb_mode reverb;
|
||||
int32 volume;
|
||||
float windowX;
|
||||
float windowY;
|
||||
BMidiSynthFile synth;
|
||||
};
|
||||
|
||||
#endif // MIDI_PLAYER_WINDOW_H
|
56
src/apps/midiplayer/ScopeView.cpp
Normal file
56
src/apps/midiplayer/ScopeView.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "ScopeView.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ScopeView::ScopeView()
|
||||
: BView(BRect(0, 0, 127, 47), NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_PULSE_NEEDED)
|
||||
{
|
||||
SetViewColor(0, 0, 0);
|
||||
enabled = true;
|
||||
haveFile = false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ScopeView::~ScopeView()
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void ScopeView::SetEnabled(bool flag)
|
||||
{
|
||||
enabled = flag;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void ScopeView::SetHaveFile(bool flag)
|
||||
{
|
||||
haveFile = flag;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
46
src/apps/midiplayer/ScopeView.h
Normal file
46
src/apps/midiplayer/ScopeView.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Matthijs Hollemans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SCOPE_VIEW_H
|
||||
#define SCOPE_VIEW_H
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class ScopeView : public BView
|
||||
{
|
||||
public:
|
||||
|
||||
ScopeView();
|
||||
virtual ~ScopeView();
|
||||
|
||||
void SetEnabled(bool flag);
|
||||
void SetHaveFile(bool flag);
|
||||
|
||||
private:
|
||||
|
||||
typedef BView super;
|
||||
|
||||
bool enabled;
|
||||
bool haveFile;
|
||||
};
|
||||
|
||||
#endif // SCOPE_VIEW_H
|
Loading…
Reference in New Issue
Block a user