Skip to content

Commit

Permalink
Merge pull request #17 from philippekocher/PolytempoNetwork-March2023
Browse files Browse the repository at this point in the history
Polytempo network march2023
  • Loading branch information
schweizerweb committed Apr 18, 2023
2 parents 28f716a + b531bc0 commit f0af95c
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.12)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OSX deployment version")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OSX deployment version")

project(Polytempo)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void Polytempo_NetworkApplication::initialise(const String& commandLine)

// scheduler
Polytempo_ScoreScheduler::getInstance()->setEngine(new Polytempo_NetworkEngine());
Polytempo_EventScheduler::getInstance()->startThread(5); // priority between 0 and 10
Polytempo_EventScheduler::getInstance()->startThread(8); // priority between 0 and 10

// create network connection
oscListener.reset(new Polytempo_OSCListener(POLYTEMPO_NETWORK_PORT_APP));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ void Polytempo_MenuBarModel::getCommandInfo(CommandID commandID, ApplicationComm

case Polytempo_CommandIDs::addSection:
result.setInfo("Add Section", "Add a section", infoCategory, 0);
result.addDefaultKeypress('S', ModifierKeys::altModifier);
result.setActive(window->getContentID() == Polytempo_NetworkWindow::pageEditorViewID && ((Polytempo_PageEditorView*)window->getContentComponent())->hasSelectedImage());
break;

case Polytempo_CommandIDs::addInstance:
result.setInfo("Add Instance", "Add an instance of the section", infoCategory, 0);
result.addDefaultKeypress('N', ModifierKeys::altModifier);
result.setActive(window->getContentID() == Polytempo_NetworkWindow::pageEditorViewID && ((Polytempo_PageEditorView*)window->getContentComponent())->hasSelectedSection());
break;

Expand Down
6 changes: 3 additions & 3 deletions Source/Scheduler/Polytempo_ScoreScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void Polytempo_ScoreScheduler::eventNotification(Polytempo_Event* event)
{
if (event == nullptr) return;
if (event->getType() == eventType_Start) start();
else if (event->getType() == eventType_Stop) stop();
else if (event->getType() == eventType_Stop) stop(true);
else if (event->getType() == eventType_Pause) pause(event);
else if (event->getType() == eventType_GotoMarker) gotoMarker(event);
else if (event->getType() == eventType_GotoTime) gotoTime(event);
Expand Down Expand Up @@ -87,9 +87,9 @@ void Polytempo_ScoreScheduler::start()
else engine->startThread(5); // priority between 0 and 10
}

void Polytempo_ScoreScheduler::stop()
void Polytempo_ScoreScheduler::stop(bool returnToDownbeat)
{
engine->stop();
engine->stop(returnToDownbeat);
engine->pause(false);
Polytempo_EventScheduler::getInstance()->deletePendingEvents();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Scheduler/Polytempo_ScoreScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Polytempo_ScoreScheduler : public Polytempo_EventObserver
void startStop();
void broadcastStop();
void start();
void stop();
void stop(bool returnToDownbeat = false);
void pause(Polytempo_Event*);
void kill();
void returnToLocator();
Expand Down
12 changes: 7 additions & 5 deletions Source/Scheduler/Polytempo_ScoreSchedulerEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ void Polytempo_NetworkEngine::setScoreTime(int time)
{
scheduler->executeEvent(events[i]);
}

lastDownbeat = time;
}

void Polytempo_NetworkEngine::run()
{
int interval = 200;
int lookAhead = 200;
int interval = 200; // update interval in milliseconds
int lookAhead = 800; // look ahead in the score in milliseconds

Polytempo_Event* nextScoreEvent = score->getNextEvent();
Polytempo_Event* schedulerTick = Polytempo_Event::makeEvent(eventType_Tick);
Expand Down Expand Up @@ -177,7 +175,11 @@ void Polytempo_NetworkEngine::run()
this must be called here to make sure that the engine thread really
has finished.
*/
if (!killed) scoreScheduler->gotoTime(lastDownbeat);
if (!killed && shouldReturnToLastDownbeat)
{
scoreScheduler->gotoTime(lastDownbeat);
shouldReturnToLastDownbeat = false;
}

Polytempo_NetworkApplication* const app = dynamic_cast<Polytempo_NetworkApplication*>(JUCEApplication::getInstance());
if (app->quitApplication) app->applicationShouldQuit();
Expand Down
5 changes: 4 additions & 1 deletion Source/Scheduler/Polytempo_ScoreSchedulerEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Polytempo_ScoreSchedulerEngine : public Thread
killed(false),
shouldStop(true),
pausing(false),
shouldReturnToLastDownbeat(false),
scoreTimeOffset(0)
{
}
Expand All @@ -47,9 +48,10 @@ class Polytempo_ScoreSchedulerEngine : public Thread
}
#endif

void stop()
void stop(bool returnToDownbeat = false)
{
shouldStop = true;
shouldReturnToLastDownbeat = returnToDownbeat;
}

void kill()
Expand Down Expand Up @@ -98,6 +100,7 @@ class Polytempo_ScoreSchedulerEngine : public Thread
bool killed;
bool shouldStop;
bool pausing;
bool shouldReturnToLastDownbeat;

private:
uint32 scoreTimeOffset;
Expand Down
19 changes: 14 additions & 5 deletions Source/Views/PolytempoNetwork/Polytempo_PageEditorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Polytempo_PageEditorView::Polytempo_PageEditorView()
addChildComponent(sectionInstancesLabel = new Label(String(), "Instances"));
sectionInstancesLabel->setFont(Font (15.0f, Font::plain));

addChildComponent(addSectionButton = new TextButton("add"));
addSectionButton->addListener(this);

addChildComponent(sectionInstancesViewport = new Polytempo_SectionInstancesViewport());
sectionInstancesViewport->setScrollBarsShown(true, false);
sectionInstancesViewport->getComponent()->setModel(this);
Expand Down Expand Up @@ -202,6 +205,7 @@ void Polytempo_PageEditorView::update()

// hide section instances
sectionInstancesLabel->setVisible(false);
addSectionButton->setVisible(false);
sectionInstancesViewport->setVisible(false);

if(imageID != var() && sectionID == var())
Expand Down Expand Up @@ -250,6 +254,7 @@ void Polytempo_PageEditorView::update()
hTextbox->setText(String((float)r[3],3), dontSendNotification);

sectionInstancesLabel->setVisible(true);
addSectionButton->setVisible(true);
sectionInstancesViewport->setVisible(true);
sectionInstancesViewport->getComponent()->setImageEvents(imageEvents, sectionID);
}
Expand Down Expand Up @@ -298,12 +303,13 @@ void Polytempo_PageEditorView::resized()

relativePositionLabel->setBounds(getWidth() - TREE_VIEW_WIDTH + 5, 0, TREE_VIEW_WIDTH - 20, 34);

xTextbox->setBounds(getWidth() - TREE_VIEW_WIDTH + 10, 50, 55, 26);
yTextbox->setBounds((int)(getWidth() - TREE_VIEW_WIDTH * 0.5 + 10), 50, 55, 26);
wTextbox->setBounds(getWidth() - TREE_VIEW_WIDTH + 10, 95, 55, 26);
hTextbox->setBounds((int)(getWidth() - TREE_VIEW_WIDTH * 0.5 + 10), 95, 55, 26);
xTextbox->setBounds(getWidth() - TREE_VIEW_WIDTH + 10, 50, 80, 26);
yTextbox->setBounds((int)(getWidth() - TREE_VIEW_WIDTH * 0.5 + 10), 50, 80, 26);
wTextbox->setBounds(getWidth() - TREE_VIEW_WIDTH + 10, 95, 80, 26);
hTextbox->setBounds((int)(getWidth() - TREE_VIEW_WIDTH * 0.5 + 10), 95, 80, 26);

sectionInstancesLabel->setBounds(getWidth() - TREE_VIEW_WIDTH + 5, 140, TREE_VIEW_WIDTH - 20, 34);
sectionInstancesLabel->setBounds(getWidth() - TREE_VIEW_WIDTH + 5, 138, TREE_VIEW_WIDTH - 20, 34);
addSectionButton->setBounds(getWidth() - 56, 146, 46, 18);
sectionInstancesViewport->setBounds(r.withLeft(int(getWidth()) - TREE_VIEW_WIDTH + 1).withTrimmedTop(170));
}

Expand Down Expand Up @@ -643,6 +649,9 @@ void Polytempo_PageEditorView::buttonClicked(Button* button) {
}
#endif
}
else if (button == addSectionButton) {
addInstance();
}
}

//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Source/Views/PolytempoNetwork/Polytempo_PageEditorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Polytempo_PageEditorView : public Component,
Polytempo_Textbox *hTextbox;

Label *sectionInstancesLabel;
TextButton * addSectionButton;
Polytempo_SectionInstancesViewport* sectionInstancesViewport;

std::unique_ptr<FileChooser> fc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void Polytempo_SectionInstancesComponent::resized()
for (int i = 0; i < markerTextboxes.size(); i++)
{
regionTextboxes[i]->setBounds(10, i * 120 + 20, int((getWidth() - 20) * 0.3), 28);
deleteButtons[i]->setBounds(10 + int((getWidth() - 20) * 0.75), i * 120 + 20, int((getWidth() - 20) * 0.25), 18);
deleteButtons[i]->setBounds(getWidth() - 56, i * 120 + 20, 46, 18);
markerTextboxes[i]->setBounds(10, i * 120 + 65, int((getWidth() - 20) * 0.3), 28);
timeTextboxes[i]->setBounds(10 + int((getWidth() - 20) * 0.35), i * 120 + 65, int((getWidth() - 20) * 0.65), 28);
}
Expand Down
12 changes: 4 additions & 8 deletions Source/Views/PolytempoNetwork/Polytempo_VisualMetro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Polytempo_VisualMetro::Polytempo_VisualMetro(): Polytempo_EventObserver()
setOpaque(true);
width = 0.0f;
pos = 0.5f;
timeInterval = 50; // good somewhere between 5 and 20
timeInterval = 20; // update interval in milliseconds (equals 50 fps)
tempoFactor = 1.0f;
pattern = 0;
exponentMain = 1.5f;
Expand Down Expand Up @@ -174,7 +174,7 @@ void Polytempo_VisualMetro::timerCallback()
/* conductor position
----------------------------------- */

float ictus = 1.0f - increment * 5.0f;
float ictus = 1.0f - pow(increment * 5, 2.0f);
/* This factor creates a sudden jerk at the end of the movement. The animation of the conductor reaches only a certain amount of the total length (ictus < 1.0, dependent on the tempo) and jumps to the max when the next beat is due.
*/
ictus = ictus < 0 ? 0 : ictus; // must not be negative!
Expand Down Expand Up @@ -271,14 +271,10 @@ void Polytempo_VisualMetro::eventNotification(Polytempo_Event* event)
float actualDuration = beatDuration / tempoFactor;
exponentMain = 0.75f + actualDuration;
exponentMain = exponentMain > 2.5f ? 2.5f : exponentMain; // clip

/*
40 / timeInterval looks good on a fast computer.
60 / timeInterval is needed for slower computers (old mac minis)
*/
exponentMain = exponentMain < 1.0f ? 1.0f : exponentMain;

if (pattern < 3) holdMax = 0;
else holdMax = 60 / timeInterval;
else holdMax = 50 / timeInterval;

increment = (float)timeInterval / actualDuration * 0.001f;

Expand Down

0 comments on commit f0af95c

Please sign in to comment.