Skip to content

Commit

Permalink
add INSTRUMENT_PITCH endpoint
Browse files Browse the repository at this point in the history
to both OSC and MIDI api
  • Loading branch information
theGreatWhiteShark committed Apr 30, 2024
1 parent c694dcc commit f423df2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ XXXX-XX-XX the hydrogen team <hydrogen-devel@lists.sourceforge.net>
- `CLEAR_SELECTED_INSTRUMENT` - to remove all notes of the selected
pattern associated with the currently selected instrument.
- `CLEAR_PATTERN` - to remove all notes of the selected pattern.
- `INSTRUMENT_PITCH` - to adjust the pitch of an instrument.
- OSC commands
- `NOTE_ON` and `NOTE_OFF` which are handled like incoming MIDI events
without triggering their associated actions.
Expand Down
19 changes: 19 additions & 0 deletions src/core/MidiAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ MidiActionManager::MidiActionManager() {
m_actionMap.insert(std::make_pair("PAN_RELATIVE", std::make_pair( &MidiActionManager::pan_relative, 1 ) ));
m_actionMap.insert(std::make_pair("PAN_ABSOLUTE", std::make_pair( &MidiActionManager::pan_absolute, 1 ) ));
m_actionMap.insert(std::make_pair("PAN_ABSOLUTE_SYM", std::make_pair( &MidiActionManager::pan_absolute_sym, 1 ) ));
m_actionMap.insert(std::make_pair("INSTRUMENT_PITCH",
std::make_pair( &MidiActionManager::instrument_pitch, 1 ) ));
m_actionMap.insert(std::make_pair("FILTER_CUTOFF_LEVEL_ABSOLUTE", std::make_pair( &MidiActionManager::filter_cutoff_level_absolute, 1 ) ));
m_actionMap.insert(std::make_pair("BEATCOUNTER", std::make_pair( &MidiActionManager::beatcounter, 0 ) ));
m_actionMap.insert(std::make_pair("TAP_TEMPO", std::make_pair( &MidiActionManager::tap_tempo, 0 ) ));
Expand Down Expand Up @@ -896,6 +898,23 @@ bool MidiActionManager::pitch_level_absolute( std::shared_ptr<Action> pAction, H
return true;
}

bool MidiActionManager::instrument_pitch( std::shared_ptr<Action> pAction, Hydrogen* pHydrogen ) {

bool ok;
float fPitch;
const int nInstrument = pAction->getParameter1().toInt(&ok,10);
const int nPitchMidi = pAction->getValue().toInt(&ok,10);
if ( nPitchMidi != 0 ) {
fPitch = ( Instrument::fPitchMax - Instrument::fPitchMin ) *
( (float) (nPitchMidi / 127.0 ) ) + Instrument::fPitchMin;
} else {
fPitch = Instrument::fPitchMin;
}

return pHydrogen->getCoreActionController()->
setInstrumentPitch( nInstrument, fPitch );
}

bool MidiActionManager::filter_cutoff_level_absolute( std::shared_ptr<Action> pAction, Hydrogen* pHydrogen ) {
auto pSong = pHydrogen->getSong();

Expand Down
1 change: 1 addition & 0 deletions src/core/MidiAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class MidiActionManager : public H2Core::Object<MidiActionManager>
bool pan_relative(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool pan_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool pan_absolute_sym(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool instrument_pitch(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool filter_cutoff_level_absolute(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool beatcounter(std::shared_ptr<Action> , H2Core::Hydrogen * );
bool tap_tempo(std::shared_ptr<Action> , H2Core::Hydrogen * );
Expand Down
14 changes: 13 additions & 1 deletion src/core/OscServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int OscServer::generic_handler(const char * path,
}
}
}

QRegExp rxStripFilterCutoffAbs( "/Hydrogen/FILTER_CUTOFF_LEVEL_ABSOLUTE/(\\d+)" );
pos = rxStripFilterCutoffAbs.indexIn( oscPath );
if ( pos > -1 ) {
Expand Down Expand Up @@ -682,6 +682,15 @@ void OscServer::FILTER_CUTOFF_LEVEL_ABSOLUTE_Handler(QString param1, QString par
pActionManager->handleAction( pAction );
}


void OscServer::INSTRUMENT_PITCH_Handler( lo_arg** argv, int )
{
INFOLOG( "processing message" );

H2Core::Hydrogen::get_instance()->getCoreActionController()->
setInstrumentPitch( static_cast<int>( argv[0]->f ), argv[1]->f );
}

void OscServer::BEATCOUNTER_Handler(lo_arg **argv,int i)
{
INFOLOG( "processing message" );
Expand Down Expand Up @@ -1357,6 +1366,9 @@ bool OscServer::init()
m_pServerThread->add_method("/Hydrogen/UNMUTE", "f", UNMUTE_Handler);
m_pServerThread->add_method("/Hydrogen/MUTE_TOGGLE", "", MUTE_TOGGLE_Handler);
m_pServerThread->add_method("/Hydrogen/MUTE_TOGGLE", "f", MUTE_TOGGLE_Handler);

m_pServerThread->add_method("/Hydrogen/INSTRUMENT_PITCH", "ff",
INSTRUMENT_PITCH_Handler);

m_pServerThread->add_method("/Hydrogen/NEXT_BAR", "", NEXT_BAR_Handler);
m_pServerThread->add_method("/Hydrogen/NEXT_BAR", "f", NEXT_BAR_Handler);
Expand Down
1 change: 1 addition & 0 deletions src/core/OscServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class OscServer : public H2Core::Object<OscServer>
* \param i Unused number of arguments passed by the OSC
* message.*/
static void SELECT_AND_PLAY_PATTERN_Handler(lo_arg **argv, int i);
static void INSTRUMENT_PITCH_Handler( lo_arg **argv, int t);
/**
* Creates an Action of type @b FILTER_CUTOFF_LEVEL_ABSOLUTE
* and passes its references to
Expand Down

0 comments on commit f423df2

Please sign in to comment.