Skip to content

Commit 8e0a57e

Browse files
committed
[Imp] In-tracker drag&drop can now also be done into the upper half of the sample and instrument views.
[Ref] Move in-tracker sample / instrument drag&drop handling from CViewSample/CViewInstrument to CCtrlSamples/CCtrlInstruments, since all the logic is already there anyway, and the views were just relying window messages to there. git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@25000 56274372-70c3-4bfc-bfc3-4c3a0b034d27
1 parent 9302ee4 commit 8e0a57e

File tree

11 files changed

+302
-329
lines changed

11 files changed

+302
-329
lines changed

mptrack/Ctrl_ins.cpp

Lines changed: 143 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Ctrl_ins.h"
1414
#include "Childfrm.h"
1515
#include "dlg_misc.h"
16+
#include "Dlsbank.h"
1617
#include "FileDialog.h"
1718
#include "Globals.h"
1819
#include "HighDPISupport.h"
@@ -1284,15 +1285,6 @@ LRESULT CCtrlInstruments::OnModCtrlMsg(WPARAM wParam, LPARAM lParam)
12841285
return OpenInstrument(*reinterpret_cast<const mpt::PathString *>(lParam));
12851286
break;
12861287

1287-
case CTRLMSG_INS_SONGDROP:
1288-
if(lParam)
1289-
{
1290-
const auto &dropInfo = *reinterpret_cast<const DRAGONDROP *>(lParam);
1291-
if(dropInfo.sndFile)
1292-
return OpenInstrument(*dropInfo.sndFile, static_cast<INSTRUMENTINDEX>(dropInfo.dropItem));
1293-
}
1294-
break;
1295-
12961288
case CTRLMSG_INS_NEWINSTRUMENT:
12971289
return InsertInstrument(false) ? 1 : 0;
12981290

@@ -1748,6 +1740,148 @@ bool CCtrlInstruments::OpenInstrument(const CSoundFile &sndFile, INSTRUMENTINDEX
17481740
}
17491741

17501742

1743+
1744+
1745+
bool CCtrlInstruments::OnDragonDrop(bool doDrop, const DRAGONDROP &dropInfo)
1746+
{
1747+
bool canDrop = false;
1748+
switch (dropInfo.dropType)
1749+
{
1750+
case DRAGONDROP_INSTRUMENT:
1751+
if(!dropInfo.dropItem)
1752+
return canDrop;
1753+
if(dropInfo.sndFile == &m_sndFile)
1754+
canDrop = dropInfo.dropItem <= m_sndFile.GetNumInstruments();
1755+
else
1756+
canDrop = dropInfo.dropParam || dropInfo.sndFile;
1757+
break;
1758+
1759+
case DRAGONDROP_DLS:
1760+
canDrop = (dropInfo.dropItem < CTrackApp::gpDLSBanks.size()) && CTrackApp::gpDLSBanks[dropInfo.dropItem];
1761+
break;
1762+
1763+
case DRAGONDROP_SOUNDFILE:
1764+
case DRAGONDROP_MIDIINSTR:
1765+
canDrop = !dropInfo.GetPath().empty();
1766+
break;
1767+
1768+
default:
1769+
break;
1770+
}
1771+
1772+
const bool insertNew = m_sndFile.GetNumInstruments() > 0 && ((dropInfo.insertType == DRAGONDROP::InsertType::Unspecified)
1773+
? CInputHandler::ShiftPressed()
1774+
: dropInfo.insertType == DRAGONDROP::InsertType::InsertNew);
1775+
1776+
if(insertNew && !m_sndFile.CanAddMoreInstruments())
1777+
canDrop = false;
1778+
1779+
if(!canDrop || !doDrop)
1780+
return canDrop;
1781+
1782+
if(!m_sndFile.GetNumInstruments() && m_sndFile.GetModSpecifications().instrumentsMax > 0)
1783+
InsertInstrument(false);
1784+
if(!m_nInstrument || m_nInstrument > m_sndFile.GetNumInstruments())
1785+
return false;
1786+
1787+
// Do the drop
1788+
bool modified = false;
1789+
BeginWaitCursor();
1790+
switch (dropInfo.dropType)
1791+
{
1792+
case DRAGONDROP_INSTRUMENT:
1793+
if(dropInfo.sndFile == &m_sndFile)
1794+
{
1795+
SetCurrentInstrument(static_cast<INSTRUMENTINDEX>(dropInfo.dropItem));
1796+
} else if(dropInfo.sndFile)
1797+
{
1798+
if(insertNew && !InsertInstrument(false))
1799+
canDrop = false;
1800+
else
1801+
return OpenInstrument(*dropInfo.sndFile, static_cast<INSTRUMENTINDEX>(dropInfo.dropItem));
1802+
}
1803+
break;
1804+
1805+
case DRAGONDROP_MIDIINSTR:
1806+
if(CDLSBank::IsDLSBank(dropInfo.GetPath()))
1807+
{
1808+
CDLSBank dlsbank;
1809+
if(dlsbank.Open(dropInfo.GetPath()))
1810+
{
1811+
const DLSINSTRUMENT *pDlsIns;
1812+
UINT nIns = 0, nRgn = 0xFF;
1813+
if(dropInfo.dropItem & 0x80)
1814+
{
1815+
// Drums
1816+
UINT key = dropInfo.dropItem & 0x7F;
1817+
pDlsIns = dlsbank.FindInstrument(true, 0xFFFF, 0xFF, key, &nIns);
1818+
if(pDlsIns)
1819+
nRgn = dlsbank.GetRegionFromKey(nIns, key);
1820+
} else
1821+
{
1822+
// Melodic
1823+
pDlsIns = dlsbank.FindInstrument(false, 0xFFFF, dropInfo.dropItem, 60, &nIns);
1824+
if(pDlsIns)
1825+
nRgn = dlsbank.GetRegionFromKey(nIns, 60);
1826+
}
1827+
canDrop = false;
1828+
if(pDlsIns)
1829+
{
1830+
if(!insertNew || InsertInstrument(false))
1831+
{
1832+
CriticalSection cs;
1833+
m_modDoc.GetInstrumentUndo().PrepareUndo(m_nInstrument, "Replace Instrument");
1834+
canDrop = modified = dlsbank.ExtractInstrument(m_sndFile, m_nInstrument, nIns, nRgn);
1835+
}
1836+
}
1837+
break;
1838+
}
1839+
}
1840+
// Instrument file -> fall through
1841+
[[fallthrough]];
1842+
case DRAGONDROP_SOUNDFILE:
1843+
if(!insertNew || InsertInstrument(false))
1844+
OpenInstrument(*reinterpret_cast<const mpt::PathString*>(dropInfo.dropParam));
1845+
break;
1846+
1847+
case DRAGONDROP_DLS:
1848+
{
1849+
uint32 drumRgn = uint32_max;
1850+
// Drums: (0x80000000) | (Region << 16) | (Instrument)
1851+
if(dropInfo.dropParam & 0x80000000)
1852+
drumRgn = (dropInfo.dropParam & 0x7FFF0000) >> 16;
1853+
1854+
if(!insertNew || InsertInstrument(false))
1855+
{
1856+
CriticalSection cs;
1857+
m_modDoc.GetInstrumentUndo().PrepareUndo(m_nInstrument, "Replace Instrument");
1858+
canDrop = modified = CTrackApp::gpDLSBanks[dropInfo.dropItem]->ExtractInstrument(m_sndFile, m_nInstrument, dropInfo.dropParam & 0xFFFF, drumRgn);
1859+
}
1860+
}
1861+
break;
1862+
1863+
default:
1864+
break;
1865+
}
1866+
1867+
if(modified)
1868+
{
1869+
SetModified(InstrumentHint().Info().Envelope().Names(), true);
1870+
m_modDoc.UpdateAllViews(nullptr, SampleHint().Info().Names().Data(), this);
1871+
}
1872+
1873+
CMDIChildWnd *pMDIFrame = static_cast<CMDIChildWnd *>(GetParentFrame());
1874+
if(pMDIFrame)
1875+
{
1876+
pMDIFrame->MDIActivate();
1877+
pMDIFrame->SetActiveView(&m_parent);
1878+
}
1879+
SwitchToView();
1880+
EndWaitCursor();
1881+
return canDrop;
1882+
}
1883+
1884+
17511885
BOOL CCtrlInstruments::EditSample(UINT nSample)
17521886
{
17531887
if ((nSample > 0) && (nSample < MAX_SAMPLES))

mptrack/Ctrl_ins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class CCtrlInstruments: public CModControlDlg
149149
LRESULT OnModCtrlMsg(WPARAM wParam, LPARAM lParam) override;
150150
CString GetToolTipText(UINT uId, HWND hwnd) const override;
151151
BOOL PreTranslateMessage(MSG* pMsg) override;
152+
bool OnDragonDrop(bool doDrop, const DRAGONDROP &dropInfo) override;
152153
//}}AFX_VIRTUAL
153154
protected:
154155
void PrepareUndo(const char *description);

mptrack/Ctrl_smp.cpp

Lines changed: 150 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Autotune.h"
1515
#include "Childfrm.h"
1616
#include "dlg_misc.h"
17+
#include "Dlsbank.h"
1718
#include "FileDialog.h"
1819
#include "Globals.h"
1920
#include "HighDPISupport.h"
@@ -455,15 +456,6 @@ LRESULT CCtrlSamples::OnModCtrlMsg(WPARAM wParam, LPARAM lParam)
455456
return OpenSample(*reinterpret_cast<const mpt::PathString *>(lParam));
456457
break;
457458

458-
case CTRLMSG_SMP_SONGDROP:
459-
if(lParam)
460-
{
461-
const auto &dropInfo = *reinterpret_cast<const DRAGONDROP *>(lParam);
462-
if(dropInfo.sndFile)
463-
return OpenSample(*dropInfo.sndFile, static_cast<SAMPLEINDEX>(dropInfo.dropItem)) ? TRUE : FALSE;
464-
}
465-
break;
466-
467459
case CTRLMSG_SMP_SETZOOM:
468460
SetCurrentSample(m_nSample, static_cast<int>(lParam), FALSE);
469461
break;
@@ -1164,6 +1156,155 @@ bool CCtrlSamples::OpenSample(const CSoundFile &sndFile, SAMPLEINDEX nSample)
11641156
}
11651157

11661158

1159+
bool CCtrlSamples::OnDragonDrop(bool doDrop, const DRAGONDROP &dropInfo)
1160+
{
1161+
bool canDrop = false;
1162+
switch (dropInfo.dropType)
1163+
{
1164+
case DRAGONDROP_SAMPLE:
1165+
if(!dropInfo.dropItem)
1166+
return canDrop;
1167+
if(dropInfo.sndFile == &m_sndFile)
1168+
canDrop = dropInfo.dropItem <= m_sndFile.GetNumSamples();
1169+
else
1170+
canDrop = dropInfo.dropParam || dropInfo.sndFile;
1171+
break;
1172+
1173+
case DRAGONDROP_DLS:
1174+
canDrop = ((dropInfo.dropItem < CTrackApp::gpDLSBanks.size()) && CTrackApp::gpDLSBanks[dropInfo.dropItem]);
1175+
break;
1176+
1177+
case DRAGONDROP_SOUNDFILE:
1178+
case DRAGONDROP_MIDIINSTR:
1179+
canDrop = !dropInfo.GetPath().empty();
1180+
break;
1181+
1182+
default:
1183+
break;
1184+
}
1185+
1186+
const bool insertNew = (dropInfo.insertType == DRAGONDROP::InsertType::Unspecified)
1187+
? CInputHandler::ShiftPressed()
1188+
: dropInfo.insertType == DRAGONDROP::InsertType::InsertNew;
1189+
1190+
if(insertNew && !m_sndFile.CanAddMoreSamples())
1191+
canDrop = false;
1192+
1193+
if(!canDrop || !doDrop)
1194+
return canDrop;
1195+
1196+
// Do the drop
1197+
BeginWaitCursor();
1198+
bool modified = false;
1199+
switch (dropInfo.dropType)
1200+
{
1201+
case DRAGONDROP_SAMPLE:
1202+
if(dropInfo.sndFile == &m_sndFile)
1203+
{
1204+
SetCurrentSample(static_cast<SAMPLEINDEX>(dropInfo.dropItem), -1, true);
1205+
} else if(dropInfo.sndFile)
1206+
{
1207+
if(insertNew && !InsertSample(false))
1208+
canDrop = false;
1209+
else
1210+
return OpenSample(*dropInfo.sndFile, static_cast<SAMPLEINDEX>(dropInfo.dropItem));
1211+
}
1212+
break;
1213+
1214+
case DRAGONDROP_MIDIINSTR:
1215+
if(CDLSBank::IsDLSBank(dropInfo.GetPath()))
1216+
{
1217+
CDLSBank dlsbank;
1218+
if(dlsbank.Open(dropInfo.GetPath()))
1219+
{
1220+
const DLSINSTRUMENT *pDlsIns;
1221+
UINT nIns = 0, nRgn = 0xFF;
1222+
int transpose = 0;
1223+
if(dropInfo.dropItem & 0x80)
1224+
{
1225+
// Drums
1226+
UINT key = dropInfo.dropItem & 0x7F;
1227+
pDlsIns = dlsbank.FindInstrument(true, 0xFFFF, 0xFF, key, &nIns);
1228+
if(pDlsIns)
1229+
{
1230+
nRgn = dlsbank.GetRegionFromKey(nIns, key);
1231+
const auto& region = pDlsIns->Regions[nRgn];
1232+
if(region.tuning != 0)
1233+
transpose = (region.uKeyMin + (region.uKeyMax - region.uKeyMin) / 2) - 60;
1234+
}
1235+
} else
1236+
{
1237+
// Melodic
1238+
pDlsIns = dlsbank.FindInstrument(false, 0xFFFF, dropInfo.dropItem, 60, &nIns);
1239+
if(pDlsIns)
1240+
nRgn = dlsbank.GetRegionFromKey(nIns, 60);
1241+
}
1242+
canDrop = false;
1243+
if(pDlsIns)
1244+
{
1245+
if(!insertNew || InsertSample(false))
1246+
{
1247+
CriticalSection cs;
1248+
m_modDoc.GetSampleUndo().PrepareUndo(m_nSample, sundo_replace, "Replace");
1249+
canDrop = modified = dlsbank.ExtractSample(m_sndFile, m_nSample, nIns, nRgn, transpose);
1250+
}
1251+
}
1252+
break;
1253+
}
1254+
}
1255+
// Instrument file -> fall through
1256+
[[fallthrough]];
1257+
case DRAGONDROP_SOUNDFILE:
1258+
if(!insertNew || InsertSample(false))
1259+
return OpenSample(*reinterpret_cast<const mpt::PathString*>(dropInfo.dropParam));
1260+
break;
1261+
1262+
case DRAGONDROP_DLS:
1263+
{
1264+
const CDLSBank &dlsBank = *CTrackApp::gpDLSBanks[dropInfo.dropItem];
1265+
UINT nIns = dropInfo.dropParam & 0xFFFF;
1266+
UINT nRgn;
1267+
int transpose = 0;
1268+
if(dropInfo.dropParam & 0x80000000)
1269+
{
1270+
// Drums: (0x80000000) | (Region << 16) | (Instrument)
1271+
nRgn = (dropInfo.dropParam & 0x7FFF0000) >> 16;
1272+
const auto &region = dlsBank.GetInstrument(nIns)->Regions[nRgn];
1273+
if(region.tuning != 0)
1274+
transpose = (region.uKeyMin + (region.uKeyMax - region.uKeyMin) / 2) - 60;
1275+
} else
1276+
{
1277+
// Melodic: (Instrument)
1278+
nRgn = dlsBank.GetRegionFromKey(nIns, 60);
1279+
}
1280+
if(!insertNew || InsertSample(false))
1281+
{
1282+
CriticalSection cs;
1283+
m_modDoc.GetSampleUndo().PrepareUndo(m_nSample, sundo_replace, "Replace");
1284+
canDrop = modified = dlsBank.ExtractSample(m_sndFile, m_nSample, nIns, nRgn, transpose);
1285+
}
1286+
}
1287+
break;
1288+
1289+
default:
1290+
break;
1291+
}
1292+
1293+
if(modified)
1294+
SetModified(SampleHint().Info().Data().Names(), true, false);
1295+
1296+
CMDIChildWnd *pMDIFrame = static_cast<CMDIChildWnd *>(GetParentFrame());
1297+
if(pMDIFrame)
1298+
{
1299+
pMDIFrame->MDIActivate();
1300+
pMDIFrame->SetActiveView(&m_parent);
1301+
}
1302+
SwitchToView();
1303+
EndWaitCursor();
1304+
return canDrop;
1305+
}
1306+
1307+
11671308
//////////////////////////////////////////////////////////////////////////////////
11681309
// CCtrlSamples messages
11691310

mptrack/Ctrl_smp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class CCtrlSamples: public CModControlDlg
100100
CString GetToolTipText(UINT uId, HWND hwnd) const override;
101101
BOOL PreTranslateMessage(MSG* pMsg) override;
102102
void OnDPIChanged() override;
103+
bool OnDragonDrop(bool doDrop, const DRAGONDROP &dropInfo) override;
103104
//}}AFX_VIRTUAL
104105
protected:
105106
//{{AFX_MSG(CCtrlSamples)

mptrack/Globals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ BEGIN_MESSAGE_MAP(CModControlDlg, DialogBase)
5252
//{{AFX_MSG_MAP(CModControlDlg)
5353
ON_WM_SIZE()
5454
ON_MESSAGE(WM_MOD_UNLOCKCONTROLS, &CModControlDlg::OnUnlockControls)
55+
ON_MESSAGE(WM_MOD_DRAGONDROPPING, &CModControlDlg::OnDragonDropping)
5556
//}}AFX_MSG_MAP
5657
END_MESSAGE_MAP()
5758

0 commit comments

Comments
 (0)